| 1 | import * as DateTime from "effect/DateTime"; |
| 2 | import { describe, expect, it } from "vite-plus/test"; |
| 3 | import { subagentCardDetail, subagentCardElapsed } from "./subagent-card-presentation"; |
| 4 | |
| 5 | describe("subagent card", () => { |
| 6 | it("shows readable result text and suppresses generic completion messages", () => { |
| 7 | expect( |
| 8 | subagentCardDetail( |
| 9 | "- Updated `app.ts` with [the fix](https://example.com).\n- Checked tests.", |
| 10 | ), |
| 11 | ).toBe("Updated app.ts with the fix. Checked tests."); |
| 12 | expect(subagentCardDetail("Child task ended with status failed.")).toBeNull(); |
| 13 | expect(subagentCardDetail(" ")).toBeNull(); |
| 14 | }); |
| 15 | |
| 16 | const start = DateTime.makeUnsafe("2026-09-21T12:00:00Z"); |
| 17 | const end = DateTime.makeUnsafe("2026-09-21T12:01:00Z"); |
| 18 | const later = DateTime.makeUnsafe("2026-09-21T12:02:00Z"); |
| 19 | const done = { status: "completed" as const, startedAt: start, completedAt: end }; |
| 20 | |
| 21 | it("freezes settled durations and spans the group's wall time", () => { |
| 22 | expect(subagentCardElapsed([done], DateTime.toEpochMillis(later))).toBe("1m"); |
| 23 | expect( |
| 24 | subagentCardElapsed( |
| 25 | [done, { ...done, startedAt: end, completedAt: later }], |
| 26 | DateTime.toEpochMillis(later), |
| 27 | ), |
| 28 | ).toBe("2m"); |
| 29 | }); |
| 30 | |
| 31 | it("counts live work but never uses a settled agent's age as its duration", () => { |
| 32 | const unfinished = { ...done, completedAt: null }; |
| 33 | expect(subagentCardElapsed([unfinished], DateTime.toEpochMillis(later))).toBeNull(); |
| 34 | expect( |
| 35 | subagentCardElapsed([{ ...unfinished, status: "running" }], DateTime.toEpochMillis(later)), |
| 36 | ).toBe("2m"); |
| 37 | expect( |
| 38 | subagentCardElapsed([{ ...unfinished, status: "idle" }], DateTime.toEpochMillis(later)), |
| 39 | ).toBeNull(); |
| 40 | expect( |
| 41 | subagentCardElapsed([{ ...done, startedAt: null }], DateTime.toEpochMillis(later)), |
| 42 | ).toBeNull(); |
| 43 | }); |
| 44 | }); |