diff --git a/src/commands/quota/show.ts b/src/commands/quota/show.ts index 5a09684..8e14a9d 100644 --- a/src/commands/quota/show.ts +++ b/src/commands/quota/show.ts @@ -17,13 +17,13 @@ export default defineCommand({ 'mmx quota show', 'mmx quota show --output json', ], - async run(config: Config, flags: GlobalFlags) { + async run(config: Config, _flags: GlobalFlags) { if (config.dryRun) { console.log('Would fetch quota information.'); return; } - const format = detectOutputFormat(flags.output as string | undefined); + const format = detectOutputFormat(config.output); const credential = await resolveCredential(config); const endpoint = selectUsageEndpoint(config.baseUrl, credential); diff --git a/test/commands/quota/show.test.ts b/test/commands/quota/show.test.ts index 6a96ff7..6868464 100644 --- a/test/commands/quota/show.test.ts +++ b/test/commands/quota/show.test.ts @@ -62,6 +62,39 @@ describe('quota show command', () => { } }); + it('honors JSON output resolved from config without an output flag', async () => { + server = createMockServer({ + routes: { + '/v1/token_plan/remains': () => jsonResponse({ + model_remains: [], + base_resp: { status_code: 0, status_msg: 'ok' }, + }), + }, + }); + + const output: string[] = []; + const originalLog = console.log; + const ttyDescriptor = Object.getOwnPropertyDescriptor(process.stdout, 'isTTY'); + console.log = (message?: unknown) => { output.push(String(message ?? '')); }; + Object.defineProperty(process.stdout, 'isTTY', { value: true, configurable: true }); + + try { + await showCommand.execute( + { ...baseConfig, baseUrl: server.url, output: 'json' }, + { ...baseFlags, output: undefined }, + ); + } finally { + console.log = originalLog; + if (ttyDescriptor) { + Object.defineProperty(process.stdout, 'isTTY', ttyDescriptor); + } else { + delete (process.stdout as unknown as Record).isTTY; + } + } + + expect(JSON.parse(output.join('\n'))).toMatchObject({ model_remains: [] }); + }); + it('uses account/query_balance for sk-api keys', async () => { server = createMockServer({ routes: {