Open History to see the last commit
1import { DEFAULT_CLIENT_SETTINGS, EnvironmentId, ProjectId } from "@t3tools/contracts";
2import type { AnyRouter } from "@tanstack/react-router";
3import { describe, expect, it, vi } from "vite-plus/test";
4
5import * as commandPalette from "../commandPaletteBus";
6import * as settings from "../hooks/useSettings";
7import * as threadActions from "../lib/chatThreadActions";
8import * as entities from "../state/entities";
9import type { Project } from "../types";
10import { installChatRouteCommands } from "./chatRouteCommands";
11import * as dispatcher from "./dispatcher";
12
13function project(id: string): Project {
14 return {
15 id: ProjectId.make(id),
16 environmentId: EnvironmentId.make("local"),
17 title: id,
18 workspaceRoot: `/projects/${id}`,
19 repositoryIdentity: null,
20 defaultModelSelection: null,
21 createdAt: "2026-01-01T00:00:00.000Z",
22 updatedAt: "2026-01-01T00:00:00.000Z",
23 scripts: [],
24 };
25}
26
27describe("new thread commands", () => {
28 it.each([
29 { mode: "normal", count: 2, command: "chat.new", picker: true },
30 { mode: "boring", count: 2, command: "chat.new", picker: true },
31 { mode: "boring", count: 1, command: "chat.new", picker: false },
32 { mode: "boring", count: 2, command: "chat.newLocal", picker: false },
33 ] as const)("$mode sidebar, $count projects, $command: picker=$picker", (scenario) => {
34 using _settings = vi.spyOn(settings, "getClientSettings").mockReturnValue({
35 ...DEFAULT_CLIENT_SETTINGS,
36 boringSidebarEnabled: scenario.mode === "boring",
37 });
38 using _projects = vi
39 .spyOn(entities, "readProjects")
40 .mockReturnValue([project("active"), project("idle")].slice(0, scenario.count));
41 using openPicker = vi.spyOn(commandPalette, "openCommandPalette").mockImplementation(() => {});
42 using startLocal = vi.spyOn(threadActions, "startNewThreadFromContext").mockResolvedValue(true);
43 using register = vi.spyOn(dispatcher, "registerCommands").mockReturnValue(() => {});
44 const router = { state: { matches: [] } } as unknown as AnyRouter;
45 using stack = new DisposableStack();
46 stack.defer(installChatRouteCommands(router));
47 const commands = register.mock.calls[0]![0];
48 const event = {
49 preventDefault: vi.fn(),
50 stopPropagation: vi.fn(),
51 } as unknown as KeyboardEvent;
52
53 commands[scenario.command]!(event);
54
55 if (scenario.picker) {
56 expect(openPicker).toHaveBeenCalledWith({ open: "new-thread-in" });
57 expect(startLocal).not.toHaveBeenCalled();
58 } else {
59 expect(openPicker).not.toHaveBeenCalled();
60 expect(startLocal).toHaveBeenCalledOnce();
61 }
62 });
63});