From 859c8133c0727135ffa7920762c668e90bfbb7e4 Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Mon, 6 Apr 2026 05:45:36 +0100 Subject: [PATCH] test(tooling): reuse temp dir helpers in script tests --- src/scripts/canvas-a2ui-copy.test.ts | 9 ++------- src/scripts/docs-link-audit.test.ts | 6 ++++-- src/scripts/sync-plugin-versions.test.ts | 9 +++------ 3 files changed, 9 insertions(+), 15 deletions(-) diff --git a/src/scripts/canvas-a2ui-copy.test.ts b/src/scripts/canvas-a2ui-copy.test.ts index 4cf2732deff..4b3ef9f4cf6 100644 --- a/src/scripts/canvas-a2ui-copy.test.ts +++ b/src/scripts/canvas-a2ui-copy.test.ts @@ -1,8 +1,8 @@ import fs from "node:fs/promises"; -import os from "node:os"; import path from "node:path"; import { afterEach, describe, expect, it } from "vitest"; import { copyA2uiAssets } from "../../scripts/canvas-a2ui-copy.js"; +import { withTempDir } from "../test-utils/temp-dir.js"; const ORIGINAL_SKIP_MISSING = process.env.OPENCLAW_A2UI_SKIP_MISSING; const ORIGINAL_SPARSE_PROFILE = process.env.OPENCLAW_SPARSE_PROFILE; @@ -23,12 +23,7 @@ describe("canvas a2ui copy", () => { }); async function withA2uiFixture(run: (dir: string) => Promise) { - const dir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-a2ui-")); - try { - await run(dir); - } finally { - await fs.rm(dir, { recursive: true, force: true }); - } + await withTempDir("openclaw-a2ui-", run); } it("throws a helpful error when assets are missing", async () => { diff --git a/src/scripts/docs-link-audit.test.ts b/src/scripts/docs-link-audit.test.ts index b87252b1e3b..7d9737cc893 100644 --- a/src/scripts/docs-link-audit.test.ts +++ b/src/scripts/docs-link-audit.test.ts @@ -2,6 +2,7 @@ import fs from "node:fs"; import os from "node:os"; import path from "node:path"; import { describe, expect, it } from "vitest"; +import { cleanupTempDirs, makeTempDir } from "../../test/helpers/temp-dir.js"; const { normalizeRoute, @@ -95,7 +96,8 @@ describe("docs-link-audit", () => { }); it("builds an English-only docs tree for anchor audits", () => { - const fixtureRoot = fs.mkdtempSync(path.join(os.tmpdir(), "docs-link-audit-fixture-")); + const tempDirs: string[] = []; + const fixtureRoot = makeTempDir(tempDirs, "docs-link-audit-fixture-"); const docsRoot = path.join(fixtureRoot, "docs"); fs.mkdirSync(path.join(docsRoot, "help"), { recursive: true }); fs.mkdirSync(path.join(docsRoot, "zh-CN", "help"), { recursive: true }); @@ -140,7 +142,7 @@ describe("docs-link-audit", () => { }); } finally { fs.rmSync(anchorDocsDir, { recursive: true, force: true }); - fs.rmSync(fixtureRoot, { recursive: true, force: true }); + cleanupTempDirs(tempDirs); } }); diff --git a/src/scripts/sync-plugin-versions.test.ts b/src/scripts/sync-plugin-versions.test.ts index e5706c3931c..85cd612f23f 100644 --- a/src/scripts/sync-plugin-versions.test.ts +++ b/src/scripts/sync-plugin-versions.test.ts @@ -1,8 +1,8 @@ import fs from "node:fs"; -import os from "node:os"; import path from "node:path"; import { afterEach, describe, expect, it } from "vitest"; import { syncPluginVersions } from "../../scripts/sync-plugin-versions.js"; +import { cleanupTempDirs, makeTempDir } from "../../test/helpers/temp-dir.js"; const tempDirs: string[] = []; @@ -13,14 +13,11 @@ function writeJson(filePath: string, value: unknown) { describe("syncPluginVersions", () => { afterEach(() => { - for (const dir of tempDirs.splice(0)) { - fs.rmSync(dir, { recursive: true, force: true }); - } + cleanupTempDirs(tempDirs); }); it("preserves workspace openclaw devDependencies while bumping plugin host constraints", () => { - const rootDir = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-sync-plugin-versions-")); - tempDirs.push(rootDir); + const rootDir = makeTempDir(tempDirs, "openclaw-sync-plugin-versions-"); writeJson(path.join(rootDir, "package.json"), { name: "openclaw",