mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-21 10:34:35 -07:00
feat(plan): refactor ToolConfirmationPayload to union type (#17980)
This commit is contained in:
@@ -156,7 +156,7 @@ export async function resolveConfirmation(
|
||||
|
||||
if (outcome === ToolConfirmationOutcome.ModifyWithEditor) {
|
||||
await handleExternalModification(deps, toolCall, signal);
|
||||
} else if (response.payload?.newContent) {
|
||||
} else if (response.payload && 'newContent' in response.payload) {
|
||||
await handleInlineModification(deps, toolCall, response.payload, signal);
|
||||
outcome = ToolConfirmationOutcome.ProceedOnce;
|
||||
}
|
||||
|
||||
@@ -193,13 +193,46 @@ describe('ToolModificationHandler', () => {
|
||||
|
||||
const result = await handler.applyInlineModify(
|
||||
mockWaitingToolCall,
|
||||
{ newContent: undefined } as unknown as ToolConfirmationPayload,
|
||||
{} as ToolConfirmationPayload, // no newContent property
|
||||
new AbortController().signal,
|
||||
);
|
||||
|
||||
expect(result).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should process empty string as valid new content', async () => {
|
||||
vi.mocked(
|
||||
modifiableToolModule.isModifiableDeclarativeTool,
|
||||
).mockReturnValue(true);
|
||||
(Diff.createPatch as unknown as Mock).mockReturnValue('mock-diff-empty');
|
||||
|
||||
mockModifyContext.getCurrentContent.mockResolvedValue('old content');
|
||||
mockModifyContext.getFilePath.mockReturnValue('test.txt');
|
||||
mockModifyContext.createUpdatedParams.mockReturnValue({
|
||||
content: '',
|
||||
});
|
||||
|
||||
const mockWaitingToolCall = createMockWaitingToolCall({
|
||||
tool: mockModifiableTool,
|
||||
});
|
||||
|
||||
const result = await handler.applyInlineModify(
|
||||
mockWaitingToolCall,
|
||||
{ newContent: '' },
|
||||
new AbortController().signal,
|
||||
);
|
||||
|
||||
expect(mockModifyContext.createUpdatedParams).toHaveBeenCalledWith(
|
||||
expect.any(String),
|
||||
'',
|
||||
expect.any(Object),
|
||||
);
|
||||
expect(result).toEqual({
|
||||
updatedParams: { content: '' },
|
||||
updatedDiff: 'mock-diff-empty',
|
||||
});
|
||||
});
|
||||
|
||||
it('should calculate diff and return updated params', async () => {
|
||||
vi.mocked(
|
||||
modifiableToolModule.isModifiableDeclarativeTool,
|
||||
|
||||
@@ -70,7 +70,7 @@ export class ToolModificationHandler {
|
||||
): Promise<ModificationResult | undefined> {
|
||||
if (
|
||||
toolCall.confirmationDetails.type !== 'edit' ||
|
||||
!payload.newContent ||
|
||||
!('newContent' in payload) ||
|
||||
!isModifiableDeclarativeTool(toolCall.tool)
|
||||
) {
|
||||
return undefined;
|
||||
|
||||
Reference in New Issue
Block a user