( command: string, policy: SandboxPolicy | undefined, scripts?: Record<string, string>, )
| 91 | * or its expanded command value (and vice versa for the command under test). |
| 92 | */ |
| 93 | export function evaluateCommand( |
| 94 | command: string, |
| 95 | policy: SandboxPolicy | undefined, |
| 96 | scripts?: Record<string, string>, |
| 97 | ): PolicyDecision { |
| 98 | const fallback = policy?.default ?? 'ask' |
| 99 | const rules = policy?.commands |
| 100 | if (!rules) return fallback |
| 101 | |
| 102 | const matches = (patterns: Array<string> | undefined): boolean => |
| 103 | (patterns ?? []).some((pattern) => |
| 104 | patternMatchesCommand(pattern, command, scripts), |
| 105 | ) |
| 106 | |
| 107 | if (matches(rules.deny)) return 'deny' |
| 108 | if (matches(rules.ask)) return 'ask' |
| 109 | if (matches(rules.allow)) return 'allow' |
| 110 | return fallback |
| 111 | } |
no test coverage detected