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