Open History to see the last commit
1import { EnvironmentId, ProjectId, ThreadId } from "@t3tools/contracts";
2import { describe, expect, it, vi } from "vite-plus/test";
3import { page } from "vite-plus/test/browser";
4
5import { render } from "../../test/render";
6import { openCommandPalette } from "../commandPaletteBus";
7import { useCommandPaletteStore } from "../commandPaletteStore";
8import { makeThreadFixture } from "../test-fixtures";
9import type { Project, Thread } from "../types";
10import { CommandPalette } from "./CommandPalette";
11
12const entities = vi.hoisted(() => ({
13 projects: [] as ReadonlyArray<Project>,
14 threads: [] as ReadonlyArray<Thread>,
15}));
16vi.mock("../state/entities", async (original) => ({
17 ...(await original<typeof import("../state/entities")>()),
18 useProjects: () => entities.projects,
19 useVisibleThreadShells: () => entities.threads,
20}));
21
22function setup(state: { projects?: ReadonlyArray<Project>; threads?: ReadonlyArray<Thread> } = {}) {
23 useCommandPaletteStore.setState(useCommandPaletteStore.getInitialState(), true);
24 entities.projects = state.projects ?? [];
25 entities.threads = state.threads ?? [];
26}
27
28describe("CommandPalette open intents", () => {
29 it("opens New thread in... with focus in the search input, not the Back button", async () => {
30 setup();
31 await using _screen = await render(<CommandPalette>{null}</CommandPalette>);
32
33 openCommandPalette({ open: "new-thread-in" });
34
35 await expect.element(page.getByPlaceholder("Search...")).toHaveFocus();
36 });
37
38 it("opens a search intent with its query in the focused input", async () => {
39 setup();
40 await using _screen = await render(<CommandPalette>{null}</CommandPalette>);
41
42 openCommandPalette({ query: "acme" });
43
44 const input = page.getByPlaceholder("Search commands, projects, and threads...");
45 await expect.element(input).toHaveFocus();
46 await expect.element(input).toHaveValue("acme");
47 });
48
49 it("opens a searched project's latest listed thread, not a newer subagent", async () => {
50 const environmentId = EnvironmentId.make("local");
51 const projectId = ProjectId.make("acme");
52 const parentId = ThreadId.make("parent");
53 setup({
54 projects: [
55 {
56 id: projectId,
57 environmentId,
58 title: "Acme",
59 workspaceRoot: "/work/acme",
60 repositoryIdentity: null,
61 defaultModelSelection: null,
62 createdAt: "2026-03-01T00:00:00.000Z",
63 updatedAt: "2026-03-01T00:00:00.000Z",
64 scripts: [],
65 },
66 ],
67 threads: [
68 makeThreadFixture({
69 id: parentId,
70 environmentId,
71 projectId,
72 latestUserMessageAt: "2026-03-02T00:00:00.000Z",
73 }),
74 makeThreadFixture({
75 id: ThreadId.make("subagent"),
76 environmentId,
77 projectId,
78 updatedAt: "2026-03-03T00:00:00.000Z",
79 lineage: {
80 rootThreadId: parentId,
81 parentThreadId: parentId,
82 relationshipToParent: "subagent",
83 },
84 }),
85 ],
86 });
87 await using screen = await render(<CommandPalette>{null}</CommandPalette>);
88
89 openCommandPalette({ query: "Acme" });
90 await page.getByRole("option", { name: /Acme/ }).first().click();
91
92 await vi.waitFor(() => expect(screen.router?.state.location.pathname).toBe("/local/parent"));
93 });
94});