mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 08:51:23 +00:00
refactor(test): replace manual PATH restore with env helpers
This commit is contained in:
@@ -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;
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user