mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 07:10:43 +00:00
test: share exec approval policy fallback fixture
This commit is contained in:
@@ -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", () => {
|
||||
|
||||
Reference in New Issue
Block a user