|
| 1 | +import { describe, expect, it } from "vitest"; |
| 2 | +import { MAX_TIMER_TIMEOUT_MS } from "../shared/number-coercion.js"; |
| 3 | +import { |
| 4 | + resolveSubagentRunDeadlineMs, |
| 5 | + resolveSubagentRunDurationMs, |
| 6 | + resolveSubagentRunTimerDelayMs, |
| 7 | +} from "./subagent-run-timeout.js"; |
| 8 | + |
| 9 | +describe("subagent run timeout helpers", () => { |
| 10 | + it("preserves semantic deadlines longer than the timer cap", () => { |
| 11 | + const thirtyDaysSeconds = 30 * 24 * 60 * 60; |
| 12 | + |
| 13 | + expect(resolveSubagentRunDurationMs(thirtyDaysSeconds)).toBe(2_592_000_000); |
| 14 | + expect( |
| 15 | + resolveSubagentRunDeadlineMs({ |
| 16 | + createdAt: 1_000, |
| 17 | + runTimeoutSeconds: thirtyDaysSeconds, |
| 18 | + }), |
| 19 | + ).toBe(2_592_001_000); |
| 20 | + }); |
| 21 | + |
| 22 | + it("caps actual timer delays without shortening semantic durations", () => { |
| 23 | + const thirtyDaysSeconds = 30 * 24 * 60 * 60; |
| 24 | + |
| 25 | + expect(resolveSubagentRunTimerDelayMs(thirtyDaysSeconds)).toBe(MAX_TIMER_TIMEOUT_MS); |
| 26 | + expect(resolveSubagentRunDurationMs(thirtyDaysSeconds)).toBeGreaterThan(MAX_TIMER_TIMEOUT_MS); |
| 27 | + }); |
| 28 | + |
| 29 | + it("ignores invalid timeout seconds and invalid start timestamps", () => { |
| 30 | + expect(resolveSubagentRunDurationMs(Number.NaN)).toBeUndefined(); |
| 31 | + expect(resolveSubagentRunDurationMs(0)).toBeUndefined(); |
| 32 | + expect( |
| 33 | + resolveSubagentRunDeadlineMs({ |
| 34 | + createdAt: Number.POSITIVE_INFINITY, |
| 35 | + runTimeoutSeconds: 60, |
| 36 | + }), |
| 37 | + ).toBeUndefined(); |
| 38 | + }); |
| 39 | +}); |
0 commit comments