diff options
| author | Akhil Appana <[email protected]> | 2025-08-08 04:33:42 -0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-08-08 11:33:42 +0000 |
| commit | f5e0f16157da6a0b0dbae3b4ebf920fdee81c461 (patch) | |
| tree | e8f91ee92d41a5ac7280b2bad7e8cba103bc1ca7 /packages/core/src/tools/shell.test.ts | |
| parent | 5ab184fcaf40d4e7dec9ba6a0526cac39b602ee2 (diff) | |
fix: properly report tool errors in telemetry (#5688)
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Diffstat (limited to 'packages/core/src/tools/shell.test.ts')
| -rw-r--r-- | packages/core/src/tools/shell.test.ts | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/packages/core/src/tools/shell.test.ts b/packages/core/src/tools/shell.test.ts index 7f237e3d..55720af5 100644 --- a/packages/core/src/tools/shell.test.ts +++ b/packages/core/src/tools/shell.test.ts @@ -25,6 +25,7 @@ vi.mock('../utils/summarizer.js'); import { isCommandAllowed } from '../utils/shell-utils.js'; import { ShellTool } from './shell.js'; +import { ToolErrorType } from './tool-error.js'; import { type Config } from '../config/config.js'; import { type ShellExecutionResult, @@ -203,6 +204,42 @@ describe('ShellTool', () => { expect(result.llmContent).not.toContain('pgrep'); }); + it('should return error with error property for invalid parameters', async () => { + const result = await shellTool.execute( + { command: '' }, // Empty command is invalid + mockAbortSignal, + ); + + expect(result.llmContent).toContain( + 'Could not execute command due to invalid parameters:', + ); + expect(result.returnDisplay).toBe('Command cannot be empty.'); + expect(result.error).toEqual({ + message: 'Command cannot be empty.', + type: ToolErrorType.INVALID_TOOL_PARAMS, + }); + }); + + it('should return error with error property for invalid directory', async () => { + vi.mocked(fs.existsSync).mockReturnValue(false); + const result = await shellTool.execute( + { command: 'ls', directory: 'nonexistent' }, + mockAbortSignal, + ); + + expect(result.llmContent).toContain( + 'Could not execute command due to invalid parameters:', + ); + expect(result.returnDisplay).toBe( + "Directory 'nonexistent' is not a registered workspace directory.", + ); + expect(result.error).toEqual({ + message: + "Directory 'nonexistent' is not a registered workspace directory.", + type: ToolErrorType.INVALID_TOOL_PARAMS, + }); + }); + it('should summarize output when configured', async () => { (mockConfig.getSummarizeToolOutputConfig as Mock).mockReturnValue({ [shellTool.name]: { tokenBudget: 1000 }, |
