diff options
Diffstat (limited to 'packages/core/src/tools/read-file.test.ts')
| -rw-r--r-- | packages/core/src/tools/read-file.test.ts | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/packages/core/src/tools/read-file.test.ts b/packages/core/src/tools/read-file.test.ts index 987b451c..bfb08a6c 100644 --- a/packages/core/src/tools/read-file.test.ts +++ b/packages/core/src/tools/read-file.test.ts @@ -57,14 +57,14 @@ describe('ReadFileTool', () => { describe('validateToolParams', () => { it('should return null for valid params (absolute path within root)', () => { const params: ReadFileToolParams = { - path: path.join(tempRootDir, 'test.txt'), + absolute_path: path.join(tempRootDir, 'test.txt'), }; expect(tool.validateToolParams(params)).toBeNull(); }); it('should return null for valid params with offset and limit', () => { const params: ReadFileToolParams = { - path: path.join(tempRootDir, 'test.txt'), + absolute_path: path.join(tempRootDir, 'test.txt'), offset: 0, limit: 10, }; @@ -72,7 +72,7 @@ describe('ReadFileTool', () => { }); it('should return error for relative path', () => { - const params: ReadFileToolParams = { path: 'test.txt' }; + const params: ReadFileToolParams = { absolute_path: 'test.txt' }; expect(tool.validateToolParams(params)).toMatch( /File path must be absolute/, ); @@ -80,7 +80,7 @@ describe('ReadFileTool', () => { it('should return error for path outside root', () => { const outsidePath = path.resolve(os.tmpdir(), 'outside-root.txt'); - const params: ReadFileToolParams = { path: outsidePath }; + const params: ReadFileToolParams = { absolute_path: outsidePath }; expect(tool.validateToolParams(params)).toMatch( /File path must be within the root directory/, ); @@ -88,7 +88,7 @@ describe('ReadFileTool', () => { it('should return error for negative offset', () => { const params: ReadFileToolParams = { - path: path.join(tempRootDir, 'test.txt'), + absolute_path: path.join(tempRootDir, 'test.txt'), offset: -1, limit: 10, }; @@ -99,7 +99,7 @@ describe('ReadFileTool', () => { it('should return error for non-positive limit', () => { const paramsZero: ReadFileToolParams = { - path: path.join(tempRootDir, 'test.txt'), + absolute_path: path.join(tempRootDir, 'test.txt'), offset: 0, limit: 0, }; @@ -107,7 +107,7 @@ describe('ReadFileTool', () => { 'Limit must be a positive number', ); const paramsNegative: ReadFileToolParams = { - path: path.join(tempRootDir, 'test.txt'), + absolute_path: path.join(tempRootDir, 'test.txt'), offset: 0, limit: -5, }; @@ -127,21 +127,21 @@ describe('ReadFileTool', () => { describe('getDescription', () => { it('should return a shortened, relative path', () => { const filePath = path.join(tempRootDir, 'sub', 'dir', 'file.txt'); - const params: ReadFileToolParams = { path: filePath }; + const params: ReadFileToolParams = { absolute_path: filePath }; // Assuming tempRootDir is something like /tmp/read-file-tool-root-XXXXXX // The relative path would be sub/dir/file.txt expect(tool.getDescription(params)).toBe('sub/dir/file.txt'); }); it('should return . if path is the root directory', () => { - const params: ReadFileToolParams = { path: tempRootDir }; + const params: ReadFileToolParams = { absolute_path: tempRootDir }; expect(tool.getDescription(params)).toBe('.'); }); }); describe('execute', () => { it('should return validation error if params are invalid', async () => { - const params: ReadFileToolParams = { path: 'relative/path.txt' }; + const params: ReadFileToolParams = { absolute_path: 'relative/path.txt' }; const result = await tool.execute(params, abortSignal); expect(result.llmContent).toMatch(/Error: Invalid parameters provided/); expect(result.returnDisplay).toMatch(/File path must be absolute/); @@ -149,7 +149,7 @@ describe('ReadFileTool', () => { it('should return error from processSingleFileContent if it fails', async () => { const filePath = path.join(tempRootDir, 'error.txt'); - const params: ReadFileToolParams = { path: filePath }; + const params: ReadFileToolParams = { absolute_path: filePath }; const errorMessage = 'Simulated read error'; mockProcessSingleFileContent.mockResolvedValue({ llmContent: `Error reading file ${filePath}: ${errorMessage}`, @@ -171,7 +171,7 @@ describe('ReadFileTool', () => { it('should return success result for a text file', async () => { const filePath = path.join(tempRootDir, 'textfile.txt'); const fileContent = 'This is a test file.'; - const params: ReadFileToolParams = { path: filePath }; + const params: ReadFileToolParams = { absolute_path: filePath }; mockProcessSingleFileContent.mockResolvedValue({ llmContent: fileContent, returnDisplay: `Read text file: ${path.basename(filePath)}`, @@ -195,7 +195,7 @@ describe('ReadFileTool', () => { const imageData = { inlineData: { mimeType: 'image/png', data: 'base64...' }, }; - const params: ReadFileToolParams = { path: filePath }; + const params: ReadFileToolParams = { absolute_path: filePath }; mockProcessSingleFileContent.mockResolvedValue({ llmContent: imageData, returnDisplay: `Read image file: ${path.basename(filePath)}`, @@ -217,7 +217,7 @@ describe('ReadFileTool', () => { it('should pass offset and limit to processSingleFileContent', async () => { const filePath = path.join(tempRootDir, 'paginated.txt'); const params: ReadFileToolParams = { - path: filePath, + absolute_path: filePath, offset: 10, limit: 5, }; @@ -237,7 +237,7 @@ describe('ReadFileTool', () => { it('should return error if path is ignored by a .geminiignore pattern', async () => { const params: ReadFileToolParams = { - path: path.join(tempRootDir, 'foo.bar'), + absolute_path: path.join(tempRootDir, 'foo.bar'), }; const result = await tool.execute(params, abortSignal); expect(result.returnDisplay).toContain('foo.bar'); |
