diff --git a/extensions/memory-core/src/memory/temporal-decay.test.ts b/extensions/memory-core/src/memory/temporal-decay.test.ts index edb4df553d6..d1661ce482d 100644 --- a/extensions/memory-core/src/memory/temporal-decay.test.ts +++ b/extensions/memory-core/src/memory/temporal-decay.test.ts @@ -1,7 +1,7 @@ import fs from "node:fs/promises"; -import os from "node:os"; import path from "node:path"; -import { afterEach, describe, expect, it } from "vitest"; +import { describe, expect, it } from "vitest"; +import { createMemoryCoreTestHarness } from "../test-helpers.js"; import { mergeHybridResults } from "./hybrid.js"; import { applyTemporalDecayToHybridResults, @@ -11,14 +11,7 @@ import { const DAY_MS = 24 * 60 * 60 * 1000; const NOW_MS = Date.UTC(2026, 1, 10, 0, 0, 0); - -const tempDirs: string[] = []; - -async function makeTempDir(): Promise { - const dir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-temporal-decay-")); - tempDirs.push(dir); - return dir; -} +const { createTempWorkspace } = createMemoryCoreTestHarness(); function createVectorMemoryEntry(params: { id: string; @@ -51,14 +44,6 @@ async function mergeVectorResultsWithTemporalDecay( }); } -afterEach(async () => { - await Promise.all( - tempDirs.splice(0).map(async (dir) => { - await fs.rm(dir, { recursive: true, force: true }); - }), - ); -}); - describe("temporal decay", () => { it("matches exponential decay formula", () => { const halfLifeDays = 30; @@ -79,7 +64,7 @@ describe("temporal decay", () => { }); it("does not decay evergreen memory files", async () => { - const dir = await makeTempDir(); + const dir = await createTempWorkspace("openclaw-temporal-decay-"); const rootMemoryPath = path.join(dir, "MEMORY.md"); const topicPath = path.join(dir, "memory", "projects.md"); @@ -154,7 +139,7 @@ describe("temporal decay", () => { }); it("uses file mtime fallback for non-memory sources", async () => { - const dir = await makeTempDir(); + const dir = await createTempWorkspace("openclaw-temporal-decay-"); const sessionPath = path.join(dir, "sessions", "thread.jsonl"); await fs.mkdir(path.dirname(sessionPath), { recursive: true }); await fs.writeFile(sessionPath, "{}\n"); diff --git a/extensions/memory-core/src/tools.citations.test.ts b/extensions/memory-core/src/tools.citations.test.ts index 983ef66cf04..c2bce446936 100644 --- a/extensions/memory-core/src/tools.citations.test.ts +++ b/extensions/memory-core/src/tools.citations.test.ts @@ -1,5 +1,4 @@ import fs from "node:fs/promises"; -import os from "node:os"; import path from "node:path"; import { beforeEach, describe, expect, it } from "vitest"; import { @@ -16,6 +15,7 @@ import { setMemoryWorkspaceDir, type MemoryReadParams, } from "../../../test/helpers/memory-tool-manager-mock.js"; +import { createMemoryCoreTestHarness } from "./test-helpers.js"; import { asOpenClawConfig, createAutoCitationsMemorySearchTool, @@ -25,6 +25,8 @@ import { expectUnavailableMemorySearchDetails, } from "./tools.test-helpers.js"; +const { createTempWorkspace } = createMemoryCoreTestHarness(); + async function waitFor(task: () => Promise, timeoutMs: number = 1500): Promise { const startedAt = Date.now(); let lastError: unknown; @@ -180,7 +182,7 @@ describe("memory tools", () => { }); it("persists short-term recall events from memory_search tool hits", async () => { - const workspaceDir = await fs.mkdtemp(path.join(os.tmpdir(), "memory-tools-recall-")); + const workspaceDir = await createTempWorkspace("memory-tools-recall-"); try { setMemoryBackend("builtin"); setMemoryWorkspaceDir(workspaceDir);