fix(cli): make Ctrl+C UI test less flaky (#7166)

This commit is contained in:
David East
2025-08-26 20:06:02 -04:00
committed by GitHub
parent 1baa74ebbf
commit 2df3480cba

View File

@@ -1576,28 +1576,52 @@ describe('App UI', () => {
describe('Ctrl+C behavior', () => { describe('Ctrl+C behavior', () => {
it('should call cancel but only clear the prompt when a tool is executing', async () => { it('should call cancel but only clear the prompt when a tool is executing', async () => {
const mockCancel = vi.fn(); const mockCancel = vi.fn();
let onCancelSubmitCallback = () => {};
// Simulate a tool in the "Executing" state. // Simulate a tool in the "Executing" state.
vi.mocked(useGeminiStream).mockReturnValue({ vi.mocked(useGeminiStream).mockImplementation(
streamingState: StreamingState.Responding, (
submitQuery: vi.fn(), _client,
initError: null, _history,
pendingHistoryItems: [ _addItem,
{ _config,
type: 'tool_group', _onDebugMessage,
tools: [ _handleSlashCommand,
_shellModeActive,
_getPreferredEditor,
_onAuthError,
_performMemoryRefresh,
_modelSwitchedFromQuotaError,
_setModelSwitchedFromQuotaError,
_onEditorClose,
onCancelSubmit, // Capture the cancel callback from App.tsx
) => {
onCancelSubmitCallback = onCancelSubmit;
return {
streamingState: StreamingState.Responding,
submitQuery: vi.fn(),
initError: null,
pendingHistoryItems: [
{ {
name: 'test_tool', type: 'tool_group',
status: 'Executing', tools: [
result: '', {
args: {}, name: 'test_tool',
status: 'Executing',
result: '',
args: {},
},
],
}, },
], ],
}, thought: null,
], cancelOngoingRequest: () => {
thought: null, mockCancel();
cancelOngoingRequest: mockCancel, onCancelSubmitCallback(); // <--- This is the key change
}); },
};
},
);
const { stdin, lastFrame, unmount } = renderWithProviders( const { stdin, lastFrame, unmount } = renderWithProviders(
<App <App
@@ -1624,7 +1648,9 @@ describe('App UI', () => {
// The prompt should now be empty as a result of the cancellation handler's logic. // The prompt should now be empty as a result of the cancellation handler's logic.
// We can't directly test the buffer's state, but we can see the rendered output. // We can't directly test the buffer's state, but we can see the rendered output.
expect(lastFrame()).not.toContain('some text'); await waitFor(() => {
expect(lastFrame()).not.toContain('some text');
});
}); });
}); });
}); });