test(config): avoid module resets in pruning tests

This commit is contained in:
Peter Steinberger
2026-04-23 12:46:41 +01:00
parent 5c9233c64e
commit 09a118c57e

View File

@@ -11,10 +11,8 @@ vi.mock("../config.js", async () => ({
loadConfig: vi.fn().mockReturnValue({}),
}));
let loadConfig: typeof import("../config.js").loadConfig;
let clearSessionStoreCacheForTest: typeof import("./store.js").clearSessionStoreCacheForTest;
let loadSessionStore: typeof import("./store.js").loadSessionStore;
let saveSessionStore: typeof import("./store.js").saveSessionStore;
import { loadConfig } from "../config.js";
import { clearSessionStoreCacheForTest, loadSessionStore, saveSessionStore } from "./store.js";
let mockLoadConfig: ReturnType<typeof vi.fn>;
@@ -88,21 +86,17 @@ describe("Integration: saveSessionStore with pruning", () => {
});
beforeEach(async () => {
vi.resetModules();
({ loadConfig } = await import("../config.js"));
({ clearSessionStoreCacheForTest, loadSessionStore, saveSessionStore } =
await import("./store.js"));
mockLoadConfig = vi.mocked(loadConfig) as ReturnType<typeof vi.fn>;
mockLoadConfig.mockReset();
testDir = await createCaseDir("pruning-integ");
storePath = path.join(testDir, "sessions.json");
savedCacheTtl = process.env.OPENCLAW_SESSION_CACHE_TTL_MS;
process.env.OPENCLAW_SESSION_CACHE_TTL_MS = "0";
clearSessionStoreCacheForTest();
mockLoadConfig.mockClear();
});
afterEach(() => {
vi.restoreAllMocks();
mockLoadConfig.mockReset();
clearSessionStoreCacheForTest();
if (savedCacheTtl === undefined) {
delete process.env.OPENCLAW_SESSION_CACHE_TTL_MS;