Merge pull request #4201 from code-yeongyu/fix/test-isolation-cross-test-state-leak

fix(test-isolation): isolate rules injector storage and fixture home
This commit is contained in:
YeonGyu-Kim
2026-05-20 13:38:41 +09:00
committed by GitHub
2 changed files with 32 additions and 0 deletions
@@ -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([]);
});
});
+7
View File
@@ -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()