Repository navigation
fix(cli): default to virtualized terminal history #5738
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 24 commits
8f5eb98
738cac3
b35fef7
604e733
cc5d436
22f100f
769e196
8632a62
975d216
874fb6c
50187da
81daecf
e1cc1c4
ddc0c31
6953ae4
c4485e2
999a609
9e0919b
f4cdecc
cc24b0a
0c9df2b
a22120a
ad92da5
cef51a6
66a1499
2a097de
d18f38a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,7 @@ import { | |
| validateDnsResolutionOrder, | ||
| } from './gemini.js'; | ||
| import { startInteractiveUI } from './ui/startInteractiveUI.js'; | ||
| import { clearCiEnv } from './test-utils/ci-env.js'; | ||
| import type { CliArgs } from './config/config.js'; | ||
| import { type LoadedSettings } from './config/settings.js'; | ||
| import { appEvents, AppEvent } from './utils/events.js'; | ||
|
|
@@ -1917,8 +1918,41 @@ describe('startInteractiveUI', () => { | |
| render: vi.fn().mockReturnValue({ unmount: vi.fn() }), | ||
| })); | ||
|
|
||
| let initialExitListeners: NodeJS.ExitListener[] = []; | ||
| let originalStdoutIsTTY: boolean | undefined; | ||
| let restoreCiEnv = () => {}; | ||
|
|
||
| beforeEach(() => { | ||
| vi.clearAllMocks(); | ||
| restoreCiEnv = clearCiEnv(); | ||
| vi.stubEnv('TERM', 'xterm-256color'); | ||
| originalStdoutIsTTY = process.stdout.isTTY; | ||
| Object.defineProperty(process.stdout, 'isTTY', { | ||
| value: true, | ||
| configurable: true, | ||
| }); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in 975d216. The interactive TTY-focused test suites now clear and restore CI-related env keys ( |
||
| initialExitListeners = process.listeners('exit') as NodeJS.ExitListener[]; | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| if (originalStdoutIsTTY === undefined) { | ||
| delete (process.stdout as { isTTY?: unknown }).isTTY; | ||
| } else { | ||
| Object.defineProperty(process.stdout, 'isTTY', { | ||
| value: originalStdoutIsTTY, | ||
| configurable: true, | ||
| }); | ||
| } | ||
| vi.unstubAllEnvs(); | ||
| restoreCiEnv(); | ||
| const currentExitListeners = process.listeners( | ||
| 'exit', | ||
| ) as NodeJS.ExitListener[]; | ||
| for (const listener of currentExitListeners) { | ||
| if (!initialExitListeners.includes(listener)) { | ||
| process.removeListener('exit', listener); | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| it('should render the UI with proper React context and exitOnCtrlC disabled', async () => { | ||
|
|
@@ -1948,13 +1982,191 @@ describe('startInteractiveUI', () => { | |
| expect(options).toEqual({ | ||
| exitOnCtrlC: false, | ||
| isScreenReaderEnabled: false, | ||
| alternateScreen: false, | ||
| alternateScreen: true, | ||
| }); | ||
|
|
||
| // Verify React element structure is valid (but don't deep dive into JSX internals) | ||
| expect(reactElement).toBeDefined(); | ||
| }); | ||
|
|
||
| it('should not use alternate screen when VP mode is explicitly disabled', async () => { | ||
| const { render } = await import('ink'); | ||
| const renderSpy = vi.mocked(render); | ||
| const legacySettings = { | ||
| ...mockSettings, | ||
| merged: { | ||
| ...mockSettings.merged, | ||
| ui: { | ||
| ...mockSettings.merged.ui, | ||
| useTerminalBuffer: false, | ||
| }, | ||
| }, | ||
| } as LoadedSettings; | ||
|
|
||
| const mockInitializationResult = { | ||
| authError: null, | ||
| themeError: null, | ||
| shouldOpenAuthDialog: false, | ||
| geminiMdFileCount: 0, | ||
| }; | ||
|
|
||
| await startInteractiveUI( | ||
| mockConfig, | ||
| legacySettings, | ||
| mockStartupWarnings, | ||
| mockWorkspaceRoot, | ||
| mockInitializationResult, | ||
| ); | ||
|
|
||
| const [, options] = renderSpy.mock.calls[0]; | ||
| expect(options).toMatchObject({ alternateScreen: false }); | ||
| }); | ||
|
|
||
| it('should not use alternate screen when stdout is not interactive', async () => { | ||
| Object.defineProperty(process.stdout, 'isTTY', { | ||
| value: false, | ||
| configurable: true, | ||
| }); | ||
| const { render } = await import('ink'); | ||
| const renderSpy = vi.mocked(render); | ||
|
|
||
| const mockInitializationResult = { | ||
| authError: null, | ||
| themeError: null, | ||
| shouldOpenAuthDialog: false, | ||
| geminiMdFileCount: 0, | ||
| }; | ||
|
|
||
| await startInteractiveUI( | ||
| mockConfig, | ||
| mockSettings, | ||
| mockStartupWarnings, | ||
| mockWorkspaceRoot, | ||
| mockInitializationResult, | ||
| ); | ||
|
|
||
| const [, options] = renderSpy.mock.calls[0]; | ||
| expect(options).toMatchObject({ alternateScreen: false }); | ||
| }); | ||
|
|
||
| it('should not use alternate screen when TERM is dumb', async () => { | ||
| vi.stubEnv('TERM', 'dumb'); | ||
| const { render } = await import('ink'); | ||
| const renderSpy = vi.mocked(render); | ||
|
|
||
| const mockInitializationResult = { | ||
| authError: null, | ||
| themeError: null, | ||
| shouldOpenAuthDialog: false, | ||
| geminiMdFileCount: 0, | ||
| }; | ||
|
|
||
| await startInteractiveUI( | ||
| mockConfig, | ||
| mockSettings, | ||
| mockStartupWarnings, | ||
| mockWorkspaceRoot, | ||
| mockInitializationResult, | ||
| ); | ||
|
|
||
| const [, options] = renderSpy.mock.calls[0]; | ||
| expect(options).toMatchObject({ alternateScreen: false }); | ||
| }); | ||
|
|
||
| it('should not use alternate screen in CI with a TTY stdout', async () => { | ||
| vi.stubEnv('CI', 'true'); | ||
| const { render } = await import('ink'); | ||
| const renderSpy = vi.mocked(render); | ||
|
|
||
| const mockInitializationResult = { | ||
| authError: null, | ||
| themeError: null, | ||
| shouldOpenAuthDialog: false, | ||
| geminiMdFileCount: 0, | ||
| }; | ||
|
|
||
| await startInteractiveUI( | ||
| mockConfig, | ||
| mockSettings, | ||
| mockStartupWarnings, | ||
| mockWorkspaceRoot, | ||
| mockInitializationResult, | ||
| ); | ||
|
|
||
| const [, options] = renderSpy.mock.calls[0]; | ||
| expect(options).toMatchObject({ alternateScreen: false }); | ||
| }); | ||
|
|
||
| it('should not use alternate screen in screen reader mode when VP mode is unset', async () => { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Suggestion] Test gap: the screen-reader guard is tested when it('should not use alternate screen in screen reader mode even when VP mode is explicitly enabled', async () => {
// useTerminalBuffer: true, getScreenReader: () => true
// expect alternateScreen: false
});— qwen3.7-max via Qwen Code /review
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Covered in 8f5eb98. Added the explicit useTerminalBuffer: true + screen-reader case for startInteractiveUI, asserting alternateScreen remains false. |
||
| const { render } = await import('ink'); | ||
| const renderSpy = vi.mocked(render); | ||
| const screenReaderConfig = { | ||
| ...mockConfig, | ||
| getScreenReader: () => true, | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added in a22120a. startInteractiveUI now has a real-process-env integration test with stdout.isTTY=true and CI=true, asserting alternateScreen=false. I also corrected teardown ordering so vi.stubEnv values are removed before the original CI environment snapshot is restored, preventing cross-test env leakage on GitHub Actions. |
||
| } as Config; | ||
|
|
||
| const mockInitializationResult = { | ||
| authError: null, | ||
| themeError: null, | ||
| shouldOpenAuthDialog: false, | ||
| geminiMdFileCount: 0, | ||
| }; | ||
|
|
||
| await startInteractiveUI( | ||
| screenReaderConfig, | ||
| mockSettings, | ||
| mockStartupWarnings, | ||
| mockWorkspaceRoot, | ||
| mockInitializationResult, | ||
| ); | ||
|
|
||
| const [, options] = renderSpy.mock.calls[0]; | ||
| expect(options).toMatchObject({ | ||
| isScreenReaderEnabled: true, | ||
| alternateScreen: false, | ||
| }); | ||
| }); | ||
|
|
||
| it('should not use alternate screen in screen reader mode even when VP mode is explicitly enabled', async () => { | ||
| const { render } = await import('ink'); | ||
| const renderSpy = vi.mocked(render); | ||
| const screenReaderConfig = { | ||
| ...mockConfig, | ||
| getScreenReader: () => true, | ||
| } as Config; | ||
| const vpSettings = { | ||
| ...mockSettings, | ||
| merged: { | ||
| ...mockSettings.merged, | ||
| ui: { | ||
| ...mockSettings.merged.ui, | ||
| useTerminalBuffer: true, | ||
| }, | ||
| }, | ||
| } as LoadedSettings; | ||
|
|
||
| const mockInitializationResult = { | ||
| authError: null, | ||
| themeError: null, | ||
| shouldOpenAuthDialog: false, | ||
| geminiMdFileCount: 0, | ||
| }; | ||
|
|
||
| await startInteractiveUI( | ||
| screenReaderConfig, | ||
| vpSettings, | ||
| mockStartupWarnings, | ||
| mockWorkspaceRoot, | ||
| mockInitializationResult, | ||
| ); | ||
|
|
||
| const [, options] = renderSpy.mock.calls[0]; | ||
| expect(options).toMatchObject({ | ||
| isScreenReaderEnabled: true, | ||
| alternateScreen: false, | ||
| }); | ||
| }); | ||
|
|
||
| it('should perform all startup tasks in correct order', async () => { | ||
| const { getCliVersion } = await import('./utils/version.js'); | ||
| const { registerCleanup } = await import('./utils/cleanup.js'); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Suggestion] This default flip leaves
docs/design/ctrl-o-detail-expand/design.mdinconsistent with the shipped architecture: its current-state sections still call native scrollback/<Static>the default and point to the old rawgemini.tsxsettings gate. Update those passages to describe VP/alternate-screen as the default interactive path, the explicit opt-out/screen-reader/non-interactive exceptions, and the startup decision instartInteractiveUI.tsx.— Codex $qreview via Qwen Code /review
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 0c9df2b. The Ctrl+O design now describes VP/root alternate-screen as the default interactive path, the explicit opt-out, screen-reader, CI, non-TTY, and TERM=dumb fallbacks, and the single startup decision shared by startInteractiveUI and AppContainer. The transcript enter/exit sections and implementation references were updated to match the current architecture.