fixing error (#8676)

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
This commit is contained in:
matt korwel
2025-09-18 08:41:12 -07:00
committed by GitHub
parent e0fcbc39f6
commit 0534ca74d4

View File

@@ -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();
});
});