fix(core): prevent omission placeholder deletions in replace/write_file (#19870)

Co-authored-by: Bryan Morgan <bryanmorgan@google.com>
This commit is contained in:
Nick Salerni
2026-02-22 11:58:31 -08:00
committed by GitHub
parent d96bd05d36
commit faa1ec3044
9 changed files with 282 additions and 8 deletions
@@ -310,6 +310,42 @@ describe('WriteFileTool', () => {
};
expect(() => tool.build(params)).toThrow(`Missing or empty "file_path"`);
});
it('should throw an error if content includes an omission placeholder', () => {
const params = {
file_path: path.join(rootDir, 'placeholder.txt'),
content: '(rest of methods ...)',
};
expect(() => tool.build(params)).toThrow(
"`content` contains an omission placeholder (for example 'rest of methods ...'). Provide complete file content.",
);
});
it('should throw an error when multiline content includes omission placeholders', () => {
const params = {
file_path: path.join(rootDir, 'service.ts'),
content: `class Service {
execute() {
return "run";
}
// rest of methods ...
}`,
};
expect(() => tool.build(params)).toThrow(
"`content` contains an omission placeholder (for example 'rest of methods ...'). Provide complete file content.",
);
});
it('should allow content with placeholder text in a normal string literal', () => {
const params = {
file_path: path.join(rootDir, 'valid-content.ts'),
content: 'const note = "(rest of methods ...)";',
};
const invocation = tool.build(params);
expect(invocation).toBeDefined();
expect(invocation.params).toEqual(params);
});
});
describe('getCorrectedFileContent', () => {