test: trim memory-core fixture setup

This commit is contained in:
Peter Steinberger
2026-04-06 23:24:57 +01:00
parent ca8570be02
commit 637a5b137e
3 changed files with 18 additions and 24 deletions

View File

@@ -201,6 +201,7 @@ describe("memory cli", () => {
async function withTempWorkspace(run: (workspaceDir: string) => Promise<void>) {
const workspaceDir = path.join(workspaceFixtureRoot, `case-${workspaceCaseId++}`);
await fs.mkdir(workspaceDir, { recursive: true });
await fs.mkdir(path.join(workspaceDir, "memory", ".dreams"), { recursive: true });
await run(workspaceDir);
}
@@ -210,7 +211,6 @@ describe("memory cli", () => {
lines: string[],
): Promise<void> {
const notePath = path.join(workspaceDir, "memory", `${date}.md`);
await fs.mkdir(path.dirname(notePath), { recursive: true });
await fs.writeFile(notePath, `${lines.join("\n")}\n`, "utf-8");
}
@@ -409,7 +409,6 @@ describe("memory cli", () => {
it("repairs invalid recall metadata and stale locks with status --fix", async () => {
await withTempWorkspace(async (workspaceDir) => {
const storePath = path.join(workspaceDir, "memory", ".dreams", "short-term-recall.json");
await fs.mkdir(path.dirname(storePath), { recursive: true });
await fs.writeFile(
storePath,
JSON.stringify(
@@ -469,7 +468,6 @@ describe("memory cli", () => {
it("shows the fix hint only before --fix has been run", async () => {
await withTempWorkspace(async (workspaceDir) => {
const storePath = path.join(workspaceDir, "memory", ".dreams", "short-term-recall.json");
await fs.mkdir(path.dirname(storePath), { recursive: true });
await fs.writeFile(storePath, " \n", "utf-8");
const close = vi.fn(async () => {});

View File

@@ -91,7 +91,6 @@ async function withDreamingTestClock(run: () => Promise<void>) {
}
async function writeDailyNote(workspaceDir: string, lines: string[]): Promise<void> {
await fs.mkdir(path.join(workspaceDir, "memory"), { recursive: true });
await fs.writeFile(
path.join(workspaceDir, "memory", `${DREAMING_TEST_DAY}.md`),
lines.join("\n"),
@@ -99,6 +98,12 @@ async function writeDailyNote(workspaceDir: string, lines: string[]): Promise<vo
);
}
async function createDreamingWorkspace(): Promise<string> {
const workspaceDir = await createTempWorkspace("openclaw-dreaming-phases-");
await fs.mkdir(path.join(workspaceDir, "memory"), { recursive: true });
return workspaceDir;
}
function createLightDreamingHarness(workspaceDir: string) {
return createHarness(LIGHT_DREAMING_TEST_CONFIG, workspaceDir);
}
@@ -128,7 +133,7 @@ async function readCandidateSnippets(workspaceDir: string, nowIso: string): Prom
describe("memory-core dreaming phases", () => {
it("does not re-ingest managed light dreaming blocks from daily notes", async () => {
const workspaceDir = await createTempWorkspace("openclaw-dreaming-phases-");
const workspaceDir = await createDreamingWorkspace();
await withDreamingTestClock(async () => {
await writeDailyNote(workspaceDir, [
`# ${DREAMING_TEST_DAY}`,
@@ -166,7 +171,7 @@ describe("memory-core dreaming phases", () => {
});
it("stops stripping a malformed managed block at the next section boundary", async () => {
const workspaceDir = await createTempWorkspace("openclaw-dreaming-phases-");
const workspaceDir = await createDreamingWorkspace();
await withDreamingTestClock(async () => {
await writeDailyNote(workspaceDir, [
`# ${DREAMING_TEST_DAY}`,
@@ -196,8 +201,7 @@ describe("memory-core dreaming phases", () => {
});
it("checkpoints daily ingestion and skips unchanged daily files", async () => {
const workspaceDir = await createTempWorkspace("openclaw-dreaming-phases-");
await fs.mkdir(path.join(workspaceDir, "memory"), { recursive: true });
const workspaceDir = await createDreamingWorkspace();
const dailyPath = path.join(workspaceDir, "memory", "2026-04-05.md");
await fs.writeFile(
dailyPath,
@@ -253,8 +257,7 @@ describe("memory-core dreaming phases", () => {
});
it("ingests recent daily memory files even before recall traffic exists", async () => {
const workspaceDir = await createTempWorkspace("openclaw-dreaming-phases-");
await fs.mkdir(path.join(workspaceDir, "memory"), { recursive: true });
const workspaceDir = await createDreamingWorkspace();
await fs.writeFile(
path.join(workspaceDir, "memory", "2026-04-05.md"),
["# 2026-04-05", "", "- Move backups to S3 Glacier.", "- Keep retention at 365 days."].join(
@@ -317,8 +320,7 @@ describe("memory-core dreaming phases", () => {
});
it("keeps section context when chunking durable daily notes", async () => {
const workspaceDir = await createTempWorkspace("openclaw-dreaming-phases-");
await fs.mkdir(path.join(workspaceDir, "memory"), { recursive: true });
const workspaceDir = await createDreamingWorkspace();
await fs.writeFile(
path.join(workspaceDir, "memory", "2026-04-05.md"),
[
@@ -377,8 +379,7 @@ describe("memory-core dreaming phases", () => {
});
it("drops generic day headings but keeps meaningful section labels", async () => {
const workspaceDir = await createTempWorkspace("openclaw-dreaming-phases-");
await fs.mkdir(path.join(workspaceDir, "memory"), { recursive: true });
const workspaceDir = await createDreamingWorkspace();
await fs.writeFile(
path.join(workspaceDir, "memory", "2026-04-05.md"),
[
@@ -444,8 +445,7 @@ describe("memory-core dreaming phases", () => {
});
it("splits noisy daily notes into a few coherent chunks instead of one line per item", async () => {
const workspaceDir = await createTempWorkspace("openclaw-dreaming-phases-");
await fs.mkdir(path.join(workspaceDir, "memory"), { recursive: true });
const workspaceDir = await createDreamingWorkspace();
await fs.writeFile(
path.join(workspaceDir, "memory", "2026-04-05.md"),
[

View File

@@ -38,6 +38,7 @@ describe("short-term promotion", () => {
async function withTempWorkspace(run: (workspaceDir: string) => Promise<void>) {
const workspaceDir = path.join(fixtureRoot, `case-${caseId++}`);
await fs.mkdir(path.join(workspaceDir, "memory", ".dreams"), { recursive: true });
await run(workspaceDir);
}
@@ -47,7 +48,6 @@ describe("short-term promotion", () => {
lines: string[],
): Promise<string> {
const notePath = path.join(workspaceDir, "memory", `${date}.md`);
await fs.mkdir(path.dirname(notePath), { recursive: true });
await fs.writeFile(notePath, `${lines.join("\n")}\n`, "utf-8");
return notePath;
}
@@ -124,7 +124,7 @@ describe("short-term promotion", () => {
it("serializes concurrent recall writes so counts are not lost", async () => {
await withTempWorkspace(async (workspaceDir) => {
await Promise.all(
Array.from({ length: 20 }, (_, index) =>
Array.from({ length: 12 }, (_, index) =>
recordShortTermRecalls({
workspaceDir,
query: `backup-${index % 4}`,
@@ -149,7 +149,7 @@ describe("short-term promotion", () => {
minUniqueQueries: 0,
});
expect(ranked).toHaveLength(1);
expect(ranked[0]?.recallCount).toBe(20);
expect(ranked[0]?.recallCount).toBe(12);
expect(ranked[0]?.uniqueQueries).toBe(4);
});
});
@@ -1005,7 +1005,6 @@ describe("short-term promotion", () => {
it("audits and repairs invalid store metadata plus stale locks", async () => {
await withTempWorkspace(async (workspaceDir) => {
const storePath = resolveShortTermRecallStorePath(workspaceDir);
await fs.mkdir(path.dirname(storePath), { recursive: true });
await fs.writeFile(
storePath,
JSON.stringify(
@@ -1069,7 +1068,6 @@ describe("short-term promotion", () => {
it("repairs empty recall-store files without throwing", async () => {
await withTempWorkspace(async (workspaceDir) => {
const storePath = resolveShortTermRecallStorePath(workspaceDir);
await fs.mkdir(path.dirname(storePath), { recursive: true });
await fs.writeFile(storePath, " \n", "utf-8");
const repair = await repairShortTermPromotionArtifacts({ workspaceDir });
@@ -1086,7 +1084,6 @@ describe("short-term promotion", () => {
it("does not rewrite an already normalized healthy recall store", async () => {
await withTempWorkspace(async (workspaceDir) => {
const storePath = resolveShortTermRecallStorePath(workspaceDir);
await fs.mkdir(path.dirname(storePath), { recursive: true });
const snippet = "Gateway host uses qmd vector search for router notes.";
const raw = `${JSON.stringify(
{
@@ -1133,7 +1130,6 @@ describe("short-term promotion", () => {
await withTempWorkspace(async (workspaceDir) => {
const storePath = resolveShortTermRecallStorePath(workspaceDir);
const lockPath = resolveShortTermRecallLockPath(workspaceDir);
await fs.mkdir(path.dirname(storePath), { recursive: true });
await fs.writeFile(
storePath,
JSON.stringify(
@@ -1159,7 +1155,7 @@ describe("short-term promotion", () => {
return result;
});
await new Promise((resolve) => setTimeout(resolve, 45));
await new Promise((resolve) => setTimeout(resolve, 41));
expect(settled).toBe(false);
await fs.unlink(lockPath);