Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/commands/auth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -986,6 +986,27 @@ describe('createAuthCommand wiring', () => {
expect(fetchImpl).toHaveBeenCalledTimes(1);
});

it('status rejects unsupported global --output modes', async () => {
const { deps } = makeCapture();
const auth = createAuthCommand({ ...deps });
const parent = new (await import('commander')).Command('testsprite');
parent.option('--output <mode>', 'output', 'text');
parent.option('--profile <name>', 'profile', 'default');
parent.option('--endpoint-url <url>');
parent.option('--debug', 'debug', false);
parent.option('--verbose', 'verbose', false);
parent.option('--dry-run', 'dry-run', false);
parent.addCommand(auth);

await expect(
parent.parseAsync(['node', 'ts', 'auth', 'status', '--output', 'yaml', '--dry-run']),
).rejects.toMatchObject({
code: 'VALIDATION_ERROR',
exitCode: 5,
details: { field: 'output' },
});
});

it('logout removes the profile', async () => {
writeProfile('default', { apiKey: 'sk' }, { path: credentialsPath });
const { deps } = makeCapture();
Expand Down
8 changes: 6 additions & 2 deletions src/commands/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
type CommonOptions as FactoryCommonOptions,
} from '../lib/client-factory.js';
import type { ErrorCode } from '../lib/errors.js';
import { ApiError, CLIError } from '../lib/errors.js';
import { ApiError, CLIError, localValidationError } from '../lib/errors.js';
import { facadeBaseUrl } from '../lib/facade.js';
import type { FetchImpl } from '../lib/http.js';
import { HttpClient } from '../lib/http.js';
Expand Down Expand Up @@ -316,9 +316,13 @@ function resolveCommonOptions(command: Command): CommonOptions {
const globals = command.optsWithGlobals() as Partial<CommonOptions> & {
requestTimeout?: string;
};
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,
Expand Down