|
| 1 | +import { checkAutoApproval } from ".." |
| 2 | + |
| 3 | +describe("Destructive Command Guard auto-approval precedence", () => { |
| 4 | + const baseState = { |
| 5 | + autoApprovalEnabled: true, |
| 6 | + alwaysAllowExecute: true, |
| 7 | + alwaysAllowReadOnly: false, |
| 8 | + alwaysAllowReadOnlyOutsideWorkspace: false, |
| 9 | + alwaysAllowWrite: false, |
| 10 | + alwaysAllowWriteOutsideWorkspace: false, |
| 11 | + alwaysAllowWriteProtected: false, |
| 12 | + alwaysAllowMcp: false, |
| 13 | + alwaysAllowModeSwitch: false, |
| 14 | + alwaysAllowSubtasks: false, |
| 15 | + alwaysAllowFollowupQuestions: false, |
| 16 | + allowedCommands: ["echo"], |
| 17 | + deniedCommands: ["rm"], |
| 18 | + destructiveCommandGuardEnabled: true, |
| 19 | + mcpServers: [], |
| 20 | + } |
| 21 | + |
| 22 | + it("auto-approves commands allowed by DCG without consulting Zoo's deny list", async () => { |
| 23 | + expect(await checkAutoApproval({ state: baseState, ask: "command", text: "rm file" })).toEqual({ |
| 24 | + decision: "approve", |
| 25 | + }) |
| 26 | + }) |
| 27 | + |
| 28 | + it("requires explicit approval for a DCG-protected command", async () => { |
| 29 | + expect( |
| 30 | + await checkAutoApproval({ state: baseState, ask: "command", text: "echo safe", isProtected: true }), |
| 31 | + ).toEqual({ decision: "ask" }) |
| 32 | + }) |
| 33 | + |
| 34 | + it("auto-approves DCG-allowed commands without consulting Zoo's allowlist", async () => { |
| 35 | + expect(await checkAutoApproval({ state: baseState, ask: "command", text: "unlisted-command" })).toEqual({ |
| 36 | + decision: "approve", |
| 37 | + }) |
| 38 | + }) |
| 39 | + |
| 40 | + it("does not auto-approve via DCG when execute auto-approval is off", async () => { |
| 41 | + const state = { ...baseState, alwaysAllowExecute: false } |
| 42 | + |
| 43 | + expect(await checkAutoApproval({ state, ask: "command", text: "echo safe" })).toEqual({ decision: "ask" }) |
| 44 | + }) |
| 45 | + |
| 46 | + it("keeps ordinary allowlist auto-approval when DCG is disabled", async () => { |
| 47 | + const state = { ...baseState, destructiveCommandGuardEnabled: false } |
| 48 | + |
| 49 | + expect(await checkAutoApproval({ state, ask: "command", text: "echo safe" })).toEqual({ |
| 50 | + decision: "approve", |
| 51 | + }) |
| 52 | + }) |
| 53 | + |
| 54 | + it("keeps ordinary denylist behavior when DCG is disabled", async () => { |
| 55 | + const state = { ...baseState, destructiveCommandGuardEnabled: false } |
| 56 | + |
| 57 | + expect(await checkAutoApproval({ state, ask: "command", text: "rm file" })).toEqual({ |
| 58 | + decision: "deny", |
| 59 | + }) |
| 60 | + }) |
| 61 | + |
| 62 | + it("keeps ordinary prompts for unlisted commands when DCG is disabled", async () => { |
| 63 | + const state = { ...baseState, destructiveCommandGuardEnabled: false } |
| 64 | + |
| 65 | + expect(await checkAutoApproval({ state, ask: "command", text: "unlisted-command" })).toEqual({ |
| 66 | + decision: "ask", |
| 67 | + }) |
| 68 | + }) |
| 69 | +}) |
0 commit comments