| 1 | import { describe, expect, it } from "vite-plus/test"; |
| 2 | |
| 3 | import { resolveSubagentRowPresentation } from "./threadAgentsPresentation"; |
| 4 | |
| 5 | const base = { |
| 6 | title: null, |
| 7 | prompt: "Audit the timestamps", |
| 8 | status: "running" as const, |
| 9 | result: null, |
| 10 | childThreadId: "thread-child" as never, |
| 11 | }; |
| 12 | |
| 13 | describe("resolveSubagentRowPresentation", () => { |
| 14 | it("leads with progress while the agent is working", () => { |
| 15 | const row = resolveSubagentRowPresentation({ |
| 16 | ...base, |
| 17 | progress: "Reading files", |
| 18 | result: "stale result", |
| 19 | }); |
| 20 | |
| 21 | expect(row.detail).toBe("Reading files"); |
| 22 | expect(row.tone).toBe("working"); |
| 23 | expect(row.live).toBe(true); |
| 24 | }); |
| 25 | |
| 26 | it("leads with the result once the agent has settled", () => { |
| 27 | const row = resolveSubagentRowPresentation({ |
| 28 | ...base, |
| 29 | status: "completed", |
| 30 | progress: "Reading files", |
| 31 | result: "Found two\n problems", |
| 32 | }); |
| 33 | |
| 34 | expect(row.detail).toBe("Found two problems"); |
| 35 | expect(row.tone).toBe("completed"); |
| 36 | expect(row.statusLabel).toBe("Completed"); |
| 37 | }); |
| 38 | |
| 39 | it("shows a failure's text, since that is where the error lands", () => { |
| 40 | const row = resolveSubagentRowPresentation({ ...base, status: "failed", result: "Timed out" }); |
| 41 | |
| 42 | expect(row.detail).toBe("Timed out"); |
| 43 | expect(row.tone).toBe("failed"); |
| 44 | }); |
| 45 | |
| 46 | it("falls back to a trimmed prompt when the agent has no title", () => { |
| 47 | const long = resolveSubagentRowPresentation({ ...base, prompt: "x".repeat(200) }); |
| 48 | const titled = resolveSubagentRowPresentation({ ...base, title: "Subagent: /root/my_worker" }); |
| 49 | |
| 50 | expect(long.title).toHaveLength(80); |
| 51 | expect(long.title.endsWith("...")).toBe(true); |
| 52 | expect(titled.title).toBe("My Worker"); |
| 53 | }); |
| 54 | |
| 55 | it("only offers a thread to open when the agent has one", () => { |
| 56 | expect(resolveSubagentRowPresentation(base).canOpenThread).toBe(true); |
| 57 | expect(resolveSubagentRowPresentation({ ...base, childThreadId: null }).canOpenThread).toBe( |
| 58 | false, |
| 59 | ); |
| 60 | }); |
| 61 | |
| 62 | it("uses the status label when there is nothing to report yet", () => { |
| 63 | const row = resolveSubagentRowPresentation({ ...base, status: "pending" }); |
| 64 | |
| 65 | expect(row.detail).toBeNull(); |
| 66 | expect(row.statusLabel).toBe("Working"); |
| 67 | }); |
| 68 | |
| 69 | it("bounds long result previews without dropping the agent's status", () => { |
| 70 | const row = resolveSubagentRowPresentation({ |
| 71 | ...base, |
| 72 | status: "failed", |
| 73 | result: "x".repeat(400), |
| 74 | }); |
| 75 | expect(row.detail).toBe(`${"x".repeat(280)}…`); |
| 76 | expect(row.statusLabel).toBe("Failed"); |
| 77 | }); |
| 78 | }); |