The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 03:37 UTC
| 1 | import { describe, expect, it } from "vite-plus/test"; |
| 2 | |
| 3 | import { deriveSubagentElapsedMs, formatDuration } from "./orchestrationTiming.ts"; |
| 4 | |
| 5 | describe("formatDuration", () => { |
| 6 | it.each([ |
| 7 | [59_000, "59s"], |
| 8 | [59_500, "1m 0s"], |
| 9 | [60_000, "1m 0s"], |
| 10 | [720_000, "12m 0s"], |
| 11 | [736_000, "12m 16s"], |
| 12 | [3_600_000, "1h"], |
| 13 | [3_660_000, "1h 1m 0s"], |
| 14 | ])("formats %i milliseconds as %s", (durationMs, expected) => { |
| 15 | expect(formatDuration(durationMs)).toBe(expected); |
| 16 | }); |
| 17 | }); |
| 18 | |
| 19 | describe("deriveSubagentElapsedMs", () => { |
| 20 | const startedAt = "2026-09-21T12:00:00.000Z"; |
| 21 | const completedAt = "2026-09-21T12:00:10.000Z"; |
| 22 | const now = Date.parse("2026-09-21T13:00:00.000Z"); |
| 23 | it.each(["idle", "completed", "failed"] as const)( |
| 24 | "does not count the age of %s work with unknown completion timing", |
| 25 | (status) => { |
| 26 | expect(deriveSubagentElapsedMs({ status, startedAt, completedAt: null }, now)).toBeNull(); |
| 27 | expect(deriveSubagentElapsedMs({ status, startedAt, completedAt }, now)).toBe(10_000); |
| 28 | }, |
| 29 | ); |
| 30 | it("counts a resumed activation despite a stale previous completion timestamp", () => { |
| 31 | expect(deriveSubagentElapsedMs({ status: "running", startedAt, completedAt }, now)).toBe( |
| 32 | 3_600_000, |
| 33 | ); |
| 34 | expect( |
| 35 | deriveSubagentElapsedMs({ status: "running", startedAt: null, completedAt: null }, now), |
| 36 | ).toBeNull(); |
| 37 | }); |
| 38 | }); |