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});