From b1ae35d6029c258984a980bbe101e188f137c2cc Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Mon, 6 Apr 2026 05:35:38 +0100 Subject: [PATCH] test(scripts): reuse temp dir helpers in runtime tests --- test/scripts/runtime-postbuild.test.ts | 24 +++++-------------- .../write-cli-startup-metadata.test.ts | 19 ++++----------- 2 files changed, 10 insertions(+), 33 deletions(-) diff --git a/test/scripts/runtime-postbuild.test.ts b/test/scripts/runtime-postbuild.test.ts index bab69773634..7c10c779927 100644 --- a/test/scripts/runtime-postbuild.test.ts +++ b/test/scripts/runtime-postbuild.test.ts @@ -1,26 +1,14 @@ import fs from "node:fs/promises"; -import os from "node:os"; import path from "node:path"; -import { afterEach, describe, expect, it, vi } from "vitest"; +import { describe, expect, it, vi } from "vitest"; import { copyStaticExtensionAssets, listStaticExtensionAssetOutputs, writeStableRootRuntimeAliases, } from "../../scripts/runtime-postbuild.mjs"; +import { createScriptTestHarness } from "./test-helpers.js"; -const cleanupDirs: string[] = []; - -afterEach(async () => { - await Promise.all( - cleanupDirs.splice(0).map((dir) => fs.rm(dir, { recursive: true, force: true })), - ); -}); - -async function createTempRoot() { - const dir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-runtime-postbuild-")); - cleanupDirs.push(dir); - return dir; -} +const { createTempDir } = createScriptTestHarness(); describe("runtime postbuild static assets", () => { it("tracks plugin-owned static assets that release packaging must ship", () => { @@ -30,7 +18,7 @@ describe("runtime postbuild static assets", () => { }); it("copies declared static assets into dist", async () => { - const rootDir = await createTempRoot(); + const rootDir = createTempDir("openclaw-runtime-postbuild-"); const src = "extensions/acpx/src/runtime-internals/mcp-proxy.mjs"; const dest = "dist/extensions/acpx/mcp-proxy.mjs"; const sourcePath = path.join(rootDir, src); @@ -47,7 +35,7 @@ describe("runtime postbuild static assets", () => { }); it("warns when a declared static asset is missing", async () => { - const rootDir = await createTempRoot(); + const rootDir = createTempDir("openclaw-runtime-postbuild-"); const warn = vi.fn(); copyStaticExtensionAssets({ @@ -62,7 +50,7 @@ describe("runtime postbuild static assets", () => { }); it("writes stable aliases for hashed root runtime modules", async () => { - const rootDir = await createTempRoot(); + const rootDir = createTempDir("openclaw-runtime-postbuild-"); const distDir = path.join(rootDir, "dist"); await fs.mkdir(distDir, { recursive: true }); await fs.writeFile( diff --git a/test/scripts/write-cli-startup-metadata.test.ts b/test/scripts/write-cli-startup-metadata.test.ts index 1c3569a1c8b..22eab7dc8c5 100644 --- a/test/scripts/write-cli-startup-metadata.test.ts +++ b/test/scripts/write-cli-startup-metadata.test.ts @@ -1,24 +1,14 @@ -import { mkdtempSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs"; -import os from "node:os"; +import { mkdirSync, readFileSync, writeFileSync } from "node:fs"; import path from "node:path"; -import { afterEach, describe, expect, it } from "vitest"; +import { describe, expect, it } from "vitest"; import { renderBundledRootHelpText, writeCliStartupMetadata, } from "../../scripts/write-cli-startup-metadata.ts"; - -function createTempDir(prefix: string): string { - return mkdtempSync(path.join(os.tmpdir(), prefix)); -} +import { createScriptTestHarness } from "./test-helpers.js"; describe("write-cli-startup-metadata", () => { - const tempDirs: string[] = []; - - afterEach(() => { - for (const dir of tempDirs.splice(0)) { - rmSync(dir, { recursive: true, force: true }); - } - }); + const { createTempDir } = createScriptTestHarness(); it("captures bundled root help text from the CLI program", async () => { const rootHelpText = await renderBundledRootHelpText(); @@ -29,7 +19,6 @@ describe("write-cli-startup-metadata", () => { it("writes startup metadata with populated root help text", async () => { const tempRoot = createTempDir("openclaw-startup-metadata-"); - tempDirs.push(tempRoot); const distDir = path.join(tempRoot, "dist"); const extensionsDir = path.join(tempRoot, "extensions"); const outputPath = path.join(distDir, "cli-startup-metadata.json");