|
1 | 1 | import { expect, test } from "bun:test"; |
| 2 | +import { mkdtempSync } from "node:fs"; |
| 3 | +import { tmpdir } from "node:os"; |
| 4 | +import { join } from "node:path"; |
2 | 5 | import { createPermissionGate } from "./gate.js"; |
3 | 6 | import { |
4 | 7 | createReactorAuthorize, |
@@ -33,6 +36,43 @@ const gate = (opts?: { interactive?: boolean; auto?: boolean }) => |
33 | 36 | }, |
34 | 37 | }); |
35 | 38 |
|
| 39 | +test("worker grant after a denied write allows a later call id through gateToolCall", async () => { |
| 40 | + const cwd = mkdtempSync(join(tmpdir(), "worker-grant-")); |
| 41 | + const path = join(cwd, "probe.txt"); |
| 42 | + const policy = createPermissionGate({ |
| 43 | + cwd, |
| 44 | + approvals: [], |
| 45 | + interactive: false, |
| 46 | + auto: false, |
| 47 | + skipPermissions: false, |
| 48 | + reactorGated: true, |
| 49 | + requestApproval: async () => { |
| 50 | + throw new Error("worker must never ask"); |
| 51 | + }, |
| 52 | + }); |
| 53 | + const workerGate = workerPermissionGate(policy); |
| 54 | + const first: ToolCall = { |
| 55 | + id: "call_auto_0", |
| 56 | + name: "write_file", |
| 57 | + arguments: { path, content: "unauthorized" }, |
| 58 | + }; |
| 59 | + const second: ToolCall = { |
| 60 | + id: "call_auto_1", |
| 61 | + name: "write_file", |
| 62 | + arguments: { path, content: "unauthorized" }, |
| 63 | + }; |
| 64 | + expect((await workerGate.authorizeCall(first)).effect).toBe("deny"); |
| 65 | + policy.setSeededApprovals([{ tool: "write_file", pattern: path }]); |
| 66 | + expect((await workerGate.authorizeCall(second)).effect).toBe("allow"); |
| 67 | + let called = false; |
| 68 | + const result = await gateToolCall(workerGate, second, new AbortController().signal, async () => { |
| 69 | + called = true; |
| 70 | + return { callId: second.id, content: "executed", isError: false }; |
| 71 | + }); |
| 72 | + expect(result.isError).toBe(false); |
| 73 | + expect(called).toBe(true); |
| 74 | +}); |
| 75 | + |
36 | 76 | test("worker maps unresolved ask to deny while main reactor suspends", async () => { |
37 | 77 | const policy = gate(); |
38 | 78 | expect((await createReactorAuthorize(policy)("tool:write_file", "invoke", call)).effect).toBe( |
|
0 commit comments