diff options
| author | joshualitt <[email protected]> | 2025-08-21 14:40:18 -0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-08-21 21:40:18 +0000 |
| commit | ec41b8db8e714867ea354c29c07f009cd837ac23 (patch) | |
| tree | 4bb01ac90a25d6d82cfc005d68aae336be192744 /packages/core/src/tools/read-many-files.test.ts | |
| parent | 299bf58309a0950ac81ae051b02ec64463ebd153 (diff) | |
feat(core): Annotate remaining error paths in tools with type. (#6699)
Diffstat (limited to 'packages/core/src/tools/read-many-files.test.ts')
| -rw-r--r-- | packages/core/src/tools/read-many-files.test.ts | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/packages/core/src/tools/read-many-files.test.ts b/packages/core/src/tools/read-many-files.test.ts index b432998d..0e55f5c0 100644 --- a/packages/core/src/tools/read-many-files.test.ts +++ b/packages/core/src/tools/read-many-files.test.ts @@ -15,6 +15,10 @@ import os from 'os'; import { Config } from '../config/config.js'; import { WorkspaceContext } from '../utils/workspaceContext.js'; import { StandardFileSystemService } from '../services/fileSystemService.js'; +import { ToolErrorType } from './tool-error.js'; +import * as glob from 'glob'; + +vi.mock('glob', { spy: true }); vi.mock('mime-types', () => { const lookup = (filename: string) => { @@ -566,6 +570,28 @@ Content of file[1] }); }); + describe('Error handling', () => { + it('should return an INVALID_TOOL_PARAMS error if no paths are provided', async () => { + const params = { paths: [], include: [] }; + expect(() => { + tool.build(params); + }).toThrow('params/paths must NOT have fewer than 1 items'); + }); + + it('should return a READ_MANY_FILES_SEARCH_ERROR on glob failure', async () => { + vi.mocked(glob.glob).mockRejectedValue(new Error('Glob failed')); + const params = { paths: ['*.txt'] }; + const invocation = tool.build(params); + const result = await invocation.execute(new AbortController().signal); + expect(result.error?.type).toBe( + ToolErrorType.READ_MANY_FILES_SEARCH_ERROR, + ); + expect(result.llmContent).toBe('Error during file search: Glob failed'); + // Reset glob. + vi.mocked(glob.glob).mockReset(); + }); + }); + describe('Batch Processing', () => { const createMultipleFiles = (count: number, contentPrefix = 'Content') => { const files: string[] = []; |
