mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-19 09:33:53 +00:00
feat(core): Annotate remaining error paths in tools with type. (#6699)
This commit is contained in:
@@ -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[] = [];
|
||||
|
||||
Reference in New Issue
Block a user