From 0534ca74d4e67b00ed51e9f8bf568efc3ecaf834 Mon Sep 17 00:00:00 2001 From: matt korwel Date: Thu, 18 Sep 2025 08:41:12 -0700 Subject: [PATCH] fixing error (#8676) Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- packages/cli/src/config/config.test.ts | 55 ++++++++++++++------------ 1 file changed, 29 insertions(+), 26 deletions(-) diff --git a/packages/cli/src/config/config.test.ts b/packages/cli/src/config/config.test.ts index 4de0c8a5c4..fec2dacdb3 100644 --- a/packages/cli/src/config/config.test.ts +++ b/packages/cli/src/config/config.test.ts @@ -13,6 +13,7 @@ import { WriteFileTool, DEFAULT_GEMINI_MODEL, DEFAULT_GEMINI_MODEL_AUTO, + OutputFormat, } from '@google/gemini-cli-core'; import { loadCliConfig, parseArguments, type CliArgs } from './config.js'; import type { Settings } from './settings.js'; @@ -2095,52 +2096,54 @@ describe('loadCliConfig fileFiltering', () => { ); }); -describe('Output Format Configuration', () => { - const originalArgv = process.argv; - - afterEach(() => { - process.argv = originalArgv; - vi.restoreAllMocks(); +describe('Output format', () => { + it('should default to TEXT', async () => { + process.argv = ['node', 'script.js']; + const argv = await parseArguments({} as Settings); + const config = await loadCliConfig({}, [], 'test-session', argv); + expect(config.getOutputFormat()).toBe(OutputFormat.TEXT); }); - it('should default to text format when no setting or flag is provided', async () => { + it('should use the format from settings', async () => { process.argv = ['node', 'script.js']; const argv = await parseArguments({} as Settings); const config = await loadCliConfig( - {} as Settings, + { output: { format: OutputFormat.JSON } }, [], 'test-session', argv, ); - expect(config.getOutputFormat()).toBe(ServerConfig.OutputFormat.TEXT); + expect(config.getOutputFormat()).toBe(OutputFormat.JSON); }); - it('should use the format from settings when no flag is provided', async () => { - process.argv = ['node', 'script.js']; - const settings: Settings = { output: { format: 'json' } }; - const argv = await parseArguments(settings); - const config = await loadCliConfig(settings, [], 'test-session', argv); - expect(config.getOutputFormat()).toBe(ServerConfig.OutputFormat.JSON); - }); - - it('should use the format from the flag when provided', async () => { + it('should prioritize the format from argv', async () => { process.argv = ['node', 'script.js', '--output-format', 'json']; const argv = await parseArguments({} as Settings); const config = await loadCliConfig( - {} as Settings, + { output: { format: OutputFormat.JSON } }, [], 'test-session', argv, ); - expect(config.getOutputFormat()).toBe(ServerConfig.OutputFormat.JSON); + expect(config.getOutputFormat()).toBe(OutputFormat.JSON); }); - it('should prioritize the flag over the setting', async () => { - process.argv = ['node', 'script.js', '--output-format', 'text']; - const settings: Settings = { output: { format: 'json' } }; - const argv = await parseArguments(settings); - const config = await loadCliConfig(settings, [], 'test-session', argv); - expect(config.getOutputFormat()).toBe(ServerConfig.OutputFormat.TEXT); + it('should error on invalid --output-format argument', async () => { + process.argv = ['node', 'script.js', '--output-format', 'yaml']; + const mockExit = vi.spyOn(process, 'exit').mockImplementation(() => { + throw new Error('process.exit called'); + }); + const mockConsoleError = vi + .spyOn(console, 'error') + .mockImplementation(() => {}); + await expect(parseArguments({} as Settings)).rejects.toThrow( + 'process.exit called', + ); + expect(mockConsoleError).toHaveBeenCalledWith( + expect.stringContaining('Invalid values:'), + ); + mockExit.mockRestore(); + mockConsoleError.mockRestore(); }); });