From 9697925d4a2c4a78fdfb7b253f78beba99ca2956 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Mon, 6 Apr 2026 23:45:02 +0100 Subject: [PATCH] test: reuse memory-wiki temp roots --- extensions/memory-wiki/src/compile.test.ts | 32 +++++++++++++---- .../memory-wiki/src/source-sync.test.ts | 34 +++++++++++++++---- 2 files changed, 53 insertions(+), 13 deletions(-) diff --git a/extensions/memory-wiki/src/compile.test.ts b/extensions/memory-wiki/src/compile.test.ts index 7f04d33a3aa..42a6ed1b888 100644 --- a/extensions/memory-wiki/src/compile.test.ts +++ b/extensions/memory-wiki/src/compile.test.ts @@ -1,6 +1,7 @@ import fs from "node:fs/promises"; +import os from "node:os"; import path from "node:path"; -import { describe, expect, it } from "vitest"; +import { afterAll, beforeAll, describe, expect, it } from "vitest"; import { compileMemoryWikiVault } from "./compile.js"; import { renderWikiMarkdown } from "./markdown.js"; import { createMemoryWikiTestHarness } from "./test-helpers.js"; @@ -8,9 +9,26 @@ import { createMemoryWikiTestHarness } from "./test-helpers.js"; const { createVault } = createMemoryWikiTestHarness(); describe("compileMemoryWikiVault", () => { + let suiteRoot = ""; + let caseId = 0; + + beforeAll(async () => { + suiteRoot = await fs.mkdtemp(path.join(os.tmpdir(), "memory-wiki-compile-suite-")); + }); + + afterAll(async () => { + if (suiteRoot) { + await fs.rm(suiteRoot, { recursive: true, force: true }); + } + }); + + function nextCaseRoot() { + return path.join(suiteRoot, `case-${caseId++}`); + } + it("writes root and directory indexes for native markdown", async () => { const { rootDir, config } = await createVault({ - prefix: "memory-wiki-compile-", + rootDir: nextCaseRoot(), initialize: true, }); @@ -36,7 +54,7 @@ describe("compileMemoryWikiVault", () => { it("renders obsidian-friendly links when configured", async () => { const { rootDir, config } = await createVault({ - prefix: "memory-wiki-compile-", + rootDir: nextCaseRoot(), initialize: true, config: { vault: { renderMode: "obsidian" }, @@ -61,7 +79,7 @@ describe("compileMemoryWikiVault", () => { it("writes related blocks from source ids and shared sources", async () => { const { rootDir, config } = await createVault({ - prefix: "memory-wiki-compile-", + rootDir: nextCaseRoot(), initialize: true, }); @@ -121,7 +139,7 @@ describe("compileMemoryWikiVault", () => { it("writes dashboard report pages when createDashboards is enabled", async () => { const { rootDir, config } = await createVault({ - prefix: "memory-wiki-compile-", + rootDir: nextCaseRoot(), initialize: true, }); @@ -174,7 +192,7 @@ describe("compileMemoryWikiVault", () => { it("skips dashboard report pages when createDashboards is disabled", async () => { const { rootDir, config } = await createVault({ - prefix: "memory-wiki-compile-", + rootDir: nextCaseRoot(), initialize: true, config: { render: { createDashboards: false }, @@ -203,7 +221,7 @@ describe("compileMemoryWikiVault", () => { it("ignores generated related links when computing backlinks on repeated compile", async () => { const { rootDir, config } = await createVault({ - prefix: "memory-wiki-compile-", + rootDir: nextCaseRoot(), initialize: true, }); diff --git a/extensions/memory-wiki/src/source-sync.test.ts b/extensions/memory-wiki/src/source-sync.test.ts index dc86e5c538a..4c702abe675 100644 --- a/extensions/memory-wiki/src/source-sync.test.ts +++ b/extensions/memory-wiki/src/source-sync.test.ts @@ -1,20 +1,40 @@ import fs from "node:fs/promises"; +import os from "node:os"; import path from "node:path"; -import { describe, expect, it } from "vitest"; +import { afterAll, beforeAll, describe, expect, it } from "vitest"; import { syncMemoryWikiImportedSources } from "./source-sync.js"; import { createMemoryWikiTestHarness } from "./test-helpers.js"; -const { createTempDir, createVault } = createMemoryWikiTestHarness(); +const { createVault } = createMemoryWikiTestHarness(); describe("syncMemoryWikiImportedSources", () => { + let suiteRoot = ""; + let caseId = 0; + + beforeAll(async () => { + suiteRoot = await fs.mkdtemp(path.join(os.tmpdir(), "memory-wiki-source-sync-suite-")); + }); + + afterAll(async () => { + if (suiteRoot) { + await fs.rm(suiteRoot, { recursive: true, force: true }); + } + }); + + function nextCaseRoot() { + return path.join(suiteRoot, `case-${caseId++}`); + } + it("refreshes indexes when imported sources change and skips when they do not", async () => { - const privateDir = await createTempDir("memory-wiki-sync-private-"); + const caseRoot = nextCaseRoot(); + const privateDir = path.join(caseRoot, "private"); const sourcePath = path.join(privateDir, "alpha.md"); + await fs.mkdir(privateDir, { recursive: true }); await fs.writeFile(sourcePath, "# Alpha\n", "utf8"); const { rootDir: vaultDir, config } = await createVault({ - prefix: "memory-wiki-sync-vault-", + rootDir: path.join(caseRoot, "vault"), config: { vaultMode: "unsafe-local", unsafeLocal: { @@ -48,13 +68,15 @@ describe("syncMemoryWikiImportedSources", () => { }); it("respects ingest.autoCompile=false", async () => { - const privateDir = await createTempDir("memory-wiki-sync-private-"); + const caseRoot = nextCaseRoot(); + const privateDir = path.join(caseRoot, "private"); const sourcePath = path.join(privateDir, "alpha.md"); + await fs.mkdir(privateDir, { recursive: true }); await fs.writeFile(sourcePath, "# Alpha\n", "utf8"); const { config } = await createVault({ - prefix: "memory-wiki-sync-vault-", + rootDir: path.join(caseRoot, "vault"), config: { vaultMode: "unsafe-local", unsafeLocal: {