test: share exec approval policy fallback fixture

This commit is contained in:
Peter Steinberger
2026-04-19 02:06:54 +01:00
parent 77876bd05c
commit 89a5eadd4e

View File

@@ -22,6 +22,37 @@ import {
requiresExecApproval,
} from "./exec-approvals.js";
function expectMalformedAgentAskUsesDefaults(agentAsk: unknown): void {
const approvals = {
version: 1,
defaults: {
ask: "always",
},
agents: {
runner: {
ask: agentAsk,
},
},
} as unknown as ExecApprovalsFile;
const summary = resolveExecPolicyScopeSummary({
approvals,
globalExecConfig: {
ask: "off",
},
configPath: "agents.list.runner.tools.exec",
scopeLabel: "agent:runner",
agentId: "runner",
});
expect(summary.ask).toMatchObject({
requested: "off",
host: "always",
hostSource: "~/.openclaw/exec-approvals.json defaults.ask",
effective: "always",
note: "more aggressive ask wins",
});
}
describe("exec approvals policy helpers", () => {
it.each([
{ raw: " gateway ", expected: "gateway" },
@@ -323,96 +354,15 @@ describe("exec approvals policy helpers", () => {
});
it("skips malformed host fields when attributing their source", () => {
const approvals = {
version: 1,
defaults: {
ask: "always",
},
agents: {
runner: {
ask: "foo",
},
},
} as unknown as ExecApprovalsFile;
const summary = resolveExecPolicyScopeSummary({
approvals,
globalExecConfig: {
ask: "off",
},
configPath: "agents.list.runner.tools.exec",
scopeLabel: "agent:runner",
agentId: "runner",
});
expect(summary.ask).toMatchObject({
requested: "off",
host: "always",
hostSource: "~/.openclaw/exec-approvals.json defaults.ask",
effective: "always",
note: "more aggressive ask wins",
});
expectMalformedAgentAskUsesDefaults("foo");
});
it("ignores malformed non-string host fields when attributing their source", () => {
const approvals = {
version: 1,
defaults: {
ask: "always",
},
agents: {
runner: {
ask: true,
},
},
} as unknown as ExecApprovalsFile;
const summary = resolveExecPolicyScopeSummary({
approvals,
globalExecConfig: {
ask: "off",
},
configPath: "agents.list.runner.tools.exec",
scopeLabel: "agent:runner",
agentId: "runner",
});
expect(summary.ask).toMatchObject({
requested: "off",
host: "always",
hostSource: "~/.openclaw/exec-approvals.json defaults.ask",
effective: "always",
note: "more aggressive ask wins",
});
expectMalformedAgentAskUsesDefaults(true);
});
it("does not credit mixed-case host fields that resolution ignores", () => {
const approvals = {
version: 1,
defaults: {
ask: "always",
},
agents: {
runner: {
ask: "Always",
},
},
} as unknown as ExecApprovalsFile;
const summary = resolveExecPolicyScopeSummary({
approvals,
globalExecConfig: {
ask: "off",
},
configPath: "agents.list.runner.tools.exec",
scopeLabel: "agent:runner",
agentId: "runner",
});
expect(summary.ask).toMatchObject({
requested: "off",
host: "always",
hostSource: "~/.openclaw/exec-approvals.json defaults.ask",
effective: "always",
note: "more aggressive ask wins",
});
expectMalformedAgentAskUsesDefaults("Always");
});
it("attributes host policy to wildcard agent entries before defaults", () => {