mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-05-16 23:02:51 -07:00
test: fix policy tests for argName logic
This commit is contained in:
@@ -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) =>
|
||||
|
||||
@@ -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',
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user