mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-28 05:55:17 -07:00
fix(core): Fix unable to cancel edit tool (#9299)
This commit is contained in:
@@ -471,6 +471,34 @@ describe('EditTool', () => {
|
||||
);
|
||||
expect(patchedContent).toBe(expectedFinalContent);
|
||||
});
|
||||
|
||||
it('should rethrow calculateEdit errors when the abort signal is triggered', async () => {
|
||||
const filePath = path.join(rootDir, 'abort-confirmation.txt');
|
||||
const params: EditToolParams = {
|
||||
file_path: filePath,
|
||||
old_string: 'old',
|
||||
new_string: 'new',
|
||||
};
|
||||
|
||||
const invocation = tool.build(params);
|
||||
const abortController = new AbortController();
|
||||
const abortError = new Error('Abort requested');
|
||||
|
||||
const calculateSpy = vi
|
||||
.spyOn(invocation as any, 'calculateEdit')
|
||||
.mockImplementation(async () => {
|
||||
if (!abortController.signal.aborted) {
|
||||
abortController.abort();
|
||||
}
|
||||
throw abortError;
|
||||
});
|
||||
|
||||
await expect(
|
||||
invocation.shouldConfirmExecute(abortController.signal),
|
||||
).rejects.toBe(abortError);
|
||||
|
||||
calculateSpy.mockRestore();
|
||||
});
|
||||
});
|
||||
|
||||
describe('execute', () => {
|
||||
@@ -515,6 +543,33 @@ describe('EditTool', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('should reject when calculateEdit fails after an abort signal', async () => {
|
||||
const params: EditToolParams = {
|
||||
file_path: path.join(rootDir, 'abort-execute.txt'),
|
||||
old_string: 'old',
|
||||
new_string: 'new',
|
||||
};
|
||||
|
||||
const invocation = tool.build(params);
|
||||
const abortController = new AbortController();
|
||||
const abortError = new Error('Abort requested during execute');
|
||||
|
||||
const calculateSpy = vi
|
||||
.spyOn(invocation as any, 'calculateEdit')
|
||||
.mockImplementation(async () => {
|
||||
if (!abortController.signal.aborted) {
|
||||
abortController.abort();
|
||||
}
|
||||
throw abortError;
|
||||
});
|
||||
|
||||
await expect(invocation.execute(abortController.signal)).rejects.toBe(
|
||||
abortError,
|
||||
);
|
||||
|
||||
calculateSpy.mockRestore();
|
||||
});
|
||||
|
||||
it('should edit an existing file and return diff with fileName', async () => {
|
||||
const initialContent = 'This is some old text.';
|
||||
const newContent = 'This is some new text.'; // old -> new
|
||||
|
||||
Reference in New Issue
Block a user