Skip to content
Merged
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
4 changes: 2 additions & 2 deletions src/commands/quota/show.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
33 changes: 33 additions & 0 deletions test/commands/quota/show.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, unknown>).isTTY;
}
}

expect(JSON.parse(output.join('\n'))).toMatchObject({ model_remains: [] });
});

it('uses account/query_balance for sk-api keys', async () => {
server = createMockServer({
routes: {
Expand Down
Loading