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

CommandPalette.logic.test.ts

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