diff --git a/src/hooks/rules-injector/test-isolation.test.ts b/src/hooks/rules-injector/test-isolation.test.ts new file mode 100644 index 000000000..44e71ad0a --- /dev/null +++ b/src/hooks/rules-injector/test-isolation.test.ts @@ -0,0 +1,25 @@ +import { beforeEach, describe, expect, it } from "bun:test"; +import { existsSync, readdirSync } from "node:fs"; +import { RULES_INJECTOR_STORAGE } from "./constants"; + +function readStorageEntries(): readonly string[] { + if (!existsSync(RULES_INJECTOR_STORAGE)) return []; + return readdirSync(RULES_INJECTOR_STORAGE); +} + +describe("rules injector test isolation", () => { + beforeEach(() => { + const leakedEntries = readStorageEntries(); + expect(leakedEntries).toEqual([]); + }); + + it("#given the shared test setup runs #then persisted injected-rule state starts empty", () => { + // given: test-setup beforeEach has already run + + // when + const entries = readStorageEntries(); + + // then + expect(entries).toEqual([]); + }); +}); diff --git a/test-setup.ts b/test-setup.ts index c8e8f8d42..223f9f30e 100644 --- a/test-setup.ts +++ b/test-setup.ts @@ -4,6 +4,7 @@ import { rmSync } from "node:fs" import { _resetForTesting as resetClaudeSessionState } from "./src/features/claude-code-session-state/state" import { _resetTaskToastManagerForTesting as resetTaskToastManager } from "./src/features/task-toast-manager/manager" import { _resetForTesting as resetModelFallbackState } from "./src/hooks/model-fallback/hook" +import { RULES_INJECTOR_STORAGE } from "./src/hooks/rules-injector/constants" import { _resetMemCacheForTesting as resetConnectedProvidersCache } from "./src/shared/connected-providers-cache" import { getOmoOpenCodeCacheDir } from "./src/shared/data-path" import { releaseAllPromptAsyncReservationsForTesting } from "./src/shared/prompt-async-gate" @@ -17,11 +18,16 @@ function cleanupOmoCacheDir(cacheDir: string): void { rmSync(cacheDir, { recursive: true, force: true }) } +function cleanupRulesInjectorStorage(): void { + rmSync(RULES_INJECTOR_STORAGE, { recursive: true, force: true }) +} + beforeEach(() => { environmentSnapshot = { ...process.env } workingDirectorySnapshot = process.cwd() process.env.OMO_DISABLE_POSTHOG = "true" cleanupOmoCacheDir(getOmoOpenCodeCacheDir()) + cleanupRulesInjectorStorage() resetClaudeSessionState() resetTaskToastManager() resetModelFallbackState() @@ -53,6 +59,7 @@ afterEach(() => { cleanupOmoCacheDir(currentCacheDir) cleanupOmoCacheDir(getOmoOpenCodeCacheDir()) + cleanupRulesInjectorStorage() resetTaskToastManager() resetConnectedProvidersCache() releaseAllPromptAsyncReservationsForTesting()