fix(cliproxy): harden Claude OAuth quota window parsing

This commit is contained in:
Tam Nhu Tran committed 2026-04-14 23:09:18 -04:00
1 parent 9e880825e7
commit 050b41bb55
3 files changed
+32 -22

No files matched your search

@@ -253,7 +253,7 @@ describe('Quota Exhaustion Handlers', () => {
expect(result.reason).toContain('no alternatives');
});
it('should switch Claude accounts when fallback quota is unavailable but auth is valid', async () => {
it('should switch Claude accounts when fallback quota endpoint returns 404', async () => {
writeRegistry({
claude: {
default: 'exhausted@example.com',
@@ -294,16 +294,7 @@ describe('Quota Exhaustion Handlers', () => {
global.fetch = mock((_url: string, options?: RequestInit) => {
const authHeader = new Headers(options?.headers).get('Authorization') ?? '';
if (authHeader === 'Bearer fallback-token') {
return Promise.resolve(
new Response(
JSON.stringify({
error: {
message: 'OAuth authentication is currently not supported.',
},
}),
{ status: 401, headers: { 'Content-Type': 'application/json' } }
)
);
return Promise.resolve(new Response('', { status: 404 }));
}
return Promise.resolve(new Response('', { status: 500 }));
@@ -182,6 +182,20 @@ describe('Claude Quota Fetcher', () => {
expect(windows[1].rateLimitType).toBe('seven_day_sonnet');
expect(windows[1].remainingPercent).toBe(91);
});
it('parses future OAuth usage windows without hardcoded keys', () => {
const windows = buildClaudeQuotaWindows({
seven_day_haiku: {
utilization: 16,
resets_at: '2026-03-06T10:00:00Z',
},
});
expect(windows).toHaveLength(1);
expect(windows[0].rateLimitType).toBe('seven_day_haiku');
expect(windows[0].label).toBe('Seven Day Haiku');
expect(windows[0].remainingPercent).toBe(84);
});
});
describe('buildClaudeCoreUsageSummary', () => {