From 2204fad5094ef20eae2d11ccdd0e3f897939b5ab Mon Sep 17 00:00:00 2001 From: Priya Raman Date: Fri, 4 Sep 2026 03:18:00 +0000 Subject: [PATCH] test(runner): cover a late attempt rejection in the live-process wait guard Greptile flagged that the deadline test used a callback promise that never settles, so it could not exercise the helper's no-op rejection handler for an attempt that rejects after the deadline already won the race. Add a test where the callback's promise rejects only after the deadline fires, and assert the wait still raises no unhandled rejection. Co-authored-by: Paperclip --- .../src/live/wait-for-live-process.test.ts | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/packages/paperclip-runner/src/live/wait-for-live-process.test.ts b/packages/paperclip-runner/src/live/wait-for-live-process.test.ts index 6e6f5c03442..8617c3088e6 100644 --- a/packages/paperclip-runner/src/live/wait-for-live-process.test.ts +++ b/packages/paperclip-runner/src/live/wait-for-live-process.test.ts @@ -91,4 +91,43 @@ describe("waitForCapabilityLiveProcess", () => { expect(unhandledRejections).toEqual([]); }); + + it("raises no unhandled rejection when an attempt rejects after the deadline already won the race", async () => { + vi.useFakeTimers(); + const unhandledRejections: unknown[] = []; + const onUnhandledRejection = (reason: unknown) => { + unhandledRejections.push(reason); + }; + process.on("unhandledRejection", onUnhandledRejection); + + try { + let rejectLateAttempt: (error: unknown) => void = () => {}; + const promise = waitForCapabilityLiveProcess( + "late-rejection", + () => + new Promise((_resolve, reject) => { + rejectLateAttempt = reject; + }), + ); + const caughtError = promise.catch((error: unknown) => error); + + await vi.advanceTimersByTimeAsync( + CAPABILITY_LIVE_PROCESS_WAIT_DEADLINE_MS + 200, + ); + + const error = (await caughtError) as Error; + expect(error).toBeInstanceOf(Error); + expect(error.message).toContain("late-rejection"); + expect(error.message).toContain( + `did not settle within ${CAPABILITY_LIVE_PROCESS_WAIT_DEADLINE_MS}ms`, + ); + + rejectLateAttempt(new Error("late attempt failure")); + await vi.advanceTimersByTimeAsync(0); + } finally { + process.off("unhandledRejection", onUnhandledRejection); + } + + expect(unhandledRejections).toEqual([]); + }); });