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,
);
expect(shellRules).toHaveLength(2);
expect(
shellRules?.some((r) => r.argsPattern?.test('{"command":"git status"}')),
).toBe(true);
expect(
shellRules?.some((r) => r.argsPattern?.test('{"command":"git diff"}')),
).toBe(true);
expect(
shellRules?.every(
(r) => !r.argsPattern?.test('{"command":"git commit"}'),
),
).toBe(true);
expect(shellRules?.some((r) => r.argsPattern?.test('git status'))).toBe(
true,
);
expect(shellRules?.some((r) => r.argsPattern?.test('git diff'))).toBe(true);
expect(shellRules?.every((r) => !r.argsPattern?.test('git commit'))).toBe(
true,
);
const subagentRule = config.rules?.find(
(r) =>
+2 -1
View File
@@ -154,8 +154,9 @@ describe('createPolicyUpdater', () => {
expect(addedRule).toBeDefined();
expect(addedRule?.priority).toBe(ALWAYS_ALLOW_PRIORITY);
expect(addedRule?.argsPattern).toEqual(
new RegExp(`"command":"git\\ status(?:[\\s"]|\\\\")`),
new RegExp(`^git\\ status(?:\\s|$)`),
);
expect(addedRule?.argName).toBe('command');
// Verify file written
expect(fs.open).toHaveBeenCalledWith(expect.stringMatching(/\.tmp$/), 'wx');
@@ -75,7 +75,8 @@ describe('createPolicyUpdater', () => {
expect.objectContaining({
toolName: 'run_shell_command',
priority: ALWAYS_ALLOW_PRIORITY,
argsPattern: new RegExp('"command":"echo(?:[\\s"]|\\\\")'),
argsPattern: new RegExp('^echo(?:\\s|$)'),
argName: 'command',
}),
);
expect(policyEngine.addRule).toHaveBeenNthCalledWith(
@@ -83,7 +84,8 @@ describe('createPolicyUpdater', () => {
expect.objectContaining({
toolName: 'run_shell_command',
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({
toolName: 'run_shell_command',
priority: ALWAYS_ALLOW_PRIORITY,
argsPattern: new RegExp('"command":"git(?:[\\s"]|\\\\")'),
argsPattern: new RegExp('^git(?:\\s|$)'),
argName: 'command',
}),
);
});