| 1 | import { describe, expect, it } from "@effect/vitest"; |
| 2 | |
| 3 | import { deriveThreadTitleSeed } from "./threadTitle.ts"; |
| 4 | |
| 5 | describe("deriveThreadTitleSeed", () => { |
| 6 | it("prefers normalized message text", () => { |
| 7 | expect( |
| 8 | deriveThreadTitleSeed({ |
| 9 | text: " Investigate\n login failures ", |
| 10 | attachments: [{ name: "login-error.png" }], |
| 11 | fallbackLabels: ["Terminal 1"], |
| 12 | }), |
| 13 | ).toBe("Investigate login failures"); |
| 14 | }); |
| 15 | |
| 16 | it("uses the first attachment name when text is empty", () => { |
| 17 | expect( |
| 18 | deriveThreadTitleSeed({ |
| 19 | text: " \n ", |
| 20 | attachments: [{ name: "login-error.png" }, { name: "other.png" }], |
| 21 | }), |
| 22 | ).toBe("Image: login-error.png"); |
| 23 | }); |
| 24 | |
| 25 | it("uses the first non-empty fallback label after text and attachments", () => { |
| 26 | expect( |
| 27 | deriveThreadTitleSeed({ |
| 28 | text: "", |
| 29 | attachments: [], |
| 30 | fallbackLabels: [null, " ", "Terminal 1"], |
| 31 | }), |
| 32 | ).toBe("Terminal 1"); |
| 33 | }); |
| 34 | |
| 35 | it("falls back to New thread", () => { |
| 36 | expect(deriveThreadTitleSeed({ text: "", attachments: [] })).toBe("New thread"); |
| 37 | }); |
| 38 | |
| 39 | it("applies the shared title truncation", () => { |
| 40 | expect( |
| 41 | deriveThreadTitleSeed({ |
| 42 | text: "x".repeat(60), |
| 43 | attachments: [], |
| 44 | }), |
| 45 | ).toBe(`${"x".repeat(50)}...`); |
| 46 | }); |
| 47 | }); |