refactor(test): replace manual PATH restore with env helpers

This commit is contained in:
Peter Steinberger
2026-02-21 18:33:54 +00:00
parent 01f42a0372
commit 807968e4df
2 changed files with 21 additions and 23 deletions

View File

@@ -1,5 +1,6 @@
import path from "node:path";
import { describe, expect, it } from "vitest";
import { withEnv } from "../test-utils/env.js";
import {
buildTrustedSafeBinDirs,
getTrustedSafeBinDirs,
@@ -56,16 +57,13 @@ describe("exec safe bin trust", () => {
});
it("uses startup PATH snapshot when pathEnv is omitted", () => {
const originalPath = process.env.PATH;
const injected = `/tmp/openclaw-path-injected-${Date.now()}`;
const initial = getTrustedSafeBinDirs({ refresh: true });
try {
process.env.PATH = `${injected}${path.delimiter}${originalPath ?? ""}`;
withEnv({ PATH: `${injected}${path.delimiter}${process.env.PATH ?? ""}` }, () => {
const refreshed = getTrustedSafeBinDirs({ refresh: true });
expect(refreshed.has(path.resolve(injected))).toBe(false);
expect([...refreshed].toSorted()).toEqual([...initial].toSorted());
} finally {
process.env.PATH = originalPath;
}
});
});
});