mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-07 22:31:25 +00:00
refactor(exec): unify wrapper resolution and split approvals tests
This commit is contained in:
59
src/infra/exec-approvals-test-helpers.ts
Normal file
59
src/infra/exec-approvals-test-helpers.ts
Normal file
@@ -0,0 +1,59 @@
|
||||
import fs from "node:fs";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
|
||||
export function makePathEnv(binDir: string): NodeJS.ProcessEnv {
|
||||
if (process.platform !== "win32") {
|
||||
return { PATH: binDir };
|
||||
}
|
||||
return { PATH: binDir, PATHEXT: ".EXE;.CMD;.BAT;.COM" };
|
||||
}
|
||||
|
||||
export function makeTempDir(): string {
|
||||
return fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-exec-approvals-"));
|
||||
}
|
||||
|
||||
export type ShellParserParityFixtureCase = {
|
||||
id: string;
|
||||
command: string;
|
||||
ok: boolean;
|
||||
executables: string[];
|
||||
};
|
||||
|
||||
type ShellParserParityFixture = {
|
||||
cases: ShellParserParityFixtureCase[];
|
||||
};
|
||||
|
||||
export type WrapperResolutionParityFixtureCase = {
|
||||
id: string;
|
||||
argv: string[];
|
||||
expectedRawExecutable: string | null;
|
||||
};
|
||||
|
||||
type WrapperResolutionParityFixture = {
|
||||
cases: WrapperResolutionParityFixtureCase[];
|
||||
};
|
||||
|
||||
export function loadShellParserParityFixtureCases(): ShellParserParityFixtureCase[] {
|
||||
const fixturePath = path.join(
|
||||
process.cwd(),
|
||||
"test",
|
||||
"fixtures",
|
||||
"exec-allowlist-shell-parser-parity.json",
|
||||
);
|
||||
const fixture = JSON.parse(fs.readFileSync(fixturePath, "utf8")) as ShellParserParityFixture;
|
||||
return fixture.cases;
|
||||
}
|
||||
|
||||
export function loadWrapperResolutionParityFixtureCases(): WrapperResolutionParityFixtureCase[] {
|
||||
const fixturePath = path.join(
|
||||
process.cwd(),
|
||||
"test",
|
||||
"fixtures",
|
||||
"exec-wrapper-resolution-parity.json",
|
||||
);
|
||||
const fixture = JSON.parse(
|
||||
fs.readFileSync(fixturePath, "utf8"),
|
||||
) as WrapperResolutionParityFixture;
|
||||
return fixture.cases;
|
||||
}
|
||||
Reference in New Issue
Block a user