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:
@@ -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([]);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -4,6 +4,7 @@ import { rmSync } from "node:fs"
|
|||||||
import { _resetForTesting as resetClaudeSessionState } from "./src/features/claude-code-session-state/state"
|
import { _resetForTesting as resetClaudeSessionState } from "./src/features/claude-code-session-state/state"
|
||||||
import { _resetTaskToastManagerForTesting as resetTaskToastManager } from "./src/features/task-toast-manager/manager"
|
import { _resetTaskToastManagerForTesting as resetTaskToastManager } from "./src/features/task-toast-manager/manager"
|
||||||
import { _resetForTesting as resetModelFallbackState } from "./src/hooks/model-fallback/hook"
|
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 { _resetMemCacheForTesting as resetConnectedProvidersCache } from "./src/shared/connected-providers-cache"
|
||||||
import { getOmoOpenCodeCacheDir } from "./src/shared/data-path"
|
import { getOmoOpenCodeCacheDir } from "./src/shared/data-path"
|
||||||
import { releaseAllPromptAsyncReservationsForTesting } from "./src/shared/prompt-async-gate"
|
import { releaseAllPromptAsyncReservationsForTesting } from "./src/shared/prompt-async-gate"
|
||||||
@@ -17,11 +18,16 @@ function cleanupOmoCacheDir(cacheDir: string): void {
|
|||||||
rmSync(cacheDir, { recursive: true, force: true })
|
rmSync(cacheDir, { recursive: true, force: true })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function cleanupRulesInjectorStorage(): void {
|
||||||
|
rmSync(RULES_INJECTOR_STORAGE, { recursive: true, force: true })
|
||||||
|
}
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
environmentSnapshot = { ...process.env }
|
environmentSnapshot = { ...process.env }
|
||||||
workingDirectorySnapshot = process.cwd()
|
workingDirectorySnapshot = process.cwd()
|
||||||
process.env.OMO_DISABLE_POSTHOG = "true"
|
process.env.OMO_DISABLE_POSTHOG = "true"
|
||||||
cleanupOmoCacheDir(getOmoOpenCodeCacheDir())
|
cleanupOmoCacheDir(getOmoOpenCodeCacheDir())
|
||||||
|
cleanupRulesInjectorStorage()
|
||||||
resetClaudeSessionState()
|
resetClaudeSessionState()
|
||||||
resetTaskToastManager()
|
resetTaskToastManager()
|
||||||
resetModelFallbackState()
|
resetModelFallbackState()
|
||||||
@@ -53,6 +59,7 @@ afterEach(() => {
|
|||||||
|
|
||||||
cleanupOmoCacheDir(currentCacheDir)
|
cleanupOmoCacheDir(currentCacheDir)
|
||||||
cleanupOmoCacheDir(getOmoOpenCodeCacheDir())
|
cleanupOmoCacheDir(getOmoOpenCodeCacheDir())
|
||||||
|
cleanupRulesInjectorStorage()
|
||||||
resetTaskToastManager()
|
resetTaskToastManager()
|
||||||
resetConnectedProvidersCache()
|
resetConnectedProvidersCache()
|
||||||
releaseAllPromptAsyncReservationsForTesting()
|
releaseAllPromptAsyncReservationsForTesting()
|
||||||
|
|||||||
Reference in New Issue
Block a user