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

threadTitle.test.ts

65 lines2.1 KB

1import { describe, expect, it } from "@effect/vitest";
2​
3import { deriveThreadTitleSeed } from "./threadTitle.ts";
4​
5describe("deriveThreadTitleSeed", () => {
6 const image = "![pasted-image.png](t3-context://v1/image/aadd9cc6-1234-5678-9012-abcdef123456)";
7​
8 it.each([
9 [image, "Attached image"],
10 [`${image}\n![other.png](t3-context://v1/image/other)`, "Attached images"],
11 ])("uses a readable image-only title for %s", (text, title) => {
12 expect(deriveThreadTitleSeed({ text, attachments: [] })).toBe(title);
13 });
14​
15 it("prefers a source label when an image prompt has no prose", () => {
16 expect(
17 deriveThreadTitleSeed({
18 text: `${image}\n[src/app.ts](t3-context://v1/mention/source)`,
19 attachments: [{ type: "image", name: "pasted-image.png" }],
20 }),
21 ).toBe("src/app.ts");
22 });
23​
24 it("prefers normalized request text and context labels over attachments", () => {
25 expect(
26 deriveThreadTitleSeed({
27 text: ` Fix ${image} [src/app.ts](t3-context://v1/mention/source)\n using [Build output](t3-context://v1/terminal/build) `,
28 attachments: [{ type: "image", name: "login-error.png" }],
29 fallbackLabels: ["Terminal 1"],
30 }),
31 ).toBe("Fix src/app.ts using Build output");
32 });
33​
34 it("uses an image placeholder when text is empty", () => {
35 expect(
36 deriveThreadTitleSeed({
37 text: " \n ",
38 attachments: [{ type: "image", name: "login-error.png" }],
39 }),
40 ).toBe("Attached image");
41 });
42​
43 it("uses the first non-empty fallback label after text and attachments", () => {
44 expect(
45 deriveThreadTitleSeed({
46 text: "",
47 attachments: [],
48 fallbackLabels: [null, " ", "Terminal 1"],
49 }),
50 ).toBe("Terminal 1");
51 });
52​
53 it("falls back to New thread", () => {
54 expect(deriveThreadTitleSeed({ text: "", attachments: [] })).toBe("New thread");
55 });
56​
57 it("applies the shared title truncation", () => {
58 expect(
59 deriveThreadTitleSeed({
60 text: "x".repeat(60),
61 attachments: [],
62 }),
63 ).toBe(`${"x".repeat(50)}...`);
64 });
65});