mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-18 10:01:29 -07:00
refactor(cli): finalize event-driven transition and remove interaction bridge (#18569)
This commit is contained in:
@@ -14,7 +14,6 @@ import {
|
||||
ToolConfirmationOutcome,
|
||||
MessageBusType,
|
||||
IdeClient,
|
||||
type ToolCallConfirmationDetails,
|
||||
} from '@google/gemini-cli-core';
|
||||
import { ToolCallStatus, type IndividualToolCallDisplay } from '../types.js';
|
||||
|
||||
@@ -50,21 +49,9 @@ describe('ToolActionsContext', () => {
|
||||
resultDisplay: undefined,
|
||||
confirmationDetails: { type: 'info', title: 'title', prompt: 'prompt' },
|
||||
},
|
||||
{
|
||||
callId: 'legacy-call',
|
||||
name: 'legacy-tool',
|
||||
description: 'desc',
|
||||
status: ToolCallStatus.Confirming,
|
||||
resultDisplay: undefined,
|
||||
confirmationDetails: {
|
||||
type: 'info',
|
||||
title: 'legacy',
|
||||
prompt: 'prompt',
|
||||
onConfirm: vi.fn(),
|
||||
} as ToolCallConfirmationDetails,
|
||||
},
|
||||
{
|
||||
callId: 'edit-call',
|
||||
correlationId: 'corr-edit',
|
||||
name: 'edit-tool',
|
||||
description: 'desc',
|
||||
status: ToolCallStatus.Confirming,
|
||||
@@ -77,8 +64,7 @@ describe('ToolActionsContext', () => {
|
||||
fileDiff: 'diff',
|
||||
originalContent: 'old',
|
||||
newContent: 'new',
|
||||
onConfirm: vi.fn(),
|
||||
} as ToolCallConfirmationDetails,
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
@@ -92,7 +78,7 @@ describe('ToolActionsContext', () => {
|
||||
</ToolActionsProvider>
|
||||
);
|
||||
|
||||
it('publishes to MessageBus for tools with correlationId (Modern Path)', async () => {
|
||||
it('publishes to MessageBus for tools with correlationId', async () => {
|
||||
const { result } = renderHook(() => useToolActions(), { wrapper });
|
||||
|
||||
await result.current.confirm(
|
||||
@@ -110,27 +96,6 @@ describe('ToolActionsContext', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('calls onConfirm for legacy tools (Legacy Path)', async () => {
|
||||
const { result } = renderHook(() => useToolActions(), { wrapper });
|
||||
const legacyDetails = mockToolCalls[1]
|
||||
.confirmationDetails as ToolCallConfirmationDetails;
|
||||
|
||||
await result.current.confirm(
|
||||
'legacy-call',
|
||||
ToolConfirmationOutcome.ProceedOnce,
|
||||
);
|
||||
|
||||
if (legacyDetails && 'onConfirm' in legacyDetails) {
|
||||
expect(legacyDetails.onConfirm).toHaveBeenCalledWith(
|
||||
ToolConfirmationOutcome.ProceedOnce,
|
||||
undefined,
|
||||
);
|
||||
} else {
|
||||
throw new Error('Expected onConfirm to be present');
|
||||
}
|
||||
expect(mockMessageBus.publish).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('handles cancel by calling confirm with Cancel outcome', async () => {
|
||||
const { result } = renderHook(() => useToolActions(), { wrapper });
|
||||
|
||||
@@ -170,13 +135,11 @@ describe('ToolActionsContext', () => {
|
||||
'/f.txt',
|
||||
'accepted',
|
||||
);
|
||||
const editDetails = mockToolCalls[2]
|
||||
.confirmationDetails as ToolCallConfirmationDetails;
|
||||
if (editDetails && 'onConfirm' in editDetails) {
|
||||
expect(editDetails.onConfirm).toHaveBeenCalled();
|
||||
} else {
|
||||
throw new Error('Expected onConfirm to be present');
|
||||
}
|
||||
expect(mockMessageBus.publish).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
correlationId: 'corr-edit',
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it('updates isDiffingEnabled when IdeClient status changes', async () => {
|
||||
|
||||
@@ -18,7 +18,6 @@ import {
|
||||
MessageBusType,
|
||||
type Config,
|
||||
type ToolConfirmationPayload,
|
||||
type ToolCallConfirmationDetails,
|
||||
debugLogger,
|
||||
} from '@google/gemini-cli-core';
|
||||
import type { IndividualToolCallDisplay } from '../types.js';
|
||||
@@ -113,8 +112,7 @@ export const ToolActionsProvider: React.FC<ToolActionsProviderProps> = (
|
||||
await ideClient?.resolveDiffFromCli(details.filePath, cliOutcome);
|
||||
}
|
||||
|
||||
// 2. Dispatch
|
||||
// PATH A: Event Bus (Modern)
|
||||
// 2. Dispatch via Event Bus
|
||||
if (tool.correlationId) {
|
||||
await config.getMessageBus().publish({
|
||||
type: MessageBusType.TOOL_CONFIRMATION_RESPONSE,
|
||||
@@ -127,20 +125,7 @@ export const ToolActionsProvider: React.FC<ToolActionsProviderProps> = (
|
||||
return;
|
||||
}
|
||||
|
||||
// PATH B: Legacy Callback (Adapter or Old Scheduler)
|
||||
if (
|
||||
details &&
|
||||
'onConfirm' in details &&
|
||||
typeof details.onConfirm === 'function'
|
||||
) {
|
||||
await (details as ToolCallConfirmationDetails).onConfirm(
|
||||
outcome,
|
||||
payload,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
debugLogger.warn(`ToolActions: No confirmation mechanism for ${callId}`);
|
||||
debugLogger.warn(`ToolActions: No correlationId for ${callId}`);
|
||||
},
|
||||
[config, ideClient, toolCalls, isDiffingEnabled],
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user