mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-19 09:41:17 -07:00
Fix --allowed-tools in non-interactive mode to do substring matching for parity with interactive mode. (#10944)
Co-authored-by: Allen Hutchison <adh@google.com>
This commit is contained in:
@@ -51,6 +51,8 @@ describe('ShellTool', () => {
|
||||
vi.clearAllMocks();
|
||||
|
||||
mockConfig = {
|
||||
getAllowedTools: vi.fn().mockReturnValue([]),
|
||||
getApprovalMode: vi.fn().mockReturnValue('strict'),
|
||||
getCoreTools: vi.fn().mockReturnValue([]),
|
||||
getExcludeTools: vi.fn().mockReturnValue([]),
|
||||
getDebugMode: vi.fn().mockReturnValue(false),
|
||||
@@ -410,6 +412,52 @@ describe('ShellTool', () => {
|
||||
it('should throw an error if validation fails', () => {
|
||||
expect(() => shellTool.build({ command: '' })).toThrow();
|
||||
});
|
||||
|
||||
describe('in non-interactive mode', () => {
|
||||
beforeEach(() => {
|
||||
(mockConfig.isInteractive as Mock).mockReturnValue(false);
|
||||
});
|
||||
|
||||
it('should not throw an error or block for an allowed command', async () => {
|
||||
(mockConfig.getAllowedTools as Mock).mockReturnValue(['ShellTool(wc)']);
|
||||
const invocation = shellTool.build({ command: 'wc -l foo.txt' });
|
||||
const confirmation = await invocation.shouldConfirmExecute(
|
||||
new AbortController().signal,
|
||||
);
|
||||
expect(confirmation).toBe(false);
|
||||
});
|
||||
|
||||
it('should not throw an error or block for an allowed command with arguments', async () => {
|
||||
(mockConfig.getAllowedTools as Mock).mockReturnValue([
|
||||
'ShellTool(wc -l)',
|
||||
]);
|
||||
const invocation = shellTool.build({ command: 'wc -l foo.txt' });
|
||||
const confirmation = await invocation.shouldConfirmExecute(
|
||||
new AbortController().signal,
|
||||
);
|
||||
expect(confirmation).toBe(false);
|
||||
});
|
||||
|
||||
it('should throw an error for command that is not allowed', async () => {
|
||||
(mockConfig.getAllowedTools as Mock).mockReturnValue([
|
||||
'ShellTool(wc -l)',
|
||||
]);
|
||||
const invocation = shellTool.build({ command: 'madeupcommand' });
|
||||
await expect(
|
||||
invocation.shouldConfirmExecute(new AbortController().signal),
|
||||
).rejects.toThrow('madeupcommand');
|
||||
});
|
||||
|
||||
it('should throw an error for a command that is a prefix of an allowed command', async () => {
|
||||
(mockConfig.getAllowedTools as Mock).mockReturnValue([
|
||||
'ShellTool(wc -l)',
|
||||
]);
|
||||
const invocation = shellTool.build({ command: 'wc' });
|
||||
await expect(
|
||||
invocation.shouldConfirmExecute(new AbortController().signal),
|
||||
).rejects.toThrow('wc');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('getDescription', () => {
|
||||
|
||||
Reference in New Issue
Block a user