mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-19 09:33:53 +00:00
Update edit tool validation function to override validateToolParams (#667)
This commit is contained in:
@@ -178,14 +178,14 @@ describe('EditTool', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('validateParams', () => {
|
describe('validateToolParams', () => {
|
||||||
it('should return null for valid params', () => {
|
it('should return null for valid params', () => {
|
||||||
const params: EditToolParams = {
|
const params: EditToolParams = {
|
||||||
file_path: path.join(rootDir, 'test.txt'),
|
file_path: path.join(rootDir, 'test.txt'),
|
||||||
old_string: 'old',
|
old_string: 'old',
|
||||||
new_string: 'new',
|
new_string: 'new',
|
||||||
};
|
};
|
||||||
expect(tool.validateParams(params)).toBeNull();
|
expect(tool.validateToolParams(params)).toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return error for relative path', () => {
|
it('should return error for relative path', () => {
|
||||||
@@ -194,7 +194,9 @@ describe('EditTool', () => {
|
|||||||
old_string: 'old',
|
old_string: 'old',
|
||||||
new_string: 'new',
|
new_string: 'new',
|
||||||
};
|
};
|
||||||
expect(tool.validateParams(params)).toMatch(/File path must be absolute/);
|
expect(tool.validateToolParams(params)).toMatch(
|
||||||
|
/File path must be absolute/,
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return error for path outside root', () => {
|
it('should return error for path outside root', () => {
|
||||||
@@ -203,7 +205,7 @@ describe('EditTool', () => {
|
|||||||
old_string: 'old',
|
old_string: 'old',
|
||||||
new_string: 'new',
|
new_string: 'new',
|
||||||
};
|
};
|
||||||
expect(tool.validateParams(params)).toMatch(
|
expect(tool.validateToolParams(params)).toMatch(
|
||||||
/File path must be within the root directory/,
|
/File path must be within the root directory/,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -126,7 +126,7 @@ Expectation for parameters:
|
|||||||
* @param params Parameters to validate
|
* @param params Parameters to validate
|
||||||
* @returns Error message string or null if valid
|
* @returns Error message string or null if valid
|
||||||
*/
|
*/
|
||||||
validateParams(params: EditToolParams): string | null {
|
validateToolParams(params: EditToolParams): string | null {
|
||||||
if (
|
if (
|
||||||
this.schema.parameters &&
|
this.schema.parameters &&
|
||||||
!SchemaValidator.validate(
|
!SchemaValidator.validate(
|
||||||
@@ -372,7 +372,7 @@ Expectation for parameters:
|
|||||||
params: EditToolParams,
|
params: EditToolParams,
|
||||||
_signal: AbortSignal,
|
_signal: AbortSignal,
|
||||||
): Promise<ToolResult> {
|
): Promise<ToolResult> {
|
||||||
const validationError = this.validateParams(params);
|
const validationError = this.validateToolParams(params);
|
||||||
if (validationError) {
|
if (validationError) {
|
||||||
return {
|
return {
|
||||||
llmContent: `Error: Invalid parameters provided. Reason: ${validationError}`,
|
llmContent: `Error: Invalid parameters provided. Reason: ${validationError}`,
|
||||||
|
|||||||
Reference in New Issue
Block a user