From 89a5eadd4ef630b50d205e72150bec8bf8de0dea Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sun, 19 Apr 2026 02:06:54 +0100 Subject: [PATCH] test: share exec approval policy fallback fixture --- src/infra/exec-approvals-policy.test.ts | 118 +++++++----------------- 1 file changed, 34 insertions(+), 84 deletions(-) diff --git a/src/infra/exec-approvals-policy.test.ts b/src/infra/exec-approvals-policy.test.ts index c7162e10f66..b6787d7f4a9 100644 --- a/src/infra/exec-approvals-policy.test.ts +++ b/src/infra/exec-approvals-policy.test.ts @@ -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", () => {