Merge branch 'openchamber:main' into github-usage-rework

This commit is contained in:
Jakub Syty
2026-08-27 10:06:53 +02:00
committed by GitHub
80 changed files with 1474 additions and 815 deletions
@@ -17,7 +17,6 @@ const AUTH = JSON.stringify({
crof: { key: 'test-token' },
neuralwatt: { key: 'test-token' },
'opencode-go': { key: 'test-token' },
'command-code': { type: 'oauth', access: 'test-token' },
'zai-coding-plan': { key: 'test-token' },
deepseek: { key: 'test-token' },
'github-copilot': { access: 'test-token' },
@@ -105,57 +104,6 @@ describe('OpenCode Go quota provider (VS Code parity)', () => {
});
});
describe('Command Code quota provider (VS Code parity)', () => {
test('uses the OAuth access token and resolves server-backed limits', async () => {
const requests: Array<{ url: string; init?: RequestInit }> = [];
globalThis.fetch = (async (url: string, init?: RequestInit) => {
requests.push({ url, init });
return mockResponse(url.endsWith('/alpha/whoami')
? { org: { id: 'org/a' } }
: { credits: { monthlyCredits: 120 }, windowLimits: { fiveHour: { used: 25, cap: 100, resetAt: 1_776_000_000 } } });
}) as typeof fetch;
const result = await fetchQuotaForProvider('command-code');
assert.equal(result.ok, true);
assert.deepEqual(requests.map(({ url }) => url), [
'https://api.commandcode.ai/alpha/whoami',
'https://api.commandcode.ai/alpha/billing/credits?orgId=org%2Fa',
]);
assert.equal((requests[0].init?.headers as Record<string, string>).Authorization, 'Bearer test-token');
assert.equal(result.usage!.windows['5h']!.usedPercent, 25);
assert.equal(result.usage!.windows.monthly_credits!.valueLabel, '120');
});
test('omits orgId for personal accounts', async () => {
const urls: string[] = [];
globalThis.fetch = (async (url: string) => {
urls.push(url);
return mockResponse(url.endsWith('/alpha/whoami')
? { user: { id: 'user-1' }, org: null }
: { credits: { monthlyCredits: 120 } });
}) as typeof fetch;
const result = await fetchQuotaForProvider('command-code');
assert.equal(result.ok, true);
assert.deepEqual(urls, [
'https://api.commandcode.ai/alpha/whoami',
'https://api.commandcode.ai/alpha/billing/credits',
]);
});
test('formats fractional credit values for display', async () => {
globalThis.fetch = (async (url: string) => mockResponse(url.endsWith('/alpha/whoami')
? { org: null }
: { credits: { monthlyCredits: 69.7947070034 }, windowLimits: { fiveHour: { used: 0.2052929966, cap: 14 } } })) as typeof fetch;
const result = await fetchQuotaForProvider('command-code');
assert.equal(result.usage!.windows.monthly_credits!.valueLabel, '69.79');
assert.equal(result.usage!.windows['5h']!.valueLabel, '0.21 / 14');
});
});
describe('Crof quota provider (VS Code parity)', () => {
test('reports credits balance as valueLabel with null percent', async () => {