refactor(core): dedupe shared config and runtime helpers

This commit is contained in:
Peter Steinberger
2026-02-16 14:52:03 +00:00
parent 544ffbcf7b
commit 04892ee230
68 changed files with 1966 additions and 2018 deletions

View File

@@ -34,6 +34,26 @@ function makeTempDir() {
return fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-exec-approvals-"));
}
function createSafeBinJqCase(params: { command: string; seedFileName?: string }) {
const dir = makeTempDir();
const binDir = path.join(dir, "bin");
fs.mkdirSync(binDir, { recursive: true });
const exeName = process.platform === "win32" ? "jq.exe" : "jq";
const exe = path.join(binDir, exeName);
fs.writeFileSync(exe, "");
fs.chmodSync(exe, 0o755);
if (params.seedFileName) {
fs.writeFileSync(path.join(dir, params.seedFileName), "{}");
}
const res = analyzeShellCommand({
command: params.command,
cwd: dir,
env: makePathEnv(binDir),
});
expect(res.ok).toBe(true);
return { dir, segment: res.segments[0] };
}
describe("exec approvals allowlist matching", () => {
it("ignores basename-only patterns", () => {
const resolution = {
@@ -389,20 +409,7 @@ describe("exec approvals safe bins", () => {
if (process.platform === "win32") {
return;
}
const dir = makeTempDir();
const binDir = path.join(dir, "bin");
fs.mkdirSync(binDir, { recursive: true });
const exeName = process.platform === "win32" ? "jq.exe" : "jq";
const exe = path.join(binDir, exeName);
fs.writeFileSync(exe, "");
fs.chmodSync(exe, 0o755);
const res = analyzeShellCommand({
command: "jq .foo",
cwd: dir,
env: makePathEnv(binDir),
});
expect(res.ok).toBe(true);
const segment = res.segments[0];
const { dir, segment } = createSafeBinJqCase({ command: "jq .foo" });
const ok = isSafeBinUsage({
argv: segment.argv,
resolution: segment.resolution,
@@ -416,22 +423,10 @@ describe("exec approvals safe bins", () => {
if (process.platform === "win32") {
return;
}
const dir = makeTempDir();
const binDir = path.join(dir, "bin");
fs.mkdirSync(binDir, { recursive: true });
const exeName = process.platform === "win32" ? "jq.exe" : "jq";
const exe = path.join(binDir, exeName);
fs.writeFileSync(exe, "");
fs.chmodSync(exe, 0o755);
const file = path.join(dir, "secret.json");
fs.writeFileSync(file, "{}");
const res = analyzeShellCommand({
const { dir, segment } = createSafeBinJqCase({
command: "jq .foo secret.json",
cwd: dir,
env: makePathEnv(binDir),
seedFileName: "secret.json",
});
expect(res.ok).toBe(true);
const segment = res.segments[0];
const ok = isSafeBinUsage({
argv: segment.argv,
resolution: segment.resolution,