From 2272eb9ffad6faf6c1d9fbdee55892700ca9331d Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Mon, 6 Apr 2026 05:36:33 +0100 Subject: [PATCH] test(scripts): reuse temp dir helpers in repo fixtures --- test/scripts/committer.test.ts | 20 +++++-------------- .../stage-bundled-plugin-runtime-deps.test.ts | 6 ++++-- 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/test/scripts/committer.test.ts b/test/scripts/committer.test.ts index 9df35be48b2..e3b25ea362d 100644 --- a/test/scripts/committer.test.ts +++ b/test/scripts/committer.test.ts @@ -1,11 +1,11 @@ import { execFileSync } from "node:child_process"; -import { mkdtempSync, mkdirSync, rmSync, writeFileSync } from "node:fs"; -import { tmpdir } from "node:os"; +import { mkdirSync, writeFileSync } from "node:fs"; import path from "node:path"; -import { afterEach, describe, expect, it } from "vitest"; +import { describe, expect, it } from "vitest"; +import { createScriptTestHarness } from "./test-helpers.js"; const scriptPath = path.join(process.cwd(), "scripts", "committer"); -const tempRepos: string[] = []; +const { createTempDir } = createScriptTestHarness(); function run(cwd: string, command: string, args: string[]) { return execFileSync(command, args, { @@ -19,8 +19,7 @@ function git(cwd: string, ...args: string[]) { } function createRepo() { - const repo = mkdtempSync(path.join(tmpdir(), "committer-test-")); - tempRepos.push(repo); + const repo = createTempDir("committer-test-"); git(repo, "init", "-q"); git(repo, "config", "user.email", "test@example.com"); @@ -47,15 +46,6 @@ function committedPaths(repo: string) { return output.split("\n").filter(Boolean).toSorted(); } -afterEach(() => { - while (tempRepos.length > 0) { - const repo = tempRepos.pop(); - if (repo) { - rmSync(repo, { force: true, recursive: true }); - } - } -}); - describe("scripts/committer", () => { it("accepts supported path argument shapes", () => { const cases = [ diff --git a/test/scripts/stage-bundled-plugin-runtime-deps.test.ts b/test/scripts/stage-bundled-plugin-runtime-deps.test.ts index 377c6ee5cec..0e32f174892 100644 --- a/test/scripts/stage-bundled-plugin-runtime-deps.test.ts +++ b/test/scripts/stage-bundled-plugin-runtime-deps.test.ts @@ -1,15 +1,17 @@ import fs from "node:fs"; -import os from "node:os"; import path from "node:path"; import { describe, expect, it } from "vitest"; import { stageBundledPluginRuntimeDeps } from "../../scripts/stage-bundled-plugin-runtime-deps.mjs"; +import { createScriptTestHarness } from "./test-helpers.js"; + +const { createTempDir } = createScriptTestHarness(); describe("stageBundledPluginRuntimeDeps", () => { function createBundledPluginFixture(params: { packageJson: Record; pluginId?: string; }) { - const repoRoot = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-runtime-deps-")); + const repoRoot = createTempDir("openclaw-runtime-deps-"); const pluginId = params.pluginId ?? "fixture-plugin"; const pluginDir = path.join(repoRoot, "dist", "extensions", pluginId); fs.mkdirSync(pluginDir, { recursive: true });