remove unnecessary checks in WriteFileChecks.getDescription (#5526)

This commit is contained in:
Jacob MacDonald 2025-08-04 12:12:33 -07:00 committed by GitHub
parent d1bfba1abb
commit 5caf23d627
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 29 additions and 3 deletions

View File

@ -13,7 +13,7 @@ import {
vi, vi,
type Mocked, type Mocked,
} from 'vitest'; } from 'vitest';
import { WriteFileTool } from './write-file.js'; import { WriteFileTool, WriteFileToolParams } from './write-file.js';
import { import {
FileDiff, FileDiff,
ToolConfirmationOutcome, ToolConfirmationOutcome,
@ -202,6 +202,32 @@ describe('WriteFileTool', () => {
`Path is a directory, not a file: ${dirAsFilePath}`, `Path is a directory, not a file: ${dirAsFilePath}`,
); );
}); });
it('should return error if the content is null', () => {
const dirAsFilePath = path.join(rootDir, 'a_directory');
fs.mkdirSync(dirAsFilePath);
const params = {
file_path: dirAsFilePath,
content: null,
} as unknown as WriteFileToolParams; // Intentionally non-conforming
expect(tool.validateToolParams(params)).toMatch(
`params/content must be string`,
);
});
});
describe('getDescription', () => {
it('should return error if the file_path is empty', () => {
const dirAsFilePath = path.join(rootDir, 'a_directory');
fs.mkdirSync(dirAsFilePath);
const params = {
file_path: '',
content: '',
};
expect(tool.getDescription(params)).toMatch(
`Model did not provide valid parameters for write file tool, missing or empty "file_path"`,
);
});
}); });
describe('_getCorrectedFileContent', () => { describe('_getCorrectedFileContent', () => {

View File

@ -131,8 +131,8 @@ export class WriteFileTool
} }
getDescription(params: WriteFileToolParams): string { getDescription(params: WriteFileToolParams): string {
if (!params.file_path || !params.content) { if (!params.file_path) {
return `Model did not provide valid parameters for write file tool`; return `Model did not provide valid parameters for write file tool, missing or empty "file_path"`;
} }
const relativePath = makeRelative( const relativePath = makeRelative(
params.file_path, params.file_path,