( command: string, allowedTools: string[], cwd?: string, )
| 59 | } |
| 60 | |
| 61 | async function assertAllowed( |
| 62 | command: string, |
| 63 | allowedTools: string[], |
| 64 | cwd?: string, |
| 65 | ): Promise<void> { |
| 66 | const ctx = createMockContext(allowedTools) |
| 67 | const result = await hasPermissionsToUseTool( |
| 68 | BashTool, |
| 69 | { command }, |
| 70 | cwd ? { ...ctx, getCwd: () => cwd } : ctx, |
| 71 | createAssistantMessage({ content: [] }), |
| 72 | 'test-' + command, |
| 73 | ) |
| 74 | |
| 75 | if (result.behavior !== 'allow') { |
| 76 | const reason = |
| 77 | typeof result.decisionReason === 'object' && result.decisionReason !== null |
| 78 | ? JSON.stringify(result.decisionReason) |
| 79 | : 'no reason' |
| 80 | const msg = result.message ?? 'no message' |
| 81 | throw new Error( |
| 82 | `Expected "${command}" to be allowed, got behavior=${result.behavior} message="${msg}" reason=${reason}`, |
| 83 | ) |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | async function assertDenied(command: string, allowedTools: string[]): Promise<void> { |
| 88 | const ctx = createMockContext(allowedTools) |
no test coverage detected