fix(ux) keyboard input hangs while waiting for keyboard input. (#10121)

This commit is contained in:
Jacob Richman
2025-10-16 20:38:06 -07:00
committed by GitHub
parent cd0f9fe22f
commit 406f0baaf2
6 changed files with 778 additions and 96 deletions
@@ -5,7 +5,7 @@
*/
import { renderWithProviders } from '../../test-utils/render.js';
import { waitFor } from '@testing-library/react';
import { waitFor, act } from '@testing-library/react';
import { vi } from 'vitest';
import { FolderTrustDialog } from './FolderTrustDialog.js';
import * as processUtils from '../../utils/processUtils.js';
@@ -50,7 +50,9 @@ describe('FolderTrustDialog', () => {
<FolderTrustDialog onSelect={onSelect} isRestarting={false} />,
);
stdin.write('\x1b'); // escape key
act(() => {
stdin.write('\u001b[27u'); // Press kitty escape key
});
await waitFor(() => {
expect(lastFrame()).toContain(
@@ -87,7 +89,9 @@ describe('FolderTrustDialog', () => {
<FolderTrustDialog onSelect={vi.fn()} isRestarting={false} />,
);
stdin.write('r');
act(() => {
stdin.write('r');
});
await waitFor(() => {
expect(mockedExit).not.toHaveBeenCalled();
@@ -1616,6 +1616,7 @@ describe('InputPrompt', () => {
const { stdin, unmount } = renderWithProviders(
<InputPrompt {...props} />,
{ kittyProtocolEnabled: true },
);
await vi.runAllTimersAsync();
@@ -1661,6 +1662,7 @@ describe('InputPrompt', () => {
const { stdin, unmount } = renderWithProviders(
<InputPrompt {...props} />,
{ kittyProtocolEnabled: false },
);
await wait();
@@ -1682,6 +1684,7 @@ describe('InputPrompt', () => {
const { stdin, unmount } = renderWithProviders(
<InputPrompt {...props} />,
{ kittyProtocolEnabled: false },
);
stdin.write('\x1B');
@@ -1703,6 +1706,7 @@ describe('InputPrompt', () => {
const { stdin, unmount } = renderWithProviders(
<InputPrompt {...props} />,
{ kittyProtocolEnabled: false },
);
await wait();
@@ -1722,6 +1726,7 @@ describe('InputPrompt', () => {
const { stdin, unmount } = renderWithProviders(
<InputPrompt {...props} />,
{ kittyProtocolEnabled: false },
);
await wait();
@@ -1733,23 +1738,27 @@ describe('InputPrompt', () => {
});
it('should not call onEscapePromptChange when not provided', async () => {
vi.useFakeTimers();
props.onEscapePromptChange = undefined;
props.buffer.setText('some text');
const { stdin, unmount } = renderWithProviders(
<InputPrompt {...props} />,
{ kittyProtocolEnabled: false },
);
await wait();
await vi.runAllTimersAsync();
stdin.write('\x1B');
await wait();
await vi.runAllTimersAsync();
vi.useRealTimers();
unmount();
});
it('should not interfere with existing keyboard shortcuts', async () => {
const { stdin, unmount } = renderWithProviders(
<InputPrompt {...props} />,
{ kittyProtocolEnabled: false },
);
await wait();
@@ -1821,6 +1830,7 @@ describe('InputPrompt', () => {
stdin.write('\x12');
await wait();
stdin.write('\x1B');
stdin.write('\u001b[27u'); // Press kitty escape key
await waitFor(() => {
expect(stdout.lastFrame()).not.toContain('(r:)');
@@ -1922,7 +1932,7 @@ describe('InputPrompt', () => {
stdin.write('\x12');
await wait();
expect(stdout.lastFrame()).toContain('(r:)');
stdin.write('\x1B');
stdin.write('\u001b[27u'); // Press kitty escape key
await waitFor(() => {
expect(stdout.lastFrame()).not.toContain('(r:)');
@@ -141,7 +141,7 @@ describe('PermissionsModifyTrustDialog', () => {
await waitFor(() => expect(lastFrame()).not.toContain('Loading...'));
act(() => {
stdin.write('\x1b'); // escape key
stdin.write('\u001b[27u'); // Kitty escape key
});
await waitFor(() => {
@@ -201,7 +201,7 @@ describe('PermissionsModifyTrustDialog', () => {
await waitFor(() => expect(lastFrame()).not.toContain('Loading...'));
act(() => stdin.write('\x1b')); // Press escape
act(() => stdin.write('\u001b[27u')); // Press kitty escape key
await waitFor(() => {
expect(mockCommitTrustLevelChange).not.toHaveBeenCalled();