feat(plan): refactor ToolConfirmationPayload to union type (#17980)

This commit is contained in:
Jerop Kipruto
2026-01-30 14:51:45 -05:00
committed by GitHub
parent 6396ab1ccb
commit 71308caf05
8 changed files with 127 additions and 15 deletions
+1 -1
View File
@@ -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,
+1 -1
View File
@@ -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;