|
7 | 7 | appendProjectPermissionAllows, |
8 | 8 | computeToolCallPermissions, |
9 | 9 | evaluatePermissionScopes, |
| 10 | + getPermissionScopesRequiringAsk, |
10 | 11 | hasUserPermissionReplies, |
11 | 12 | isPathInAnyDirectory, |
12 | 13 | parseBashSideEffects, |
@@ -46,6 +47,47 @@ test("evaluatePermissionScopes applies deny, ask, allow, and default mode preced |
46 | 47 | assert.equal(evaluatePermissionScopes(["unknown"], settings), "ask"); |
47 | 48 | }); |
48 | 49 |
|
| 50 | +test("evaluatePermissionScopes allows unknown when defaultMode is allowAll", () => { |
| 51 | + const allowAllSettings = { |
| 52 | + allow: [] as const, |
| 53 | + deny: [] as const, |
| 54 | + ask: [] as const, |
| 55 | + defaultMode: "allowAll" as const, |
| 56 | + }; |
| 57 | + assert.equal(evaluatePermissionScopes(["unknown"], allowAllSettings), "allow"); |
| 58 | + |
| 59 | + // unknown + other scopes that would otherwise trigger ask should still ask for those scopes |
| 60 | + const askNetworkSettings = { |
| 61 | + allow: [] as const, |
| 62 | + deny: [] as const, |
| 63 | + ask: ["network" as const], |
| 64 | + defaultMode: "allowAll" as const, |
| 65 | + }; |
| 66 | + assert.equal(evaluatePermissionScopes(["unknown", "network"], askNetworkSettings), "ask"); |
| 67 | +}); |
| 68 | + |
| 69 | +test("getPermissionScopesRequiringAsk excludes unknown when defaultMode is allowAll", () => { |
| 70 | + const allowAllSettings = { |
| 71 | + allow: [] as const, |
| 72 | + deny: [] as const, |
| 73 | + ask: ["network" as const], |
| 74 | + defaultMode: "allowAll" as const, |
| 75 | + }; |
| 76 | + const result = getPermissionScopesRequiringAsk(["unknown", "network"], allowAllSettings); |
| 77 | + assert.deepEqual(result, ["network"]); |
| 78 | +}); |
| 79 | + |
| 80 | +test("getPermissionScopesRequiringAsk includes unknown when defaultMode is askAll", () => { |
| 81 | + const askAllSettings = { |
| 82 | + allow: [] as const, |
| 83 | + deny: [] as const, |
| 84 | + ask: ["network" as const], |
| 85 | + defaultMode: "askAll" as const, |
| 86 | + }; |
| 87 | + const result = getPermissionScopesRequiringAsk(["unknown", "network"], askAllSettings); |
| 88 | + assert.deepEqual(result, ["unknown", "network"]); |
| 89 | +}); |
| 90 | + |
49 | 91 | test("computeToolCallPermissions maps tool calls to permission requests", () => { |
50 | 92 | const projectRoot = createTempDir("deepcode-permissions-workspace-"); |
51 | 93 | const plan = computeToolCallPermissions({ |
|
0 commit comments