test: fix policy tests for argName logic

This commit is contained in:
Abhijit Balaji
2026-02-20 15:06:36 -08:00
parent 95d687a7dd
commit 92acd0de56
3 changed files with 15 additions and 15 deletions
+7 -11
View File
@@ -1169,17 +1169,13 @@ modes = ["plan"]
r.argsPattern, r.argsPattern,
); );
expect(shellRules).toHaveLength(2); expect(shellRules).toHaveLength(2);
expect( expect(shellRules?.some((r) => r.argsPattern?.test('git status'))).toBe(
shellRules?.some((r) => r.argsPattern?.test('{"command":"git status"}')), true,
).toBe(true); );
expect( expect(shellRules?.some((r) => r.argsPattern?.test('git diff'))).toBe(true);
shellRules?.some((r) => r.argsPattern?.test('{"command":"git diff"}')), expect(shellRules?.every((r) => !r.argsPattern?.test('git commit'))).toBe(
).toBe(true); true,
expect( );
shellRules?.every(
(r) => !r.argsPattern?.test('{"command":"git commit"}'),
),
).toBe(true);
const subagentRule = config.rules?.find( const subagentRule = config.rules?.find(
(r) => (r) =>
+2 -1
View File
@@ -154,8 +154,9 @@ describe('createPolicyUpdater', () => {
expect(addedRule).toBeDefined(); expect(addedRule).toBeDefined();
expect(addedRule?.priority).toBe(ALWAYS_ALLOW_PRIORITY); expect(addedRule?.priority).toBe(ALWAYS_ALLOW_PRIORITY);
expect(addedRule?.argsPattern).toEqual( expect(addedRule?.argsPattern).toEqual(
new RegExp(`"command":"git\\ status(?:[\\s"]|\\\\")`), new RegExp(`^git\\ status(?:\\s|$)`),
); );
expect(addedRule?.argName).toBe('command');
// Verify file written // Verify file written
expect(fs.open).toHaveBeenCalledWith(expect.stringMatching(/\.tmp$/), 'wx'); expect(fs.open).toHaveBeenCalledWith(expect.stringMatching(/\.tmp$/), 'wx');
@@ -75,7 +75,8 @@ describe('createPolicyUpdater', () => {
expect.objectContaining({ expect.objectContaining({
toolName: 'run_shell_command', toolName: 'run_shell_command',
priority: ALWAYS_ALLOW_PRIORITY, priority: ALWAYS_ALLOW_PRIORITY,
argsPattern: new RegExp('"command":"echo(?:[\\s"]|\\\\")'), argsPattern: new RegExp('^echo(?:\\s|$)'),
argName: 'command',
}), }),
); );
expect(policyEngine.addRule).toHaveBeenNthCalledWith( expect(policyEngine.addRule).toHaveBeenNthCalledWith(
@@ -83,7 +84,8 @@ describe('createPolicyUpdater', () => {
expect.objectContaining({ expect.objectContaining({
toolName: 'run_shell_command', toolName: 'run_shell_command',
priority: ALWAYS_ALLOW_PRIORITY, priority: ALWAYS_ALLOW_PRIORITY,
argsPattern: new RegExp('"command":"ls(?:[\\s"]|\\\\")'), argsPattern: new RegExp('^ls(?:\\s|$)'),
argName: 'command',
}), }),
); );
}); });
@@ -103,7 +105,8 @@ describe('createPolicyUpdater', () => {
expect.objectContaining({ expect.objectContaining({
toolName: 'run_shell_command', toolName: 'run_shell_command',
priority: ALWAYS_ALLOW_PRIORITY, priority: ALWAYS_ALLOW_PRIORITY,
argsPattern: new RegExp('"command":"git(?:[\\s"]|\\\\")'), argsPattern: new RegExp('^git(?:\\s|$)'),
argName: 'command',
}), }),
); );
}); });