From fcd0011a6b8cad14e4e57b0278e746c6520d8b76 Mon Sep 17 00:00:00 2001 From: YeonGyu-Kim Date: Sun, 17 May 2026 03:50:02 +0900 Subject: [PATCH] test(atlas): track active timers instead of scheduled delays in setTimeout mock - Replace the simple scheduledDelays array with an activeTimers Map so that clearTimeout removes timers from the tracked set. - This prevents false positives when internal withDispatchTimeout calls setTimeout for safety timeouts that are immediately cancelled. - Keeps the test intent unchanged: only genuinely scheduled retries are counted as delayed duplicate retries. --- src/hooks/atlas/index.test.ts | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/hooks/atlas/index.test.ts b/src/hooks/atlas/index.test.ts index fb9094d4c..c7c8d9b28 100644 --- a/src/hooks/atlas/index.test.ts +++ b/src/hooks/atlas/index.test.ts @@ -1674,11 +1674,17 @@ session_id: ses_untrusted_999 writeBoulderState(TEST_DIR, state) const originalSetTimeout = globalThis.setTimeout - const scheduledDelays: number[] = [] + const originalClearTimeout = globalThis.clearTimeout + const activeTimers = new Map, number>() globalThis.setTimeout = ((_handler: Parameters[0], timeout?: number, ..._args: unknown[]) => { - scheduledDelays.push(timeout ?? 0) - return originalSetTimeout(() => undefined, 0) + const id = originalSetTimeout(() => undefined, 0) + activeTimers.set(id, timeout ?? 0) + return id }) as typeof setTimeout + globalThis.clearTimeout = ((id: ReturnType) => { + activeTimers.delete(id) + originalClearTimeout(id) + }) as typeof clearTimeout try { const mockInput = createMockPluginInput() @@ -1702,10 +1708,12 @@ session_id: ses_untrusted_999 }) // then - stale idle is consumed, not converted into another scheduled continuation + const scheduledDelays = Array.from(activeTimers.values()) expect(mockInput._promptMock).toHaveBeenCalledTimes(1) expect(scheduledDelays.filter((delay) => delay >= 5_000 && delay !== DEFAULT_PROMPT_DISPATCH_TIMEOUT_MS)).toHaveLength(0) } finally { globalThis.setTimeout = originalSetTimeout + globalThis.clearTimeout = originalClearTimeout } }) @@ -2519,7 +2527,9 @@ session_id: ses_untrusted_999 capturedTimers.delete(id) return } - originalClearTimeout(id) + if (id !== undefined) { + originalClearTimeout(id) + } }) as typeof clearTimeout })