From d08fa728b4b650820af223ad4eee8aa8f2dfd871 Mon Sep 17 00:00:00 2001 From: YeonGyu-Kim Date: Sat, 21 Feb 2026 05:17:40 +0900 Subject: [PATCH] test(executor): add afterEach cleanup to prevent timer leaks on assertion failure --- .../executor.test.ts | 34 ++++++++----------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/src/hooks/anthropic-context-window-limit-recovery/executor.test.ts b/src/hooks/anthropic-context-window-limit-recovery/executor.test.ts index dbe91044..cc575e18 100644 --- a/src/hooks/anthropic-context-window-limit-recovery/executor.test.ts +++ b/src/hooks/anthropic-context-window-limit-recovery/executor.test.ts @@ -1,4 +1,4 @@ -import { beforeEach, describe, expect, mock, spyOn, test } from "bun:test" +import { afterEach, beforeEach, describe, expect, mock, spyOn, test } from "bun:test" import { executeCompact } from "./executor" import type { AutoCompactState } from "./types" import * as storage from "./storage" @@ -78,6 +78,7 @@ function createFakeTimeouts(): FakeTimeouts { describe("executeCompact lock management", () => { let autoCompactState: AutoCompactState let mockClient: any + let fakeTimeouts: FakeTimeouts const sessionID = "test-session-123" const directory = "/test/dir" const msg = { providerID: "anthropic", modelID: "claude-opus-4-6" } @@ -105,6 +106,11 @@ describe("executeCompact lock management", () => { }, } + fakeTimeouts = createFakeTimeouts() + }) + + afterEach(() => { + fakeTimeouts.restore() }) test("clears lock on successful summarize completion", async () => { @@ -288,16 +294,11 @@ describe("executeCompact lock management", () => { maxTokens: 200000, }) - const fakeTimeouts = createFakeTimeouts() - try { - // when: Execute compaction - await executeCompact(sessionID, msg, autoCompactState, mockClient, directory) + // when: Execute compaction + await executeCompact(sessionID, msg, autoCompactState, mockClient, directory) - // Wait for setTimeout callback - await fakeTimeouts.advanceBy(600) - } finally { - fakeTimeouts.restore() - } + // Wait for setTimeout callback + await fakeTimeouts.advanceBy(600) // then: Lock should be cleared // The continuation happens in setTimeout, but lock is cleared in finally before that @@ -365,16 +366,11 @@ describe("executeCompact lock management", () => { ], }) - const fakeTimeouts = createFakeTimeouts() - try { - // when: Execute compaction - await executeCompact(sessionID, msg, autoCompactState, mockClient, directory) + // when: Execute compaction + await executeCompact(sessionID, msg, autoCompactState, mockClient, directory) - // Wait for setTimeout callback - await fakeTimeouts.advanceBy(600) - } finally { - fakeTimeouts.restore() - } + // Wait for setTimeout callback + await fakeTimeouts.advanceBy(600) // then: Truncation was attempted expect(truncateSpy).toHaveBeenCalled()