From 37edd1d4dfb538475535d26bfc728da8cd2f69ef Mon Sep 17 00:00:00 2001 From: Coco Sheng Date: Mon, 4 May 2026 13:48:24 -0400 Subject: [PATCH] fix(cli): allow early stdout when config is undefined (#26453) --- packages/cli/src/gemini.tsx | 2 +- packages/cli/src/output-redirection.test.ts | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/cli/src/gemini.tsx b/packages/cli/src/gemini.tsx index 7bd3f3955b..892ee9862a 100644 --- a/packages/cli/src/gemini.tsx +++ b/packages/cli/src/gemini.tsx @@ -830,7 +830,7 @@ export function initializeOutputListenersAndFlush(config?: Config) { } const outputFormat = config?.getOutputFormat(); - const forceToStderr = outputFormat === 'json' || config === undefined; + const forceToStderr = outputFormat === 'json'; coreEvents.drainBacklogs( (event: K, args: CoreEvents[K]) => { diff --git a/packages/cli/src/output-redirection.test.ts b/packages/cli/src/output-redirection.test.ts index 2dc935b330..8baa1127f5 100644 --- a/packages/cli/src/output-redirection.test.ts +++ b/packages/cli/src/output-redirection.test.ts @@ -69,16 +69,16 @@ describe('Output Redirection', () => { expect(writeToStderr).not.toHaveBeenCalled(); }); - it('should force stdout to stderr when config is undefined (early failure)', () => { + it('should NOT force stdout to stderr when config is undefined (early init/version)', () => { // Simulate buffered output during early init coreEvents.emitOutput(false, 'early init message'); // Initialize with undefined config initializeOutputListenersAndFlush(undefined); - // Verify it was forced to stderr - expect(writeToStderr).toHaveBeenCalledWith('early init message', undefined); - expect(writeToStdout).not.toHaveBeenCalled(); + // Verify it went to stdout (default behavior) + expect(writeToStdout).toHaveBeenCalledWith('early init message', undefined); + expect(writeToStderr).not.toHaveBeenCalled(); }); it('should attach ConsoleLog and UserFeedback listeners even if Output already has one', () => {