Open History to see the last commit
1import { ProjectId, ProviderInstanceId } from "@t3tools/contracts";
2import { describe, expect, it } from "vite-plus/test";
3
4import { serializeComposerMessageForServer } from "./composerContext";
5
6import {
7 buildProjectThreadStartTurnInput,
8 deriveThreadTitleFromPrompt,
9 type ProjectThreadStartTurnSpec,
10} from "./projectThreadStartTurn";
11
12describe("project thread title", () => {
13 it.each([
14 {
15 type: "image" as const,
16 name: "photo.png",
17 mimeType: "image/png",
18 text: "",
19 title: "Attached image",
20 },
21 {
22 type: "file" as const,
23 name: "report.pdf",
24 mimeType: "application/pdf",
25 text: "",
26 title: "File: report.pdf",
27 },
28 {
29 type: "file" as const,
30 name: "report.pdf",
31 mimeType: "application/pdf",
32 text: "[report.pdf](t3-context://v1/file/report)",
33 title: "report.pdf",
34 },
35 ])("titles a $type-only message without changing its data", ({ text, title, ...attachment }) => {
36 const uploadedAttachments = [{ ...attachment, id: "prepared-attachment", sizeBytes: 3 }];
37 const wire = serializeComposerMessageForServer(text, undefined);
38 const spec = {
39 projectId: ProjectId.make("project"),
40 projectCwd: "/workspace",
41 threadId: "image-thread",
42 commandId: "image-command",
43 messageId: "image-message",
44 createdAt: "2026-09-04T00:00:00Z",
45 ...wire,
46 titleText: text,
47 uploadedAttachments,
48 modelSelection: { instanceId: ProviderInstanceId.make("codex"), model: "gpt-5.6-sol" },
49 runtimeMode: "full-access",
50 interactionMode: "default",
51 workspaceMode: "local",
52 branch: null,
53 worktreePath: null,
54 startFromOrigin: false,
55 worktreeBranchName: "unused",
56 } satisfies ProjectThreadStartTurnSpec;
57 const input = buildProjectThreadStartTurnInput(spec);
58
59 expect(input.titleSeed).toBe(title);
60 expect(input.bootstrap.createThread.title).toBe(input.titleSeed);
61 expect(input.message.attachments).toEqual(uploadedAttachments);
62 expect(input.message.text).toBe(wire.text);
63 const relaunched = buildProjectThreadStartTurnInput({
64 ...spec,
65 threadId: "local-relaunch",
66 text: input.message.text,
67 titleText: input.bootstrap.createThread.title,
68 });
69 expect(relaunched.titleSeed).toBe(title);
70 expect(relaunched.message.text).toBe(wire.text);
71 expect(relaunched.message.attachments).toEqual(uploadedAttachments);
72 });
73
74 it("starts a worktree of a plain project folder from each repository's default branch", () => {
75 const input = buildProjectThreadStartTurnInput({
76 projectId: ProjectId.make("project"),
77 projectCwd: "/workspace",
78 threadId: "thread",
79 commandId: "command",
80 messageId: "message",
81 createdAt: "2026-09-04T00:00:00Z",
82 text: "Fix the build",
83 uploadedAttachments: [],
84 modelSelection: { instanceId: ProviderInstanceId.make("codex"), model: "gpt-5.6-sol" },
85 runtimeMode: "full-access",
86 interactionMode: "default",
87 workspaceMode: "worktree",
88 branch: null,
89 worktreePath: null,
90 startFromOrigin: false,
91 worktreeRepositories: ["/workspace/api"],
92 worktreeBranchName: "t3/new",
93 });
94
95 expect(input.bootstrap.prepareWorktree).toEqual({
96 projectCwd: "/workspace",
97 baseBranch: "HEAD",
98 branch: "t3/new",
99 repositories: [{ path: "/workspace/api" }],
100 });
101 });
102
103 it("shortens a long prompt without splitting an emoji", () => {
104 expect(deriveThreadTitleFromPrompt(`${"a".repeat(68)}😀 and the rest of the prompt`)).toBe(
105 `${"a".repeat(68)}...`,
106 );
107 });
108});