Open History to see the last commit
1import {
2 EnvironmentId,
3 MessageId,
4 ProjectId,
5 ProviderInstanceId,
6 ThreadId,
7} from "@t3tools/contracts";
8import { serializeAssistantCitation } from "@t3tools/shared/assistantCitations";
9import { describe, expect, it } from "vite-plus/test";
10
11import {
12 buildProjectThreadStartTurnInput,
13 deriveThreadTitleFromPrompt,
14} from "./projectThreadStartTurn";
15
16describe("project thread title", () => {
17 it("keeps ordinary titles and the empty-prompt fallback", () => {
18 expect(deriveThreadTitleFromPrompt(" Fix\n the parser ")).toBe("Fix the parser");
19 expect(deriveThreadTitleFromPrompt(" \n ")).toBe("New thread");
20 });
21
22 it.each([
23 {
24 comment: undefined,
25 title: "Keep `cache[key]` & <parser> shared. Retry!",
26 },
27 {
28 comment: 'Why "shared"?',
29 title: 'Keep `cache[key]` & <parser> shared. Retry! Comment: Why "shared"?',
30 },
31 ])("uses readable titles and intact links with comment $comment", ({ comment, title }) => {
32 const quoteText = "Keep `cache[key]` & <parser> shared.\n Retry!";
33 const text = serializeAssistantCitation({
34 version: 1,
35 environmentId: EnvironmentId.make("source-environment"),
36 threadId: ThreadId.make("source-thread"),
37 messageId: MessageId.make("source-message"),
38 text: quoteText,
39 ...(comment === undefined ? {} : { comment }),
40 start: 0,
41 end: quoteText.length,
42 prefix: "",
43 suffix: "",
44 });
45 const input = buildProjectThreadStartTurnInput({
46 projectId: ProjectId.make("project"),
47 projectCwd: "/workspace",
48 threadId: "new-thread",
49 commandId: "command",
50 messageId: "message",
51 createdAt: "2026-09-01T00:00:00Z",
52 text,
53 uploadedAttachments: [],
54 modelSelection: { instanceId: ProviderInstanceId.make("codex"), model: "gpt-5.6-sol" },
55 runtimeMode: "full-access",
56 interactionMode: "default",
57 workspaceMode: "local",
58 branch: null,
59 worktreePath: null,
60 startFromOrigin: false,
61 worktreeBranchName: "unused",
62 });
63
64 expect(input.titleSeed).toBe(title);
65 expect(input.bootstrap.createThread.title).toBe(input.titleSeed);
66 expect(input.message.text).toBe(text);
67 });
68});
69
70describe("new thread on an existing branch", () => {
71 it.each([null, "/worktrees/existing"])(
72 "reuses the selected workspace %s without preparing a new worktree",
73 (worktreePath) => {
74 const input = buildProjectThreadStartTurnInput({
75 projectId: ProjectId.make("project"),
76 projectCwd: "/workspace",
77 threadId: "new-thread",
78 commandId: "command",
79 messageId: "message",
80 createdAt: "2026-09-06T00:00:00Z",
81 text: "Start fresh",
82 uploadedAttachments: [],
83 modelSelection: { instanceId: ProviderInstanceId.make("codex"), model: "gpt-5.6-sol" },
84 runtimeMode: "full-access",
85 interactionMode: "default",
86 workspaceMode: "local",
87 branch: "feature/existing",
88 worktreePath,
89 startFromOrigin: false,
90 worktreeBranchName: "unused",
91 });
92
93 expect(input.bootstrap.createThread).toMatchObject({
94 projectId: "project",
95 branch: "feature/existing",
96 worktreePath,
97 });
98 expect(input.bootstrap).not.toHaveProperty("prepareWorktree");
99 expect(input.bootstrap).not.toHaveProperty("runSetupScript");
100 expect(input.threadId).toBe("new-thread");
101 },
102 );
103});