Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

projectThreadStartTurn.test.ts

70 lines2.2 KB

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, vi } from "vite-plus/test";
10​
11import {
12 buildProjectThreadStartTurnInput,
13 deriveThreadTitleFromPrompt,
14} from "./projectThreadStartTurn";
15​
16vi.mock("./composerImages", () => ({ toUploadChatImageAttachments: () => [] }));
17​
18describe("project thread title", () => {
19 it("keeps ordinary titles and the empty-prompt fallback", () => {
20 expect(deriveThreadTitleFromPrompt(" Fix\n the parser ")).toBe("Fix the parser");
21 expect(deriveThreadTitleFromPrompt(" \n ")).toBe("New thread");
22 });
23​
24 it.each([
25 {
26 comment: undefined,
27 title: "Keep `cache[key]` & <parser> shared. Retry!",
28 },
29 {
30 comment: 'Why "shared"?',
31 title: 'Keep `cache[key]` & <parser> shared. Retry! Comment: Why "shared"?',
32 },
33 ])("uses readable titles and intact links with comment $comment", ({ comment, title }) => {
34 const quoteText = "Keep `cache[key]` & <parser> shared.\n Retry!";
35 const text = serializeAssistantCitation({
36 version: 1,
37 environmentId: EnvironmentId.make("source-environment"),
38 threadId: ThreadId.make("source-thread"),
39 messageId: MessageId.make("source-message"),
40 text: quoteText,
41 ...(comment === undefined ? {} : { comment }),
42 start: 0,
43 end: quoteText.length,
44 prefix: "",
45 suffix: "",
46 });
47 const input = buildProjectThreadStartTurnInput({
48 projectId: ProjectId.make("project"),
49 projectCwd: "/workspace",
50 threadId: "new-thread",
51 commandId: "command",
52 messageId: "message",
53 createdAt: "2026-09-01T00:00:00Z",
54 text,
55 attachments: [],
56 modelSelection: { instanceId: ProviderInstanceId.make("codex"), model: "gpt-5.6-sol" },
57 runtimeMode: "full-access",
58 interactionMode: "default",
59 workspaceMode: "local",
60 branch: null,
61 worktreePath: null,
62 startFromOrigin: false,
63 worktreeBranchName: "unused",
64 });
65​
66 expect(input.titleSeed).toBe(title);
67 expect(input.bootstrap.createThread.title).toBe(input.titleSeed);
68 expect(input.message.text).toBe(text);
69 });
70});