Open History to see the last commit
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 };
318}
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 });
343}
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("orders title matches by recent activity before older prefix matches", () => {
442 const threads = [
443 makeThread({
444 id: ThreadId.make("old-prefix"),
445 title: "Convex InvalidCursor in Convex threads query",
446 createdAt: "2026-01-01T00:00:00.000Z",
447 updatedAt: "2026-01-02T00:00:00.000Z",
448 }),
449 makeThread({
450 id: ThreadId.make("recent-title"),
451 title: "Disable Convex schema validation",
452 createdAt: "2025-12-01T00:00:00.000Z",
453 updatedAt: "2026-03-24T00:00:00.000Z",
454 }),
455 makeThread({
456 id: ThreadId.make("recent-content"),
457 title: "Fix schema validation",
458 createdAt: "2026-03-25T00:00:00.000Z",
459 updatedAt: "2026-03-25T00:00:00.000Z",
460 }),
461 ];
462 const items = buildThreadActionItems({
463 threads,
464 projectTitleById: new Map([[PROJECT_ID, "T3 Code"]]),
465 sortOrder: "created_at",
466 icon: null,
467 getContentMatch: (thread) =>
468 thread.id === ThreadId.make("recent-content")
469 ? { source: "user", snippet: "Please check Convex", query: "convex" }
470 : undefined,
471 runThread: async () => undefined,
472 });
473
474 const groups = filterCommandPaletteGroups({
475 activeGroups: [],
476 query: "convex",
477 isInSubmenu: false,
478 projectSearchItems: [],
479 threadSearchItems: items,
480 });
481
482 expect(groups[0]?.items.map((item) => item.value)).toEqual([
483 "thread:recent-title",
484 "thread:old-prefix",
485 "thread:recent-content",
486 ]);
487 });
488
489 it("preserves thread project-name matches when there is no stronger title match", () => {
490 const group: CommandPaletteGroup = {
491 value: "threads-search",
492 label: "Threads",
493 items: [
494 {
495 kind: "action",
496 value: "thread:project-context-only",
497 searchTerms: ["Fix navbar spacing", "Project"],
498 title: "Fix navbar spacing",
499 description: "Project",
500 icon: null,
501 run: async () => undefined,
502 },
503 ],
504 };
505
506 const groups = filterCommandPaletteGroups({
507 activeGroups: [group],
508 query: "project",
509 isInSubmenu: false,
510 projectSearchItems: [],
511 threadSearchItems: [],
512 });
513
514 expect(groups).toHaveLength(1);
515 expect(groups[0]?.items.map((item) => item.value)).toEqual(["thread:project-context-only"]);
516 });
517
518 it("ranks an order-independent setting title match above a split context match", () => {
519 const settingsSearchItems = [
520 {
521 kind: "action" as const,
522 value: "setting:context-match",
523 searchTerms: ["Pairing settings", "remote backend"],
524 title: "Context match",
525 icon: null,
526 run: async () => undefined,
527 },
528 {
529 kind: "action" as const,
530 value: "setting:remote-pairing",
531 searchTerms: ["Remote pairing", "connections"],
532 title: "Remote pairing",
533 icon: null,
534 run: async () => undefined,
535 },
536 ];
537
538 const groups = filterCommandPaletteGroups({
539 activeGroups: [],
540 query: "pairing remote",
541 isInSubmenu: false,
542 projectSearchItems: [],
543 settingsSearchItems,
544 threadSearchItems: [],
545 });
546
547 expect(groups).toHaveLength(1);
548 expect(groups[0]?.value).toBe("settings-search");
549 expect(groups[0]?.items.map((item) => item.value)).toEqual([
550 "setting:remote-pairing",
551 "setting:context-match",
552 ]);
553 });
554
555 it("keeps accent-insensitive setting results", () => {
556 const groups = filterCommandPaletteGroups({
557 activeGroups: [],
558 query: "thè\u{1ab0}mes",
559 isInSubmenu: false,
560 projectSearchItems: [],
561 settingsSearchItems: [
562 {
563 kind: "action",
564 value: "setting:theme",
565 searchTerms: ["Themes", "Appearance"],
566 title: "Themes",
567 icon: null,
568 run: async () => undefined,
569 },
570 ],
571 threadSearchItems: [],
572 });
573
574 expect(groups[0]?.items.map((item) => item.value)).toEqual(["setting:theme"]);
575 });
576
577 it("normalizes case independently of the host locale", () => {
578 const toLocaleLowerCase = String.prototype.toLocaleLowerCase;
579 const localeLowerCase = vi
580 .spyOn(String.prototype, "toLocaleLowerCase")
581 .mockImplementation(function (this: string) {
582 return toLocaleLowerCase.call(this, "tr");
583 });
584 try {
585 const groups = filterCommandPaletteGroups({
586 activeGroups: [],
587 query: "GIT",
588 isInSubmenu: false,
589 projectSearchItems: [],
590 threadSearchItems: [],
591 settingsSearchItems: [
592 {
593 kind: "action",
594 value: "setting:version-control",
595 title: "Version control",
596 searchTerms: ["git"],
597 icon: null,
598 run: async () => undefined,
599 },
600 ],
601 });
602 expect(groups.flatMap((group) => group.items.map((item) => item.value))).toEqual([
603 "setting:version-control",
604 ]);
605 } finally {
606 localeLowerCase.mockRestore();
607 }
608 });
609
610 it("keeps message excerpts searchable without replacing thread metadata", () => {
611 const [item] = buildThreadActionItems({
612 threads: [makeThread({ branch: "feat/search" })],
613 projectTitleById: new Map([[PROJECT_ID, "T3 Code"]]),
614 sortOrder: "updated_at",
615 icon: null,
616 getContentMatch: () => ({
617 source: "assistant",
618 snippet: "The relay reconnect is now bounded.",
619 query: "reconnect",
620 }),
621 runThread: async (_thread) => undefined,
622 });
623
624 expect(item?.searchTerms).toContain("The relay reconnect is now bounded.");
625 expect(item?.threadContentMatch).toEqual({
626 source: "assistant",
627 snippet: "The relay reconnect is now bounded.",
628 query: "reconnect",
629 });
630 expect(item?.description).toBe("T3 Code · #feat/search");
631 });
632
633 it("surfaces threads when the query is their ID, without outranking title matches", () => {
634 const idThread = makeThread({
635 id: ThreadId.make("thread-alpha-1234"),
636 title: "Unrelated work",
637 updatedAt: "2026-03-05T00:00:00.000Z",
638 });
639 const titleThread = makeThread({
640 id: ThreadId.make("thread-other-9999"),
641 title: "Fix thread-alpha-1234 flakes",
642 updatedAt: "2026-03-04T00:00:00.000Z",
643 });
644 const items = buildThreadActionItems({
645 threads: [idThread, titleThread],
646 projectTitleById: new Map([[PROJECT_ID, "T3 Code"]]),
647 sortOrder: "updated_at",
648 icon: null,
649 runThread: async (_thread) => undefined,
650 });
651
652 const groups = filterCommandPaletteGroups({
653 activeGroups: [],
654 query: " THREAD-ALPHA-1234 ",
655 isInSubmenu: false,
656 projectSearchItems: [],
657 settingsSearchItems: [],
658 threadSearchItems: items,
659 });
660
661 expect(groups.flatMap((group) => group.items)).toEqual([
662 expect.objectContaining({ value: `thread:${titleThread.id}` }),
663 expect.objectContaining({ value: `thread:${idThread.id}` }),
664 ]);
665 });
666
667 it("prefers renderDescription when provided", () => {
668 const [item] = buildThreadActionItems({
669 threads: [makeThread({ branch: "feat/search", worktreePath: "/tmp/wt" })],
670 projectTitleById: new Map([[PROJECT_ID, "T3 Code"]]),
671 sortOrder: "updated_at",
672 icon: null,
673 renderDescription: (thread, { projectTitle }) =>
674 `${projectTitle}:${thread.branch}:${thread.worktreePath ? "wt" : "local"}`,
675 runThread: async (_thread) => undefined,
676 });
677
678 expect(item?.description).toBe("T3 Code:feat/search:wt");
679 });
680
681 it("filters archived threads out of thread search items", () => {
682 const items = buildThreadActionItems({
683 threads: [
684 makeThread({
685 id: ThreadId.make("thread-active"),
686 title: "Active thread",
687 createdAt: "2026-03-02T00:00:00.000Z",
688 updatedAt: "2026-03-19T00:00:00.000Z",
689 }),
690 makeThread({
691 id: ThreadId.make("thread-archived"),
692 title: "Archived thread",
693 archivedAt: "2026-03-20T00:00:00.000Z",
694 updatedAt: "2026-03-20T00:00:00.000Z",
695 }),
696 ],
697 projectTitleById: new Map([[PROJECT_ID, "Project"]]),
698 sortOrder: "updated_at",
699 icon: null,
700 runThread: async (_thread) => undefined,
701 });
702
703 expect(items.map((item) => item.value)).toEqual(["thread:thread-active"]);
704 });
705});
706
707describe("buildBrowseGroups", () => {
708 it("waits for asynchronous browse navigation actions", async () => {
709 let finishNavigation: (() => void) | undefined;
710 const browseTo = vi.fn(
711 () =>
712 new Promise<void>((resolve) => {
713 finishNavigation = resolve;
714 }),
715 );
716 const groups = buildBrowseGroups({
717 browseEntries: [{ name: "Downloads", fullPath: "/Users/test/Downloads" }],
718 browseQuery: "~/",
719 canBrowseUp: false,
720 upIcon: null,
721 directoryIcon: null,
722 browseUp: vi.fn(),
723 browseTo,
724 });
725 const item = groups[0]?.items[0];
726 if (!item || item.kind !== "action") {
727 throw new Error("Expected a browse action");
728 }
729
730 let actionSettled = false;
731 const action = item.run().then(() => {
732 actionSettled = true;
733 });
734 await Promise.resolve();
735
736 expect(browseTo).toHaveBeenCalledWith("Downloads");
737 expect(actionSettled).toBe(false);
738
739 finishNavigation?.();
740 await action;
741 expect(actionSettled).toBe(true);
742 });
743});
744
745describe("filterPinnedBrowseEntries", () => {
746 const entries = [
747 { name: "repo", fullPath: "/projects/repo" },
748 { name: "work", fullPath: "/projects/work" },
749 ];
750
751 it("shows sibling folders without losing an existing pinned destination", () => {
752 expect(
753 filterPinnedBrowseEntries({
754 browseEntries: entries,
755 filterQuery: "repo",
756 pinnedDirectoryName: "repo",
757 caseSensitive: true,
758 }),
759 ).toEqual({ visibleEntries: entries, exactEntry: entries[0] });
760 });
761
762 it("matches an existing pinned destination without Windows casing", () => {
763 const windowsEntries = [
764 { name: "Repo", fullPath: "C:\\projects\\Repo" },
765 { name: "work", fullPath: "C:\\projects\\work" },
766 ];
767 expect(
768 filterPinnedBrowseEntries({
769 browseEntries: windowsEntries,
770 filterQuery: "repo",
771 pinnedDirectoryName: "repo",
772 caseSensitive: false,
773 }),
774 ).toEqual({
775 visibleEntries: windowsEntries,
776 exactEntry: windowsEntries[0],
777 });
778 });
779});
780
781it.each([
782 "#10839",
783 "10839",
784 "pingdotgg/t3code#10839",
785 "https://github.com/pingdotgg/t3code/pull/10839",
786])("finds linked threads from PR query %s", (query) => {
787 const items = buildThreadActionItems({
788 threads: [
789 makeThread({
790 title: "Implementation",
791 pullRequests: [
792 {
793 host: "github.com",
794 repository: "pingdotgg/t3code",
795 number: 10839,
796 url: "https://github.com/pingdotgg/t3code/pull/10839",
797 source: "manual",
798 linkedAt: "2026-09-08T00:00:00Z",
799 snapshot: null,
800 stack: null,
801 },
802 ],
803 }),
804 makeThread({ id: ThreadId.make("unrelated"), title: "Other work" }),
805 ],
806 projectTitleById: new Map(),
807 sortOrder: "updated_at",
808 icon: null,
809 runThread: async () => undefined,
810 });
811 const groups = filterCommandPaletteGroups({
812 activeGroups: [],
813 query,
814 isInSubmenu: false,
815 projectSearchItems: [],
816 threadSearchItems: items,
817 });
818 expect(groups.flatMap((group) => group.items.map((item) => item.title))).toEqual([
819 "Implementation",
820 ]);
821});
822
823describe("filterCommandPaletteGroups", () => {
824 it("sorts secondary settings results after other matches", () => {
825 const item = (value: string, title: string, secondary?: boolean) =>
826 ({
827 kind: "action",
828 value,
829 title,
830 searchTerms: [title, "General"],
831 icon: null,
832 run: async () => undefined,
833 ...(secondary ? { secondary } : {}),
834 }) satisfies CommandPaletteActionItem;
835 const [group] = filterCommandPaletteGroups({
836 activeGroups: [],
837 query: "model",
838 isInSubmenu: false,
839 projectSearchItems: [],
840 settingsSearchItems: [
841 item("setting:keybinding-modelPicker.toggle", "Model Picker: Toggle", true),
842 item("setting:default-model", "Default model"),
843 ],
844 threadSearchItems: [],
845 });
846 expect(group?.items.map((entry) => entry.value)).toEqual([
847 "setting:default-model",
848 "setting:keybinding-modelPicker.toggle",
849 ]);
850 });
851});