Structured JSON Output (#8119)

This commit is contained in:
Jerop Kipruto
2025-09-11 05:19:47 +09:00
committed by GitHub
parent db99fc70b6
commit 514767c88b
20 changed files with 1526 additions and 23 deletions
+49
View File
@@ -1972,6 +1972,55 @@ describe('loadCliConfig fileFiltering', () => {
);
});
describe('Output Format Configuration', () => {
const originalArgv = process.argv;
afterEach(() => {
process.argv = originalArgv;
vi.restoreAllMocks();
});
it('should default to text format when no setting or flag is provided', async () => {
process.argv = ['node', 'script.js'];
const argv = await parseArguments({} as Settings);
const config = await loadCliConfig(
{} as Settings,
[],
'test-session',
argv,
);
expect(config.getOutputFormat()).toBe(ServerConfig.OutputFormat.TEXT);
});
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 () => {
process.argv = ['node', 'script.js', '--output-format', 'json'];
const argv = await parseArguments({} as Settings);
const config = await loadCliConfig(
{} as Settings,
[],
'test-session',
argv,
);
expect(config.getOutputFormat()).toBe(ServerConfig.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);
});
});
describe('parseArguments with positional prompt', () => {
const originalArgv = process.argv;