|
| 1 | +import { describe, expect, it } from "vite-plus/test"; |
| 2 | + |
| 3 | +import { subagentDetailPreview } from "./subagentDisplay.js"; |
| 4 | + |
| 5 | +describe("subagentDetailPreview", () => { |
| 6 | + it("prefers progress for live work and results for settled work", () => { |
| 7 | + const details = { progress: "Reading files", result: "Found two\n problems" }; |
| 8 | + expect(subagentDetailPreview({ ...details, status: "running" })).toBe("Reading files"); |
| 9 | + expect(subagentDetailPreview({ ...details, status: "completed" })).toBe("Found two problems"); |
| 10 | + expect( |
| 11 | + subagentDetailPreview({ status: "failed", progress: "Last progress", result: " " }), |
| 12 | + ).toBe("Last progress"); |
| 13 | + expect(subagentDetailPreview({ status: "pending" })).toBeNull(); |
| 14 | + }); |
| 15 | +}); |
| 16 | + |
| 17 | +it.each([279, 280, 281])("preserves the preview boundary at %i characters", (length) => { |
| 18 | + const result = "x".repeat(length); |
| 19 | + expect(subagentDetailPreview({ status: "completed", result })).toBe( |
| 20 | + length > 280 ? "x".repeat(280) + "…" : result, |
| 21 | + ); |
| 22 | +}); |
| 23 | + |
| 24 | +it("normalizes Unicode whitespace and ignores a large hidden suffix", () => { |
| 25 | + const progress = " \u00a0Reading\tfiles\n" + "x".repeat(1_000_000); |
| 26 | + expect(subagentDetailPreview({ status: "running", progress })).toBe( |
| 27 | + "Reading files " + "x".repeat(266) + "…", |
| 28 | + ); |
| 29 | + expect( |
| 30 | + subagentDetailPreview({ status: "completed", result: "x".repeat(280) + " \n\u2028" }), |
| 31 | + ).toBe("x".repeat(280)); |
| 32 | + expect(subagentDetailPreview({ status: "completed", result: "x".repeat(279) + " \n y" })).toBe( |
| 33 | + "x".repeat(279) + "…", |
| 34 | + ); |
| 35 | + expect( |
| 36 | + subagentDetailPreview({ status: "running", progress: "\uFEFF\u2029", result: " Done " }), |
| 37 | + ).toBe("Done"); |
| 38 | + expect(subagentDetailPreview({ status: "failed", result: "x".repeat(279) + "😀" })).toBe( |
| 39 | + "x".repeat(279) + "\uD83D…", |
| 40 | + ); |
| 41 | +}); |
0 commit comments