fix(acp-integration/agent): clear pendingConfirmation when tool result arrives for pending tool

- Track pendingConfirmationCallId in AgentToolInvocation to properly clear stale prompts
- Clear pendingConfirmation when TOOL_RESULT arrives for the pending tool (IDE diff-tab path)
- Clear pendingConfirmation via onConfirm callback (terminal UI path)
- Ensure pendingConfirmation is NOT cleared when TOOL_RESULT is for a different tool
- Prefer filePath over fileName for diff content path in Session and SubAgentTracker
- Add comprehensive tests for IDE diff-tab and terminal UI confirmation flows

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
yiliang114 2026-03-23 23:49:22 +08:00
parent 38caa0b218
commit ee1f98f4ff
5 changed files with 414 additions and 12 deletions

View file

@ -531,6 +531,86 @@ describe('SubAgentTracker', () => {
expect(respondSpy).toHaveBeenCalledWith(ToolConfirmationOutcome.Cancel);
});
});
it('should use filePath over fileName for diff content path', async () => {
tracker.setup(eventEmitter, abortController.signal);
const respondSpy = vi.fn().mockResolvedValue(undefined);
const event = createApprovalEvent({
name: 'edit_file',
callId: 'call-path-test',
description: 'Editing file',
confirmationDetails: createEditConfirmation({
fileName: 'test.ts',
filePath: '/workspace/src/test.ts',
originalContent: 'old content',
newContent: 'new content',
}),
respond: respondSpy,
});
eventEmitter.emit(AgentEventType.TOOL_WAITING_APPROVAL, event);
await vi.waitFor(() => {
expect(requestPermissionSpy).toHaveBeenCalled();
});
expect(requestPermissionSpy).toHaveBeenCalledWith(
expect.objectContaining({
toolCall: expect.objectContaining({
content: [
{
type: 'diff',
path: '/workspace/src/test.ts',
oldText: 'old content',
newText: 'new content',
},
],
}),
}),
);
});
it('should fall back to fileName when filePath is not available', async () => {
tracker.setup(eventEmitter, abortController.signal);
const respondSpy = vi.fn().mockResolvedValue(undefined);
const event = createApprovalEvent({
name: 'edit_file',
callId: 'call-fallback-test',
description: 'Editing file',
confirmationDetails: {
type: 'edit' as const,
title: 'Edit file',
fileName: 'fallback.ts',
fileDiff: '',
originalContent: 'old',
newContent: 'new',
} as Omit<ToolEditConfirmationDetails, 'onConfirm'>,
respond: respondSpy,
});
eventEmitter.emit(AgentEventType.TOOL_WAITING_APPROVAL, event);
await vi.waitFor(() => {
expect(requestPermissionSpy).toHaveBeenCalled();
});
expect(requestPermissionSpy).toHaveBeenCalledWith(
expect.objectContaining({
toolCall: expect.objectContaining({
content: [
{
type: 'diff',
path: 'fallback.ts',
oldText: 'old',
newText: 'new',
},
],
}),
}),
);
});
});
describe('permission options', () => {