fix(cliproxy): use explicit utilization unit per Claude payload form

Anthropic OAuth usage returns utilization as a percent (0-100) while the
older policy-limits restrictions payload returns a 0-1 ratio. The shared
heuristic "value <= 1 means ratio" misinterpreted percent values like
1.0, rendering 1% Sonnet usage as 100% used. Pass the unit explicitly
from each payload branch so the same boundary value is interpreted
correctly in either format.
This commit is contained in:
yousiki committed 2026-04-27 15:06:04 +09:00
1 parent 10cf27f63e
commit 9808ebfe36
2 files changed
+49 -12

No files matched your search

@@ -196,6 +196,17 @@ describe('Claude Quota Fetcher', () => {
expect(windows[0].label).toBe('Seven Day Haiku');
expect(windows[0].remainingPercent).toBe(84);
});
it('treats OAuth usage utilization as percent (regression for issue: Sonnet weekly shown as 0% when 1% used)', () => {
const windows = buildClaudeQuotaWindows({
five_hour: { utilization: 34.0, resets_at: '2026-04-27T06:50:01Z' },
seven_day: { utilization: 8.0, resets_at: '2026-04-27T18:00:00Z' },
seven_day_sonnet: { utilization: 1.0, resets_at: '2026-04-27T18:00:00Z' },
});
const sonnet = windows.find((w) => w.rateLimitType === 'seven_day_sonnet');
expect(sonnet?.usedPercent).toBe(1);
expect(sonnet?.remainingPercent).toBe(99);
});
});
describe('buildClaudeCoreUsageSummary', () => {