From 2320ac23ee41f9b4224cc71bfe8f81b66fd67fe5 Mon Sep 17 00:00:00 2001 From: Akash-M-D Date: Wed, 14 Oct 2026 00:59:34 +0530 Subject: [PATCH] test(process): preserve terminal deadline expiry regression (#2055) * fix(cli): preserve import-map option descriptions * fix(process): report no remaining time after a provider deadline fires Node timers can fire while performance.now() is still a fraction of a millisecond short of the monotonic deadline. ProviderStartupDeadline then reported interruption "timeout" and an aborted signal while remainingMs() returned ceil(0.x) = 1, so polling loops guarded by remainingMs() > 0 (Hopper and Ghidra startup) could run past an elapsed deadline, and the real-timer test "aborts a bounded wait when its real monotonic deadline expires" failed intermittently in CI (expected 1 to be 0). Once the deadline's own timer has classified a timeout, report zero remaining time. A deterministic regression test fires the timer with the monotonic clock 0.4 ms short of the deadline. Co-Authored-By: Claude Opus 5.5 * test(process): keep terminal deadline expiry sticky --------- Co-authored-by: morluto <76467478+morluto@users.noreply.github.com> Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 --- src/process/ProviderDeadline.test.ts | 9 ++++++--- src/process/ProviderDeadline.ts | 3 ++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/process/ProviderDeadline.test.ts b/src/process/ProviderDeadline.test.ts index 6f26c870e..727132899 100644 --- a/src/process/ProviderDeadline.test.ts +++ b/src/process/ProviderDeadline.test.ts @@ -279,9 +279,9 @@ it("releases the timer and listener on dispose with a pending wait", async () => } }); -// Preserve the authored fractional-clock control while following the current -// owning deadline's re-arm contract for an early native timer callback. -it("reports zero after the re-armed deadline reaches a fractional early callback", async () => { +// Retain the authored terminal-budget regression under the newer monotonic +// expiry policy and re-arm contract for an early native timer callback. +it("reports no remaining time after terminal expiry near the monotonic boundary", async () => { vi.useFakeTimers({ toFake: ["setTimeout", "clearTimeout"] }); const now = vi.spyOn(performance, "now").mockReturnValue(1_000); const deadline = new ProviderStartupDeadline(40); @@ -294,6 +294,9 @@ it("reports zero after the re-armed deadline reaches a fractional early callback await vi.advanceTimersByTimeAsync(1); expect(deadline.signal.aborted).toBe(true); expect(deadline.interruption).toBe("timeout"); + // A terminal timeout stays terminal even if the monotonic source is + // observed below its deadline after the abort timer has fired. + now.mockReturnValue(1_039); expect(deadline.remainingMs()).toBe(0); } finally { deadline.dispose(); diff --git a/src/process/ProviderDeadline.ts b/src/process/ProviderDeadline.ts index 7681ecf62..26e1b0fb0 100644 --- a/src/process/ProviderDeadline.ts +++ b/src/process/ProviderDeadline.ts @@ -80,7 +80,8 @@ export class ProviderStartupDeadline { /** Milliseconds still available to the next startup phase. */ remainingMs(): number { // Node timers can fire a fraction of a millisecond before the monotonic - // deadline, so an elapsed timer must not report time left to spend. + // deadline, so an elapsed timer must not report time left to spend. A + // terminal timeout also cannot regain budget after later clock queries. if (this.#interruption === "timeout") return 0; return Math.max(0, Math.ceil(this.#deadlineAt - performance.now())); }