test(plugins): reuse tracked temp helpers in path resolution tests

This commit is contained in:
Vincent Koc
2026-04-06 05:49:09 +01:00
parent d85dbe1d4a
commit 26c34f816d
2 changed files with 11 additions and 17 deletions

View File

@@ -1,8 +1,8 @@
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
import { afterEach, describe, expect, it, vi } from "vitest";
import { resolveBundledPluginsDir } from "./bundled-dir.js";
import { cleanupTrackedTempDirs, makeTrackedTempDir } from "./test-helpers/fs-fixtures.js";
const tempDirs: string[] = [];
const originalBundledDir = process.env.OPENCLAW_BUNDLED_PLUGINS_DIR;
@@ -11,9 +11,7 @@ const originalVitest = process.env.VITEST;
const originalArgv1 = process.argv[1];
function makeRepoRoot(prefix: string): string {
const repoRoot = fs.mkdtempSync(path.join(os.tmpdir(), prefix));
tempDirs.push(repoRoot);
return repoRoot;
return makeTrackedTempDir(prefix, tempDirs);
}
function createOpenClawRoot(params: {
@@ -140,9 +138,7 @@ afterEach(() => {
process.env.VITEST = originalVitest;
}
process.argv[1] = originalArgv1;
for (const dir of tempDirs.splice(0, tempDirs.length)) {
fs.rmSync(dir, { recursive: true, force: true });
}
cleanupTrackedTempDirs(tempDirs);
});
describe("resolveBundledPluginsDir", () => {

View File

@@ -1,25 +1,23 @@
import { execFileSync } from "node:child_process";
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
import { afterEach, describe, expect, it } from "vitest";
import {
cleanupTrackedTempDirs,
makeTrackedTempDir,
mkdirSafeDir,
} from "./test-helpers/fs-fixtures.js";
const tempRoots: string[] = [];
function makeTempDir() {
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-plugin-loader-"));
tempRoots.push(dir);
return dir;
return makeTrackedTempDir("openclaw-plugin-loader", tempRoots);
}
function mkdirSafe(dir: string) {
fs.mkdirSync(dir, { recursive: true });
}
const mkdirSafe = mkdirSafeDir;
afterEach(() => {
for (const dir of tempRoots.splice(0)) {
fs.rmSync(dir, { recursive: true, force: true });
}
cleanupTrackedTempDirs(tempRoots);
});
describe("plugin loader git path regression", () => {