diff --git a/src/config/sessions/store.pruning.integration.test.ts b/src/config/sessions/store.pruning.integration.test.ts index 90aaa3a0708..2b7dd5a7411 100644 --- a/src/config/sessions/store.pruning.integration.test.ts +++ b/src/config/sessions/store.pruning.integration.test.ts @@ -1,8 +1,8 @@ import crypto from "node:crypto"; import fs from "node:fs/promises"; -import os from "node:os"; import path from "node:path"; import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest"; +import { createSuiteTempRootTracker } from "../../test-helpers/temp-dir.js"; import type { SessionEntry } from "./types.js"; // Keep integration tests deterministic: never read a real openclaw.json. @@ -31,8 +31,7 @@ const ENFORCED_MAINTENANCE_OVERRIDE = { const archiveTimestamp = (ms: number) => new Date(ms).toISOString().replaceAll(":", "-"); -let fixtureRoot = ""; -let fixtureCount = 0; +const suiteRootTracker = createSuiteTempRootTracker({ prefix: "openclaw-pruning-integ-" }); function makeEntry(updatedAt: number): SessionEntry { return { sessionId: crypto.randomUUID(), updatedAt }; @@ -65,9 +64,7 @@ function applyCappedMaintenanceConfig(mockLoadConfig: ReturnType) } async function createCaseDir(prefix: string): Promise { - const dir = path.join(fixtureRoot, `${prefix}-${fixtureCount++}`); - await fs.mkdir(dir, { recursive: true }); - return dir; + return await suiteRootTracker.make(prefix); } function createStaleAndFreshStore(now = Date.now()): Record { @@ -83,11 +80,11 @@ describe("Integration: saveSessionStore with pruning", () => { let savedCacheTtl: string | undefined; beforeAll(async () => { - fixtureRoot = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-pruning-integ-")); + await suiteRootTracker.setup(); }); afterAll(async () => { - await fs.rm(fixtureRoot, { recursive: true, force: true }); + await suiteRootTracker.cleanup(); }); beforeEach(async () => { @@ -279,7 +276,7 @@ describe("Integration: saveSessionStore with pruning", () => { applyCappedMaintenanceConfig(mockLoadConfig); const now = Date.now(); - const externalDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-external-cap-")); + const externalDir = await createCaseDir("external-cap"); const externalTranscript = path.join(externalDir, "outside.jsonl"); await fs.writeFile(externalTranscript, "external", "utf-8"); const store: Record = { @@ -299,7 +296,7 @@ describe("Integration: saveSessionStore with pruning", () => { expect(loaded.newest).toBeDefined(); await expect(fs.stat(externalTranscript)).resolves.toBeDefined(); } finally { - await fs.rm(externalDir, { recursive: true, force: true }); + await expect(fs.stat(externalTranscript)).resolves.toBeDefined(); } }); @@ -383,7 +380,7 @@ describe("Integration: saveSessionStore with pruning", () => { }); const now = Date.now(); - const externalDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-external-session-")); + const externalDir = await createCaseDir("external-session"); const externalTranscript = path.join(externalDir, "outside.jsonl"); await fs.writeFile(externalTranscript, "z".repeat(400), "utf-8"); @@ -404,7 +401,7 @@ describe("Integration: saveSessionStore with pruning", () => { await saveSessionStore(storePath, store); await expect(fs.stat(externalTranscript)).resolves.toBeDefined(); } finally { - await fs.rm(externalDir, { recursive: true, force: true }); + await expect(fs.stat(externalTranscript)).resolves.toBeDefined(); } }); });