mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-20 08:47:44 +00:00
fix(cli): make Ctrl+C UI test less flaky (#7166)
This commit is contained in:
@@ -1576,9 +1576,28 @@ 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(
|
||||||
|
(
|
||||||
|
_client,
|
||||||
|
_history,
|
||||||
|
_addItem,
|
||||||
|
_config,
|
||||||
|
_onDebugMessage,
|
||||||
|
_handleSlashCommand,
|
||||||
|
_shellModeActive,
|
||||||
|
_getPreferredEditor,
|
||||||
|
_onAuthError,
|
||||||
|
_performMemoryRefresh,
|
||||||
|
_modelSwitchedFromQuotaError,
|
||||||
|
_setModelSwitchedFromQuotaError,
|
||||||
|
_onEditorClose,
|
||||||
|
onCancelSubmit, // Capture the cancel callback from App.tsx
|
||||||
|
) => {
|
||||||
|
onCancelSubmitCallback = onCancelSubmit;
|
||||||
|
return {
|
||||||
streamingState: StreamingState.Responding,
|
streamingState: StreamingState.Responding,
|
||||||
submitQuery: vi.fn(),
|
submitQuery: vi.fn(),
|
||||||
initError: null,
|
initError: null,
|
||||||
@@ -1596,8 +1615,13 @@ describe('App UI', () => {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
thought: null,
|
thought: null,
|
||||||
cancelOngoingRequest: 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.
|
||||||
|
await waitFor(() => {
|
||||||
expect(lastFrame()).not.toContain('some text');
|
expect(lastFrame()).not.toContain('some text');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user