
























@@ -2,7 +2,17 @@ import crypto from "node:crypto";
22import fs from "node:fs";
33import os from "node:os";
44import path from "node:path";
5-import { afterEach, beforeEach, describe, expect, it, type Mock, vi } from "vitest";
5+import {
6+afterAll,
7+afterEach,
8+beforeAll,
9+beforeEach,
10+describe,
11+expect,
12+it,
13+type Mock,
14+vi,
15+} from "vitest";
616import { clearRuntimeConfigSnapshot, setRuntimeConfigSnapshot } from "../config/config.js";
717import type { SystemRunApprovalPlan } from "../infra/exec-approvals.js";
818import { loadExecApprovals, saveExecApprovals } from "../infra/exec-approvals.js";
@@ -32,12 +42,30 @@ describe("formatSystemRunAllowlistMissMessage", () => {
3242});
33433444describe("handleSystemRunInvoke mac app exec host routing", () => {
45+let sharedFixtureRoot = "";
46+let sharedFixtureId = 0;
3547let testOpenClawHome = "";
3648let previousOpenClawHome: string | undefined;
374950+beforeAll(() => {
51+sharedFixtureRoot = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-node-host-fixtures-"));
52+});
53+54+afterAll(() => {
55+if (sharedFixtureRoot) {
56+fs.rmSync(sharedFixtureRoot, { recursive: true, force: true });
57+}
58+});
59+60+function createFixtureDir(prefix: string): string {
61+const dir = path.join(sharedFixtureRoot, `${prefix}${sharedFixtureId++}`);
62+fs.mkdirSync(dir, { recursive: true });
63+return dir;
64+}
65+3866beforeEach(() => {
3967previousOpenClawHome = process.env.OPENCLAW_HOME;
40-testOpenClawHome = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-node-host-home-"));
68+testOpenClawHome = createFixtureDir("openclaw-node-host-home-");
4169process.env.OPENCLAW_HOME = testOpenClawHome;
4270clearRuntimeConfigSnapshot();
4371});
@@ -49,10 +77,7 @@ describe("handleSystemRunInvoke mac app exec host routing", () => {
4977} else {
5078process.env.OPENCLAW_HOME = previousOpenClawHome;
5179}
52-if (testOpenClawHome) {
53-fs.rmSync(testOpenClawHome, { recursive: true, force: true });
54-testOpenClawHome = "";
55-}
80+testOpenClawHome = "";
5681});
57825883function createLocalRunResult(stdout = "local-ok") {
@@ -238,7 +263,7 @@ describe("handleSystemRunInvoke mac app exec host routing", () => {
238263approvals: Parameters<typeof saveExecApprovals>[0];
239264run: (ctx: { tempHome: string }) => Promise<T>;
240265}): Promise<T> {
241-const tempHome = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-exec-approvals-"));
266+const tempHome = createFixtureDir("openclaw-exec-approvals-");
242267const previousOpenClawHome = process.env.OPENCLAW_HOME;
243268process.env.OPENCLAW_HOME = tempHome;
244269saveExecApprovals(params.approvals);
@@ -250,15 +275,14 @@ describe("handleSystemRunInvoke mac app exec host routing", () => {
250275} else {
251276process.env.OPENCLAW_HOME = previousOpenClawHome;
252277}
253-fs.rmSync(tempHome, { recursive: true, force: true });
254278}
255279}
256280257281async function withPathTokenCommand<T>(params: {
258282tmpPrefix: string;
259283run: (ctx: { link: string; expected: string }) => Promise<T>;
260284}): Promise<T> {
261-const tmp = fs.mkdtempSync(path.join(os.tmpdir(), params.tmpPrefix));
285+const tmp = createFixtureDir(params.tmpPrefix);
262286const binDir = path.join(tmp, "bin");
263287fs.mkdirSync(binDir, { recursive: true });
264288const link = path.join(binDir, "poccmd");
@@ -274,15 +298,14 @@ describe("handleSystemRunInvoke mac app exec host routing", () => {
274298} else {
275299process.env.PATH = oldPath;
276300}
277-fs.rmSync(tmp, { recursive: true, force: true });
278301}
279302}
280303281304async function withFakeRuntimeOnPath<T>(params: {
282305runtime: "bun" | "deno" | "jiti" | "tsx";
283306run: () => Promise<T>;
284307}): Promise<T> {
285-const tmp = fs.mkdtempSync(path.join(os.tmpdir(), `openclaw-${params.runtime}-path-`));
308+const tmp = createFixtureDir(`openclaw-${params.runtime}-path-`);
286309const binDir = path.join(tmp, "bin");
287310fs.mkdirSync(binDir, { recursive: true });
288311const runtimePath =
@@ -305,7 +328,6 @@ describe("handleSystemRunInvoke mac app exec host routing", () => {
305328} else {
306329process.env.PATH = oldPath;
307330}
308-fs.rmSync(tmp, { recursive: true, force: true });
309331}
310332}
311333此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。