test(perf): reuse shared temp root in plugin install tests

This commit is contained in:
Peter Steinberger
2026-03-02 11:27:04 +00:00
parent 79b649a25e
commit 3dd01c3361

View File

@@ -1,4 +1,3 @@
import { randomUUID } from "node:crypto";
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
@@ -18,16 +17,25 @@ vi.mock("../process/exec.js", () => ({
runCommandWithTimeout: vi.fn(),
}));
const tempDirs: string[] = [];
let installPluginFromArchive: typeof import("./install.js").installPluginFromArchive;
let installPluginFromDir: typeof import("./install.js").installPluginFromDir;
let installPluginFromNpmSpec: typeof import("./install.js").installPluginFromNpmSpec;
let runCommandWithTimeout: typeof import("../process/exec.js").runCommandWithTimeout;
let suiteTempRoot = "";
let tempDirCounter = 0;
function ensureSuiteTempRoot() {
if (suiteTempRoot) {
return suiteTempRoot;
}
suiteTempRoot = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-plugin-install-"));
return suiteTempRoot;
}
function makeTempDir() {
const dir = path.join(os.tmpdir(), `openclaw-plugin-install-${randomUUID()}`);
const dir = path.join(ensureSuiteTempRoot(), `case-${String(tempDirCounter)}`);
tempDirCounter += 1;
fs.mkdirSync(dir, { recursive: true });
tempDirs.push(dir);
return dir;
}
@@ -288,12 +296,14 @@ async function installArchivePackageAndReturnResult(params: {
}
afterAll(() => {
for (const dir of tempDirs.splice(0)) {
try {
fs.rmSync(dir, { recursive: true, force: true });
} catch {
// ignore cleanup failures
}
if (!suiteTempRoot) {
return;
}
try {
fs.rmSync(suiteTempRoot, { recursive: true, force: true });
} finally {
suiteTempRoot = "";
tempDirCounter = 0;
}
});