diff --git a/packages/cli/src/ui/components/FolderTrustDialog.test.tsx b/packages/cli/src/ui/components/FolderTrustDialog.test.tsx index 27405f0181..2f09b0ecd6 100644 --- a/packages/cli/src/ui/components/FolderTrustDialog.test.tsx +++ b/packages/cli/src/ui/components/FolderTrustDialog.test.tsx @@ -7,7 +7,7 @@ import { renderWithProviders } from '../../test-utils/render.js'; import { waitFor } from '@testing-library/react'; import { vi } from 'vitest'; -import { FolderTrustDialog, FolderTrustChoice } from './FolderTrustDialog.js'; +import { FolderTrustDialog } from './FolderTrustDialog.js'; import * as processUtils from '../../utils/processUtils.js'; vi.mock('../../utils/processUtils.js', () => ({ @@ -44,30 +44,23 @@ describe('FolderTrustDialog', () => { ); }); - it('should call onSelect with DO_NOT_TRUST when escape is pressed and not restarting', async () => { + it('should display exit message and call process.exit and not call onSelect when escape is pressed', async () => { const onSelect = vi.fn(); - const { stdin } = renderWithProviders( + const { lastFrame, stdin } = renderWithProviders( , ); stdin.write('\x1b'); // escape key await waitFor(() => { - expect(onSelect).toHaveBeenCalledWith(FolderTrustChoice.DO_NOT_TRUST); + expect(lastFrame()).toContain( + 'A folder trust level must be selected to continue. Exiting since escape was pressed.', + ); }); - }); - - it('should not call onSelect when escape is pressed and is restarting', async () => { - const onSelect = vi.fn(); - const { stdin } = renderWithProviders( - , - ); - - stdin.write('\x1b'); // escape key - await waitFor(() => { - expect(onSelect).not.toHaveBeenCalled(); + expect(mockedExit).toHaveBeenCalledWith(1); }); + expect(onSelect).not.toHaveBeenCalled(); }); it('should display restart message when isRestarting is true', () => { @@ -84,7 +77,7 @@ describe('FolderTrustDialog', () => { renderWithProviders( , ); - await vi.advanceTimersByTimeAsync(1000); + await vi.advanceTimersByTimeAsync(250); expect(relaunchApp).toHaveBeenCalled(); vi.useRealTimers(); }); diff --git a/packages/cli/src/ui/components/FolderTrustDialog.tsx b/packages/cli/src/ui/components/FolderTrustDialog.tsx index 3292b22751..197f48548f 100644 --- a/packages/cli/src/ui/components/FolderTrustDialog.tsx +++ b/packages/cli/src/ui/components/FolderTrustDialog.tsx @@ -6,7 +6,7 @@ import { Box, Text } from 'ink'; import type React from 'react'; -import { useEffect } from 'react'; +import { useEffect, useState } from 'react'; import { theme } from '../semantic-colors.js'; import type { RadioSelectItem } from './shared/RadioButtonSelect.js'; import { RadioButtonSelect } from './shared/RadioButtonSelect.js'; @@ -30,6 +30,7 @@ export const FolderTrustDialog: React.FC = ({ onSelect, isRestarting, }) => { + const [exiting, setExiting] = useState(false); useEffect(() => { const doRelaunch = async () => { if (isRestarting) { @@ -44,7 +45,10 @@ export const FolderTrustDialog: React.FC = ({ useKeypress( (key) => { if (key.name === 'escape') { - onSelect(FolderTrustChoice.DO_NOT_TRUST); + setExiting(true); + setTimeout(() => { + process.exit(1); + }, 100); } }, { isActive: !isRestarting }, @@ -65,9 +69,9 @@ export const FolderTrustDialog: React.FC = ({ key: `Trust parent folder (${parentFolder})`, }, { - label: "Don't trust (esc)", + label: "Don't trust", value: FolderTrustChoice.DO_NOT_TRUST, - key: "Don't trust (esc)", + key: "Don't trust", }, ]; @@ -105,6 +109,14 @@ export const FolderTrustDialog: React.FC = ({ )} + {exiting && ( + + + A folder trust level must be selected to continue. Exiting since + escape was pressed. + + + )} ); };