Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

CommandPalette.logic.test.ts

805 lines24.1 KB

1import { describe, expect, it, vi } from "vite-plus/test";
2import { EnvironmentId, ProjectId, ProviderInstanceId, ThreadId } from "@t3tools/contracts";
3import type { Project, Thread } from "../types";
4import {
5 buildBrowseGroups,
6 buildCommandPaletteProjectMetadata,
7 buildProjectActionItems,
8 buildThreadActionItems,
9 buildLinkedThreadActionItems,
10 enumerateCommandPaletteItems,
11 filterPinnedBrowseEntries,
12 filterCommandPaletteGroups,
13 reduceCommandPaletteUiState,
14 type CommandPaletteActionItem,
15 type CommandPaletteGroup,
16} from "./CommandPalette.logic";
17​
18describe("linked pull request thread navigation", () => {
19 it("keeps archived relations searchable and routes them through the PR environment", async () => {
20 const environmentId = EnvironmentId.make("remote");
21 const id = ThreadId.make("archived-thread");
22 const runThread = vi.fn(async () => {});
23 const query = "https://github.com/acme/web/pull/42";
24 const linkedThreads = {
25 environmentId,
26 threads: [
27 {
28 id,
29 projectId: ProjectId.make("project"),
30 title: "Completed work",
31 archivedAt: "2026-09-01T00:00:00.000Z",
32 },
33 ],
34 };
35 const state = reduceCommandPaletteUiState(
36 { open: false, mode: "command", openIntent: null },
37 {
38 _tag: "OpenSearch",
39 query,
40 linkedThreads,
41 },
42 );
43 expect(state.openIntent).toEqual({ kind: "search", query, linkedThreads });
44 const items = buildLinkedThreadActionItems({ ...linkedThreads, query, icon: null, runThread });
45 const groups = filterCommandPaletteGroups({
46 activeGroups: [],
47 query,
48 isInSubmenu: false,
49 projectSearchItems: [],
50 settingsSearchItems: [],
51 threadSearchItems: items,
52 });
53 expect(groups.flatMap((group) => group.items)).toEqual(items);
54 expect(items[0]?.description).toBe("Archived thread");
55 await items[0]?.run();
56 expect(runThread).toHaveBeenCalledWith({ environmentId, id });
57 });
58});
59​
60describe("buildCommandPaletteProjectMetadata", () => {
61 const localEnvironmentId = EnvironmentId.make("environment-local");
62 const remoteEnvironmentId = EnvironmentId.make("environment-build-box");
63 const locations = new Map([
64 [localEnvironmentId, { kind: "local" as const, label: "Local", machine: "laptop" as const }],
65 [
66 remoteEnvironmentId,
67 { kind: "remote" as const, label: "Build box", machine: "server" as const },
68 ],
69 ]);
70​
71 it("makes every member environment and path searchable", () => {
72 const metadata = buildCommandPaletteProjectMetadata({
73 projects: [
74 {
75 environmentId: localEnvironmentId,
76 title: "T3 Code",
77 workspaceRoot: "/Users/theo/Projects/t3code",
78 },
79 {
80 environmentId: remoteEnvironmentId,
81 title: "t3code",
82 workspaceRoot: "/srv/t3code",
83 },
84 ],
85 locationByEnvironmentId: locations,
86 });
87​
88 expect(metadata.searchTerms).toEqual([
89 "T3 Code",
90 "/Users/theo/Projects/t3code",
91 "Local",
92 "t3code",
93 "/srv/t3code",
94 "Build box",
95 ]);
96 expect(metadata.environmentLabels).toEqual(["Local", "Build box"]);
97​
98 const [filteredGroup] = filterCommandPaletteGroups({
99 activeGroups: [],
100 query: "build box",
101 isInSubmenu: false,
102 projectSearchItems: [
103 {
104 kind: "action",
105 value: "project:t3code",
106 title: "T3 Code",
107 searchTerms: metadata.searchTerms,
108 icon: null,
109 run: async () => undefined,
110 },
111 ],
112 threadSearchItems: [],
113 });
114 expect(filteredGroup?.items).toHaveLength(1);
115 });
116​
117 it("deduplicates grouped checkouts by environment", () => {
118 const metadata = buildCommandPaletteProjectMetadata({
119 projects: [
120 {
121 environmentId: remoteEnvironmentId,
122 title: "T3 Code",
123 workspaceRoot: "/srv/t3code",
124 },
125 {
126 environmentId: remoteEnvironmentId,
127 title: "T3 Code worktree",
128 workspaceRoot: "/srv/t3code-feature",
129 },
130 ],
131 locationByEnvironmentId: locations,
132 });
133​
134 expect(metadata.environmentLabels).toEqual(["Build box"]);
135 });
136​
137 it("deduplicates distinct environments with the same label", () => {
138 const secondRemoteEnvironmentId = EnvironmentId.make("environment-build-box-2");
139 const metadata = buildCommandPaletteProjectMetadata({
140 projects: [
141 {
142 environmentId: remoteEnvironmentId,
143 title: "T3 Code",
144 workspaceRoot: "/srv/t3code",
145 },
146 {
147 environmentId: secondRemoteEnvironmentId,
148 title: "T3 Code mirror",
149 workspaceRoot: "/srv/mirror/t3code",
150 },
151 ],
152 locationByEnvironmentId: new Map([
153 [remoteEnvironmentId, { label: "Build box" }],
154 [secondRemoteEnvironmentId, { label: "Build box" }],
155 ]),
156 });
157​
158 expect(metadata.environmentLabels).toEqual(["Build box"]);
159 });
160​
161 it("uses a human-readable fallback when presentation data is unavailable", () => {
162 const metadata = buildCommandPaletteProjectMetadata({
163 projects: [
164 {
165 environmentId: remoteEnvironmentId,
166 title: "T3 Code",
167 workspaceRoot: "/srv/t3code",
168 },
169 ],
170 locationByEnvironmentId: new Map(),
171 });
172​
173 expect(metadata.searchTerms).toContain("Remote");
174 expect(metadata.environmentLabels).toEqual(["Remote"]);
175 });
176});
177​
178describe("reduceCommandPaletteUiState", () => {
179 const closedState = { open: false, mode: "command", openIntent: null } as const;
180​
181 it("toggles each overlay mode open and closed", () => {
182 const filesOpen = reduceCommandPaletteUiState(closedState, {
183 _tag: "ToggleMode",
184 mode: "files",
185 });
186 expect(filesOpen).toEqual({ open: true, mode: "files", openIntent: null });
187​
188 const contentOpen = reduceCommandPaletteUiState(filesOpen, {
189 _tag: "ToggleMode",
190 mode: "content",
191 });
192 expect(contentOpen).toEqual({ open: true, mode: "content", openIntent: null });
193​
194 expect(
195 reduceCommandPaletteUiState(contentOpen, { _tag: "ToggleMode", mode: "content" }),
196 ).toEqual({ open: false, mode: "content", openIntent: null });
197 });
198​
199 it("switches between open modes without closing", () => {
200 const filesOpen = reduceCommandPaletteUiState(closedState, {
201 _tag: "ToggleMode",
202 mode: "files",
203 });
204 expect(reduceCommandPaletteUiState(filesOpen, { _tag: "ToggleMode", mode: "command" })).toEqual(
205 {
206 open: true,
207 mode: "command",
208 openIntent: null,
209 },
210 );
211 });
212​
213 it("opens PR search from another overlay and replaces an earlier search", () => {
214 const first = reduceCommandPaletteUiState(
215 { open: true, mode: "files", openIntent: null },
216 {
217 _tag: "OpenSearch",
218 query: "https://github.com/acme/web/pull/7",
219 },
220 );
221 expect(first).toEqual({
222 open: true,
223 mode: "command",
224 openIntent: { kind: "search", query: "https://github.com/acme/web/pull/7" },
225 });
226 const second = reduceCommandPaletteUiState(first, {
227 _tag: "OpenSearch",
228 query: "https://github.com/acme/web/pull/8",
229 });
230 expect(second.openIntent).toEqual({
231 kind: "search",
232 query: "https://github.com/acme/web/pull/8",
233 });
234 expect(
235 reduceCommandPaletteUiState(second, { _tag: "SetOpen", open: false }).openIntent,
236 ).toBeNull();
237 });
238​
239 it("routes open intents to command mode", () => {
240 const filesOpen = reduceCommandPaletteUiState(closedState, {
241 _tag: "ToggleMode",
242 mode: "files",
243 });
244 expect(reduceCommandPaletteUiState(filesOpen, { _tag: "OpenAddProject" })).toEqual({
245 open: true,
246 mode: "command",
247 openIntent: { kind: "add-project" },
248 });
249 expect(reduceCommandPaletteUiState(filesOpen, { _tag: "OpenNewThreadIn" })).toEqual({
250 open: true,
251 mode: "command",
252 openIntent: { kind: "new-thread-in" },
253 });
254 });
255​
256 it("preserves the mode on close and resets it on open", () => {
257 const filesOpen = reduceCommandPaletteUiState(closedState, {
258 _tag: "ToggleMode",
259 mode: "files",
260 });
261​
262 expect(reduceCommandPaletteUiState(filesOpen, { _tag: "SetOpen", open: false })).toEqual({
263 open: false,
264 mode: "files",
265 openIntent: null,
266 });
267 expect(reduceCommandPaletteUiState(filesOpen, { _tag: "SetOpen", open: true })).toEqual({
268 open: true,
269 mode: "command",
270 openIntent: null,
271 });
272 });
273});
274​
275describe("enumerateCommandPaletteItems", () => {
276 it("assigns positional jump shortcuts to the first nine displayed items", () => {
277 const items = Array.from({ length: 10 }, (_, index) => ({
278 kind: "action" as const,
279 value: `project-${index + 1}`,
280 searchTerms: [],
281 title: `Project ${index + 1}`,
282 icon: null,
283 shortcutCommand: "chat.new" as const,
284 run: async () => undefined,
285 }));
286​
287 expect(enumerateCommandPaletteItems(items).map((item) => item.shortcutCommand)).toEqual([
288 "thread.jump.1",
289 "thread.jump.2",
290 "thread.jump.3",
291 "thread.jump.4",
292 "thread.jump.5",
293 "thread.jump.6",
294 "thread.jump.7",
295 "thread.jump.8",
296 "thread.jump.9",
297 undefined,
298 ]);
299 });
300});
301​
302const LOCAL_ENVIRONMENT_ID = EnvironmentId.make("environment-local");
303const PROJECT_ID = ProjectId.make("project-1");
304​
305function makeProject(overrides: Partial<Project> = {}): Project {
306 return {
307 id: PROJECT_ID,
308 environmentId: LOCAL_ENVIRONMENT_ID,
309 title: "Project",
310 workspaceRoot: "/workspace/project",
311 defaultModelSelection: null,
312 scripts: [],
313 createdAt: "2026-03-01T00:00:00.000Z",
314 updatedAt: "2026-03-01T00:00:00.000Z",
315 ...overrides,
316 };
318​
319function makeThread(overrides: Partial<Thread> = {}): Thread {
320 return {
321 id: ThreadId.make("thread-1"),
322 environmentId: LOCAL_ENVIRONMENT_ID,
323 projectId: PROJECT_ID,
324 title: "Thread",
325 modelSelection: { instanceId: ProviderInstanceId.make("codex"), model: "gpt-5" },
326 runtimeMode: "full-access",
327 interactionMode: "default",
328 session: null,
329 messages: [],
330 proposedPlans: [],
331 createdAt: "2026-03-01T00:00:00.000Z",
332 archivedAt: null,
333 settledOverride: null,
334 settledAt: null,
335 deletedAt: null,
336 updatedAt: "2026-03-01T00:00:00.000Z",
337 latestTurn: null,
338 branch: null,
339 worktreePath: null,
340 checkpoints: [],
341 pullRequests: [],
342 activities: [],
343 ...overrides,
344 };
346​
347describe("buildProjectActionItems", () => {
348 it("shows the grouped display name but keeps the real title for icons", () => {
349 const project = makeProject({ title: "fleet", workspaceRoot: "/Users/theo/Code/p/fleet" });
350 const iconTitles: string[] = [];
351 const [item] = buildProjectActionItems({
352 projects: [{ ...project, displayName: "t3dotgg/fleet" }],
353 valuePrefix: "project",
354 icon: (candidate) => {
355 iconTitles.push(candidate.title);
356 return null;
357 },
358 runProject: async () => undefined,
359 });
360​
361 expect(item?.title).toBe("t3dotgg/fleet");
362 expect(item?.searchTerms).toEqual(
363 expect.arrayContaining(["t3dotgg/fleet", "fleet", "/Users/theo/Code/p/fleet"]),
364 );
365 expect(iconTitles).toEqual(["fleet"]);
366 });
367});
368​
369describe("buildThreadActionItems", () => {
370 it("orders threads by most recent activity and formats timestamps from updatedAt", () => {
371 vi.useFakeTimers();
372 vi.setSystemTime(new Date("2026-03-25T12:00:00.000Z"));
373​
374 try {
375 const items = buildThreadActionItems({
376 threads: [
377 makeThread({
378 id: ThreadId.make("thread-older"),
379 title: "Older thread",
380 updatedAt: "2026-03-24T12:00:00.000Z",
381 }),
382 makeThread({
383 id: ThreadId.make("thread-newer"),
384 title: "Newer thread",
385 createdAt: "2026-03-20T00:00:00.000Z",
386 updatedAt: "2026-03-20T00:00:00.000Z",
387 }),
388 ],
389 projectTitleById: new Map([[PROJECT_ID, "Project"]]),
390 sortOrder: "updated_at",
391 icon: null,
392 runThread: async (_thread) => undefined,
393 });
394​
395 expect(items.map((item) => item.value)).toEqual([
396 "thread:thread-older",
397 "thread:thread-newer",
398 ]);
399 expect(items[0]?.timestamp).toBe("1d ago");
400 expect(items[1]?.timestamp).toBe("5d ago");
401 } finally {
402 vi.useRealTimers();
403 }
404 });
405​
406 it("ranks thread title matches ahead of contextual project-name matches", () => {
407 const threadItems = buildThreadActionItems({
408 threads: [
409 makeThread({
410 id: ThreadId.make("thread-context-match"),
411 title: "Fix navbar spacing",
412 updatedAt: "2026-03-20T00:00:00.000Z",
413 }),
414 makeThread({
415 id: ThreadId.make("thread-title-match"),
416 title: "Project kickoff notes",
417 createdAt: "2026-03-02T00:00:00.000Z",
418 updatedAt: "2026-03-19T00:00:00.000Z",
419 }),
420 ],
421 projectTitleById: new Map([[PROJECT_ID, "Project"]]),
422 sortOrder: "updated_at",
423 icon: null,
424 runThread: async (_thread) => undefined,
425 });
426​
427 const groups = filterCommandPaletteGroups({
428 activeGroups: [],
429 query: "project",
430 isInSubmenu: false,
431 projectSearchItems: [],
432 threadSearchItems: threadItems,
433 });
434​
435 expect(groups).toHaveLength(1);
436 expect(groups[0]?.value).toBe("threads-search");
437 expect(groups[0]?.items.map((item) => item.value)).toEqual([
438 "thread:thread-title-match",
439 "thread:thread-context-match",
440 ]);
441 });
442​
443 it("preserves thread project-name matches when there is no stronger title match", () => {
444 const group: CommandPaletteGroup = {
445 value: "threads-search",
446 label: "Threads",
447 items: [
448 {
449 kind: "action",
450 value: "thread:project-context-only",
451 searchTerms: ["Fix navbar spacing", "Project"],
452 title: "Fix navbar spacing",
453 description: "Project",
454 icon: null,
455 run: async () => undefined,
456 },
457 ],
458 };
459​
460 const groups = filterCommandPaletteGroups({
461 activeGroups: [group],
462 query: "project",
463 isInSubmenu: false,
464 projectSearchItems: [],
465 threadSearchItems: [],
466 });
467​
468 expect(groups).toHaveLength(1);
469 expect(groups[0]?.items.map((item) => item.value)).toEqual(["thread:project-context-only"]);
470 });
471​
472 it("ranks an order-independent setting title match above a split context match", () => {
473 const settingsSearchItems = [
474 {
475 kind: "action" as const,
476 value: "setting:context-match",
477 searchTerms: ["Pairing settings", "remote backend"],
478 title: "Context match",
479 icon: null,
480 run: async () => undefined,
481 },
482 {
483 kind: "action" as const,
484 value: "setting:remote-pairing",
485 searchTerms: ["Remote pairing", "connections"],
486 title: "Remote pairing",
487 icon: null,
488 run: async () => undefined,
489 },
490 ];
491​
492 const groups = filterCommandPaletteGroups({
493 activeGroups: [],
494 query: "pairing remote",
495 isInSubmenu: false,
496 projectSearchItems: [],
497 settingsSearchItems,
498 threadSearchItems: [],
499 });
500​
501 expect(groups).toHaveLength(1);
502 expect(groups[0]?.value).toBe("settings-search");
503 expect(groups[0]?.items.map((item) => item.value)).toEqual([
504 "setting:remote-pairing",
505 "setting:context-match",
506 ]);
507 });
508​
509 it("keeps accent-insensitive setting results", () => {
510 const groups = filterCommandPaletteGroups({
511 activeGroups: [],
512 query: "thè\u{1ab0}mes",
513 isInSubmenu: false,
514 projectSearchItems: [],
515 settingsSearchItems: [
516 {
517 kind: "action",
518 value: "setting:theme",
519 searchTerms: ["Themes", "Appearance"],
520 title: "Themes",
521 icon: null,
522 run: async () => undefined,
523 },
524 ],
525 threadSearchItems: [],
526 });
527​
528 expect(groups[0]?.items.map((item) => item.value)).toEqual(["setting:theme"]);
529 });
530​
531 it("normalizes case independently of the host locale", () => {
532 const toLocaleLowerCase = String.prototype.toLocaleLowerCase;
533 const localeLowerCase = vi
534 .spyOn(String.prototype, "toLocaleLowerCase")
535 .mockImplementation(function (this: string) {
536 return toLocaleLowerCase.call(this, "tr");
537 });
538 try {
539 const groups = filterCommandPaletteGroups({
540 activeGroups: [],
541 query: "GIT",
542 isInSubmenu: false,
543 projectSearchItems: [],
544 threadSearchItems: [],
545 settingsSearchItems: [
546 {
547 kind: "action",
548 value: "setting:version-control",
549 title: "Version control",
550 searchTerms: ["git"],
551 icon: null,
552 run: async () => undefined,
553 },
554 ],
555 });
556 expect(groups.flatMap((group) => group.items.map((item) => item.value))).toEqual([
557 "setting:version-control",
558 ]);
559 } finally {
560 localeLowerCase.mockRestore();
561 }
562 });
563​
564 it("keeps message excerpts searchable without replacing thread metadata", () => {
565 const [item] = buildThreadActionItems({
566 threads: [makeThread({ branch: "feat/search" })],
567 projectTitleById: new Map([[PROJECT_ID, "T3 Code"]]),
568 sortOrder: "updated_at",
569 icon: null,
570 getContentMatch: () => ({
571 source: "assistant",
572 snippet: "The relay reconnect is now bounded.",
573 query: "reconnect",
574 }),
575 runThread: async (_thread) => undefined,
576 });
577​
578 expect(item?.searchTerms).toContain("The relay reconnect is now bounded.");
579 expect(item?.threadContentMatch).toEqual({
580 source: "assistant",
581 snippet: "The relay reconnect is now bounded.",
582 query: "reconnect",
583 });
584 expect(item?.description).toBe("T3 Code · #feat/search");
585 });
586​
587 it("surfaces threads when the query is their ID, without outranking title matches", () => {
588 const idThread = makeThread({
589 id: ThreadId.make("thread-alpha-1234"),
590 title: "Unrelated work",
591 updatedAt: "2026-03-05T00:00:00.000Z",
592 });
593 const titleThread = makeThread({
594 id: ThreadId.make("thread-other-9999"),
595 title: "Fix thread-alpha-1234 flakes",
596 updatedAt: "2026-03-04T00:00:00.000Z",
597 });
598 const items = buildThreadActionItems({
599 threads: [idThread, titleThread],
600 projectTitleById: new Map([[PROJECT_ID, "T3 Code"]]),
601 sortOrder: "updated_at",
602 icon: null,
603 runThread: async (_thread) => undefined,
604 });
605​
606 const groups = filterCommandPaletteGroups({
607 activeGroups: [],
608 query: " THREAD-ALPHA-1234 ",
609 isInSubmenu: false,
610 projectSearchItems: [],
611 settingsSearchItems: [],
612 threadSearchItems: items,
613 });
614​
615 expect(groups.flatMap((group) => group.items)).toEqual([
616 expect.objectContaining({ value: `thread:${titleThread.id}` }),
617 expect.objectContaining({ value: `thread:${idThread.id}` }),
618 ]);
619 });
620​
621 it("prefers renderDescription when provided", () => {
622 const [item] = buildThreadActionItems({
623 threads: [makeThread({ branch: "feat/search", worktreePath: "/tmp/wt" })],
624 projectTitleById: new Map([[PROJECT_ID, "T3 Code"]]),
625 sortOrder: "updated_at",
626 icon: null,
627 renderDescription: (thread, { projectTitle }) =>
628 `${projectTitle}:${thread.branch}:${thread.worktreePath ? "wt" : "local"}`,
629 runThread: async (_thread) => undefined,
630 });
631​
632 expect(item?.description).toBe("T3 Code:feat/search:wt");
633 });
634​
635 it("filters archived threads out of thread search items", () => {
636 const items = buildThreadActionItems({
637 threads: [
638 makeThread({
639 id: ThreadId.make("thread-active"),
640 title: "Active thread",
641 createdAt: "2026-03-02T00:00:00.000Z",
642 updatedAt: "2026-03-19T00:00:00.000Z",
643 }),
644 makeThread({
645 id: ThreadId.make("thread-archived"),
646 title: "Archived thread",
647 archivedAt: "2026-03-20T00:00:00.000Z",
648 updatedAt: "2026-03-20T00:00:00.000Z",
649 }),
650 ],
651 projectTitleById: new Map([[PROJECT_ID, "Project"]]),
652 sortOrder: "updated_at",
653 icon: null,
654 runThread: async (_thread) => undefined,
655 });
656​
657 expect(items.map((item) => item.value)).toEqual(["thread:thread-active"]);
658 });
659});
660​
661describe("buildBrowseGroups", () => {
662 it("waits for asynchronous browse navigation actions", async () => {
663 let finishNavigation: (() => void) | undefined;
664 const browseTo = vi.fn(
665 () =>
666 new Promise<void>((resolve) => {
667 finishNavigation = resolve;
668 }),
669 );
670 const groups = buildBrowseGroups({
671 browseEntries: [{ name: "Downloads", fullPath: "/Users/test/Downloads" }],
672 browseQuery: "~/",
673 canBrowseUp: false,
674 upIcon: null,
675 directoryIcon: null,
676 browseUp: vi.fn(),
677 browseTo,
678 });
679 const item = groups[0]?.items[0];
680 if (!item || item.kind !== "action") {
681 throw new Error("Expected a browse action");
682 }
683​
684 let actionSettled = false;
685 const action = item.run().then(() => {
686 actionSettled = true;
687 });
688 await Promise.resolve();
689​
690 expect(browseTo).toHaveBeenCalledWith("Downloads");
691 expect(actionSettled).toBe(false);
692​
693 finishNavigation?.();
694 await action;
695 expect(actionSettled).toBe(true);
696 });
697});
698​
699describe("filterPinnedBrowseEntries", () => {
700 const entries = [
701 { name: "repo", fullPath: "/projects/repo" },
702 { name: "work", fullPath: "/projects/work" },
703 ];
704​
705 it("shows sibling folders without losing an existing pinned destination", () => {
706 expect(
707 filterPinnedBrowseEntries({
708 browseEntries: entries,
709 filterQuery: "repo",
710 pinnedDirectoryName: "repo",
711 caseSensitive: true,
712 }),
713 ).toEqual({ visibleEntries: entries, exactEntry: entries[0] });
714 });
715​
716 it("matches an existing pinned destination without Windows casing", () => {
717 const windowsEntries = [
718 { name: "Repo", fullPath: "C:\\projects\\Repo" },
719 { name: "work", fullPath: "C:\\projects\\work" },
720 ];
721 expect(
722 filterPinnedBrowseEntries({
723 browseEntries: windowsEntries,
724 filterQuery: "repo",
725 pinnedDirectoryName: "repo",
726 caseSensitive: false,
727 }),
728 ).toEqual({
729 visibleEntries: windowsEntries,
730 exactEntry: windowsEntries[0],
731 });
732 });
733});
734​
735it.each([
736 "#10839",
737 "10839",
738 "pingdotgg/t3code#10839",
739 "https://github.com/pingdotgg/t3code/pull/10839",
740])("finds linked threads from PR query %s", (query) => {
741 const items = buildThreadActionItems({
742 threads: [
743 makeThread({
744 title: "Implementation",
745 pullRequests: [
746 {
747 host: "github.com",
748 repository: "pingdotgg/t3code",
749 number: 10839,
750 url: "https://github.com/pingdotgg/t3code/pull/10839",
751 source: "manual",
752 linkedAt: "2026-09-08T00:00:00Z",
753 snapshot: null,
754 stack: null,
755 },
756 ],
757 }),
758 makeThread({ id: ThreadId.make("unrelated"), title: "Other work" }),
759 ],
760 projectTitleById: new Map(),
761 sortOrder: "updated_at",
762 icon: null,
763 runThread: async () => undefined,
764 });
765 const groups = filterCommandPaletteGroups({
766 activeGroups: [],
767 query,
768 isInSubmenu: false,
769 projectSearchItems: [],
770 threadSearchItems: items,
771 });
772 expect(groups.flatMap((group) => group.items.map((item) => item.title))).toEqual([
773 "Implementation",
774 ]);
775});
776​
777describe("filterCommandPaletteGroups", () => {
778 it("sorts secondary settings results after other matches", () => {
779 const item = (value: string, title: string, secondary?: boolean) =>
780 ({
781 kind: "action",
782 value,
783 title,
784 searchTerms: [title, "General"],
785 icon: null,
786 run: async () => undefined,
787 ...(secondary ? { secondary } : {}),
788 }) satisfies CommandPaletteActionItem;
789 const [group] = filterCommandPaletteGroups({
790 activeGroups: [],
791 query: "model",
792 isInSubmenu: false,
793 projectSearchItems: [],
794 settingsSearchItems: [
795 item("setting:keybinding-modelPicker.toggle", "Model Picker: Toggle", true),
796 item("setting:default-model", "Default model"),
797 ],
798 threadSearchItems: [],
799 });
800 expect(group?.items.map((entry) => entry.value)).toEqual([
801 "setting:default-model",
802 "setting:keybinding-modelPicker.toggle",
803 ]);
804 });
805});