|
1 | 1 | import { beforeEach, describe, expect, it, vi } from "vitest"; |
2 | | -import { addTimerTimeoutGraceMs, MAX_TIMER_TIMEOUT_MS } from "../shared/number-coercion.js"; |
| 2 | +import { |
| 3 | +addTimerTimeoutGraceMs, |
| 4 | +MAX_DATE_TIMESTAMP_MS, |
| 5 | +MAX_TIMER_TIMEOUT_MS, |
| 6 | +} from "../shared/number-coercion.js"; |
3 | 7 | |
4 | 8 | const callGatewayMock = vi.fn(); |
5 | 9 | vi.mock("../gateway/call.js", () => ({ |
@@ -539,4 +543,42 @@ describe("waitForAgentRunsToDrain", () => {
|
539 | 543 | vi.useRealTimers(); |
540 | 544 | } |
541 | 545 | }); |
| 546 | + |
| 547 | +it("times out immediately when the computed drain deadline exceeds the Date range", async () => { |
| 548 | +vi.useFakeTimers(); |
| 549 | +vi.setSystemTime(new Date(MAX_DATE_TIMESTAMP_MS)); |
| 550 | +try { |
| 551 | +const result = await waitForAgentRunsToDrain({ |
| 552 | +timeoutMs: 1, |
| 553 | +getPendingRunIds: () => ["run-1"], |
| 554 | +}); |
| 555 | + |
| 556 | +expect(result).toEqual({ |
| 557 | +timedOut: true, |
| 558 | +pendingRunIds: ["run-1"], |
| 559 | +deadlineAtMs: MAX_DATE_TIMESTAMP_MS, |
| 560 | +}); |
| 561 | +expect(callGatewayMock).not.toHaveBeenCalled(); |
| 562 | +} finally { |
| 563 | +vi.useRealTimers(); |
| 564 | +} |
| 565 | +}); |
| 566 | + |
| 567 | +it("ignores invalid caller-supplied drain deadlines", async () => { |
| 568 | +vi.useFakeTimers(); |
| 569 | +vi.setSystemTime(new Date("2026-05-30T00:00:00Z")); |
| 570 | +try { |
| 571 | +const result = await waitForAgentRunsToDrain({ |
| 572 | +deadlineAtMs: Number.POSITIVE_INFINITY, |
| 573 | +getPendingRunIds: () => ["run-1"], |
| 574 | +}); |
| 575 | + |
| 576 | +expect(result.timedOut).toBe(true); |
| 577 | +expect(result.pendingRunIds).toStrictEqual(["run-1"]); |
| 578 | +expect(result.deadlineAtMs).toBe(Date.now()); |
| 579 | +expect(callGatewayMock).not.toHaveBeenCalled(); |
| 580 | +} finally { |
| 581 | +vi.useRealTimers(); |
| 582 | +} |
| 583 | +}); |
542 | 584 | }); |