@@ -13,6 +13,7 @@ import {
1313 WriteFileTool ,
1414 DEFAULT_GEMINI_MODEL ,
1515 DEFAULT_GEMINI_MODEL_AUTO ,
16+ OutputFormat ,
1617} from '@google/gemini-cli-core' ;
1718import { loadCliConfig , parseArguments , type CliArgs } from './config.js' ;
1819import type { Settings } from './settings.js' ;
@@ -2095,52 +2096,54 @@ describe('loadCliConfig fileFiltering', () => {
20952096 ) ;
20962097} ) ;
20972098
2098- describe ( 'Output Format Configuration ' , ( ) => {
2099- const originalArgv = process . argv ;
2100-
2101- afterEach ( ( ) => {
2102- process . argv = originalArgv ;
2103- vi . restoreAllMocks ( ) ;
2099+ describe ( 'Output format ' , ( ) => {
2100+ it ( 'should default to TEXT' , async ( ) => {
2101+ process . argv = [ 'node' , 'script.js' ] ;
2102+ const argv = await parseArguments ( { } as Settings ) ;
2103+ const config = await loadCliConfig ( { } , [ ] , 'test-session' , argv ) ;
2104+ expect ( config . getOutputFormat ( ) ) . toBe ( OutputFormat . TEXT ) ;
21042105 } ) ;
21052106
2106- it ( 'should default to text format when no setting or flag is provided ' , async ( ) => {
2107+ it ( 'should use the format from settings ' , async ( ) => {
21072108 process . argv = [ 'node' , 'script.js' ] ;
21082109 const argv = await parseArguments ( { } as Settings ) ;
21092110 const config = await loadCliConfig (
2110- { } as Settings ,
2111+ { output : { format : OutputFormat . JSON } } ,
21112112 [ ] ,
21122113 'test-session' ,
21132114 argv ,
21142115 ) ;
2115- expect ( config . getOutputFormat ( ) ) . toBe ( ServerConfig . OutputFormat . TEXT ) ;
2116+ expect ( config . getOutputFormat ( ) ) . toBe ( OutputFormat . JSON ) ;
21162117 } ) ;
21172118
2118- it ( 'should use the format from settings when no flag is provided' , async ( ) => {
2119- process . argv = [ 'node' , 'script.js' ] ;
2120- const settings : Settings = { output : { format : 'json' } } ;
2121- const argv = await parseArguments ( settings ) ;
2122- const config = await loadCliConfig ( settings , [ ] , 'test-session' , argv ) ;
2123- expect ( config . getOutputFormat ( ) ) . toBe ( ServerConfig . OutputFormat . JSON ) ;
2124- } ) ;
2125-
2126- it ( 'should use the format from the flag when provided' , async ( ) => {
2119+ it ( 'should prioritize the format from argv' , async ( ) => {
21272120 process . argv = [ 'node' , 'script.js' , '--output-format' , 'json' ] ;
21282121 const argv = await parseArguments ( { } as Settings ) ;
21292122 const config = await loadCliConfig (
2130- { } as Settings ,
2123+ { output : { format : OutputFormat . JSON } } ,
21312124 [ ] ,
21322125 'test-session' ,
21332126 argv ,
21342127 ) ;
2135- expect ( config . getOutputFormat ( ) ) . toBe ( ServerConfig . OutputFormat . JSON ) ;
2128+ expect ( config . getOutputFormat ( ) ) . toBe ( OutputFormat . JSON ) ;
21362129 } ) ;
21372130
2138- it ( 'should prioritize the flag over the setting' , async ( ) => {
2139- process . argv = [ 'node' , 'script.js' , '--output-format' , 'text' ] ;
2140- const settings : Settings = { output : { format : 'json' } } ;
2141- const argv = await parseArguments ( settings ) ;
2142- const config = await loadCliConfig ( settings , [ ] , 'test-session' , argv ) ;
2143- expect ( config . getOutputFormat ( ) ) . toBe ( ServerConfig . OutputFormat . TEXT ) ;
2131+ it ( 'should error on invalid --output-format argument' , async ( ) => {
2132+ process . argv = [ 'node' , 'script.js' , '--output-format' , 'yaml' ] ;
2133+ const mockExit = vi . spyOn ( process , 'exit' ) . mockImplementation ( ( ) => {
2134+ throw new Error ( 'process.exit called' ) ;
2135+ } ) ;
2136+ const mockConsoleError = vi
2137+ . spyOn ( console , 'error' )
2138+ . mockImplementation ( ( ) => { } ) ;
2139+ await expect ( parseArguments ( { } as Settings ) ) . rejects . toThrow (
2140+ 'process.exit called' ,
2141+ ) ;
2142+ expect ( mockConsoleError ) . toHaveBeenCalledWith (
2143+ expect . stringContaining ( 'Invalid values:' ) ,
2144+ ) ;
2145+ mockExit . mockRestore ( ) ;
2146+ mockConsoleError . mockRestore ( ) ;
21442147 } ) ;
21452148} ) ;
21462149
0 commit comments