From f3f42e6bbfd2bf73b0c0b263534470995db1b52e Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Mon, 6 Apr 2026 05:50:11 +0100 Subject: [PATCH] test(plugins): reuse tracked temp helpers in fixture tests --- src/plugins/bundle-claude-inspect.test.ts | 7 ++++--- src/plugins/conversation-binding.test.ts | 11 ++++++++--- .../runtime-plugin-boundary.whatsapp.test.ts | 9 +++------ src/plugins/runtime/local-runtime-module.test.ts | 13 ++++--------- 4 files changed, 19 insertions(+), 21 deletions(-) diff --git a/src/plugins/bundle-claude-inspect.test.ts b/src/plugins/bundle-claude-inspect.test.ts index aad58aef884..a06ad4a4c6d 100644 --- a/src/plugins/bundle-claude-inspect.test.ts +++ b/src/plugins/bundle-claude-inspect.test.ts @@ -1,10 +1,10 @@ import fs from "node:fs"; -import os from "node:os"; import path from "node:path"; import { afterAll, beforeAll, describe, expect, it } from "vitest"; import { inspectBundleLspRuntimeSupport } from "./bundle-lsp.js"; import { loadBundleManifest } from "./bundle-manifest.js"; import { inspectBundleMcpRuntimeSupport } from "./bundle-mcp.js"; +import { cleanupTrackedTempDirs, makeTrackedTempDir } from "./test-helpers/fs-fixtures.js"; /** * Integration test: builds a Claude Code bundle plugin fixture on disk @@ -13,6 +13,7 @@ import { inspectBundleMcpRuntimeSupport } from "./bundle-mcp.js"; */ describe("Claude bundle plugin inspect integration", () => { let rootDir: string; + const tempDirs: string[] = []; function writeFixtureText(relativePath: string, value: string) { fs.mkdirSync(path.dirname(path.join(rootDir, relativePath)), { recursive: true }); @@ -151,12 +152,12 @@ describe("Claude bundle plugin inspect integration", () => { } beforeAll(() => { - rootDir = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-claude-bundle-")); + rootDir = makeTrackedTempDir("openclaw-claude-bundle", tempDirs); setupClaudeInspectFixture(); }); afterAll(() => { - fs.rmSync(rootDir, { recursive: true, force: true }); + cleanupTrackedTempDirs(tempDirs); }); it("loads the full Claude bundle manifest with all capabilities", () => { diff --git a/src/plugins/conversation-binding.test.ts b/src/plugins/conversation-binding.test.ts index 0aeb04f502c..2eff035fb2b 100644 --- a/src/plugins/conversation-binding.test.ts +++ b/src/plugins/conversation-binding.test.ts @@ -1,7 +1,6 @@ import fs from "node:fs"; -import os from "node:os"; import path from "node:path"; -import { beforeEach, describe, expect, it, vi } from "vitest"; +import { afterAll, beforeEach, describe, expect, it, vi } from "vitest"; import type { ConversationRef, SessionBindingAdapter, @@ -9,8 +8,10 @@ import type { } from "../infra/outbound/session-binding-service.js"; import { createEmptyPluginRegistry } from "./registry-empty.js"; import type { PluginRegistry } from "./registry.js"; +import { cleanupTrackedTempDirs, makeTrackedTempDir } from "./test-helpers/fs-fixtures.js"; -const tempRoot = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-plugin-binding-")); +const tempDirs: string[] = []; +const tempRoot = makeTrackedTempDir("openclaw-plugin-binding", tempDirs); const approvalsPath = path.join(tempRoot, "plugin-binding-approvals.json"); const sessionBindingState = vi.hoisted(() => { @@ -157,6 +158,10 @@ function createAdapter(channel: string, accountId: string): SessionBindingAdapte }; } +afterAll(() => { + cleanupTrackedTempDirs(tempDirs); +}); + function createDiscordCodexBindRequest( conversationId: string, summary: string, diff --git a/src/plugins/runtime-plugin-boundary.whatsapp.test.ts b/src/plugins/runtime-plugin-boundary.whatsapp.test.ts index 0a44ace6ac3..05ad7c655ae 100644 --- a/src/plugins/runtime-plugin-boundary.whatsapp.test.ts +++ b/src/plugins/runtime-plugin-boundary.whatsapp.test.ts @@ -1,10 +1,10 @@ import fs from "node:fs"; -import os from "node:os"; import path from "node:path"; import { afterEach, describe, expect, it } from "vitest"; import { stageBundledPluginRuntime } from "../../scripts/stage-bundled-plugin-runtime.mjs"; import { bundledDistPluginFile } from "../../test/helpers/bundled-plugin-paths.js"; import { loadPluginBoundaryModuleWithJiti } from "./runtime/runtime-plugin-boundary.js"; +import { cleanupTrackedTempDirs, makeTrackedTempDir } from "./test-helpers/fs-fixtures.js"; type LightModule = { getActiveWebListener: (accountId?: string | null) => unknown; @@ -25,8 +25,7 @@ function writeRuntimeFixtureText(rootDir: string, relativePath: string, value: s } function createBundledWhatsAppRuntimeFixture() { - const rootDir = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-whatsapp-boundary-")); - tempDirs.push(rootDir); + const rootDir = makeTrackedTempDir("openclaw-whatsapp-boundary", tempDirs); for (const [relativePath, value] of Object.entries({ "package.json": JSON.stringify( { @@ -107,9 +106,7 @@ function expectSharedWhatsAppListenerState(runtimePluginDir: string, accountId: } afterEach(() => { - for (const dir of tempDirs.splice(0, tempDirs.length)) { - fs.rmSync(dir, { recursive: true, force: true }); - } + cleanupTrackedTempDirs(tempDirs); }); describe("runtime plugin boundary whatsapp seam", () => { diff --git a/src/plugins/runtime/local-runtime-module.test.ts b/src/plugins/runtime/local-runtime-module.test.ts index e597e93e91d..051a4fc13fc 100644 --- a/src/plugins/runtime/local-runtime-module.test.ts +++ b/src/plugins/runtime/local-runtime-module.test.ts @@ -1,16 +1,14 @@ import fs from "node:fs"; -import os from "node:os"; import path from "node:path"; import { pathToFileURL } from "node:url"; import { afterEach, describe, expect, it } from "vitest"; +import { cleanupTrackedTempDirs, makeTrackedTempDir } from "../test-helpers/fs-fixtures.js"; import { loadSiblingRuntimeModuleSync } from "./local-runtime-module.js"; -const tempDirs = new Set(); +const tempDirs: string[] = []; function createTempDir(): string { - const dir = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-local-runtime-module-")); - tempDirs.add(dir); - return dir; + return makeTrackedTempDir("openclaw-local-runtime-module", tempDirs); } function writeFile(filePath: string, content: string): void { @@ -19,10 +17,7 @@ function writeFile(filePath: string, content: string): void { } afterEach(() => { - for (const dir of tempDirs) { - fs.rmSync(dir, { recursive: true, force: true }); - } - tempDirs.clear(); + cleanupTrackedTempDirs(tempDirs); }); describe("loadSiblingRuntimeModuleSync", () => {