test(memory-core): reuse workspace helper in temp dir tests

This commit is contained in:
Vincent Koc
2026-04-06 05:28:10 +01:00
parent 9ba97ceaed
commit a896d5df0c
2 changed files with 9 additions and 22 deletions

View File

@@ -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<string> {
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");