From 2313711896894f3d22d23ec0ae5ee10348792072 Mon Sep 17 00:00:00 2001 From: JerryNee Date: Sat, 27 Jun 2026 22:30:10 -0500 Subject: [PATCH] fix(agent): reject invalid output modes --- src/commands/agent.test.ts | 22 ++++++++++++++++++++++ src/commands/agent.ts | 6 +++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/commands/agent.test.ts b/src/commands/agent.test.ts index bb558f3..5699f93 100644 --- a/src/commands/agent.test.ts +++ b/src/commands/agent.test.ts @@ -854,6 +854,28 @@ describe('createAgentCommand wiring', () => { expect(out).toContain('claude'); expect(out).toContain('antigravity'); }); + + it('agent list rejects unsupported global --output modes', async () => { + const { deps } = makeCapture(); + + const command = createAgentCommand({ cwd: CWD, ...deps }); + const parent = new (await import('commander')).Command('testsprite'); + parent.option('--output ', 'output', 'text'); + parent.option('--profile ', 'profile', 'default'); + parent.option('--endpoint-url '); + parent.option('--debug', 'debug', false); + parent.option('--verbose', 'verbose', false); + parent.option('--dry-run', 'dry-run', false); + parent.addCommand(command); + + await expect( + parent.parseAsync(['node', 'ts', 'agent', 'list', '--output', 'yaml']), + ).rejects.toMatchObject({ + code: 'VALIDATION_ERROR', + exitCode: 5, + details: { field: 'output' }, + }); + }); }); // --------------------------------------------------------------------------- diff --git a/src/commands/agent.ts b/src/commands/agent.ts index c27e2b8..bda86f1 100644 --- a/src/commands/agent.ts +++ b/src/commands/agent.ts @@ -755,9 +755,13 @@ export function createAgentCommand(deps: AgentDeps = {}): Command { function resolveCommonOptions(command: Command): CommonOptions { const globals = command.optsWithGlobals() as Partial; + const rawOutput = globals.output; + if (rawOutput !== undefined && rawOutput !== 'json' && rawOutput !== 'text') { + throw localValidationError('output', 'must be one of: json, text', ['json', 'text']); + } return { profile: globals.profile ?? 'default', - output: globals.output ?? 'text', + output: (globals.output as OutputMode | undefined) ?? 'text', endpointUrl: globals.endpointUrl, debug: globals.debug ?? false, verbose: globals.verbose ?? false,