diff --git a/src/infra/provider-usage.fetch.codex.test.ts b/src/infra/provider-usage.fetch.codex.test.ts index cbbfbd4db..6078e2a9b 100644 --- a/src/infra/provider-usage.fetch.codex.test.ts +++ b/src/infra/provider-usage.fetch.codex.test.ts @@ -54,4 +54,29 @@ describe("fetchCodexUsage", () => { { label: "Day", usedPercent: 75, resetAt: 1_700_050_000_000 }, ]); }); + + it("labels weekly secondary window as Week", async () => { + const mockFetch = createProviderUsageFetch(async () => + makeResponse(200, { + rate_limit: { + primary_window: { + limit_window_seconds: 10_800, + used_percent: 7, + reset_at: 1_700_000_000, + }, + secondary_window: { + limit_window_seconds: 604_800, + used_percent: 10, + reset_at: 1_700_500_000, + }, + }, + }), + ); + + const result = await fetchCodexUsage("token", undefined, 5000, mockFetch); + expect(result.windows).toEqual([ + { label: "3h", usedPercent: 7, resetAt: 1_700_000_000_000 }, + { label: "Week", usedPercent: 10, resetAt: 1_700_500_000_000 }, + ]); + }); }); diff --git a/src/infra/provider-usage.fetch.codex.ts b/src/infra/provider-usage.fetch.codex.ts index 4d4cfc7fd..28d155a6b 100644 --- a/src/infra/provider-usage.fetch.codex.ts +++ b/src/infra/provider-usage.fetch.codex.ts @@ -65,7 +65,7 @@ export async function fetchCodexUsage( if (data.rate_limit?.secondary_window) { const sw = data.rate_limit.secondary_window; const windowHours = Math.round((sw.limit_window_seconds || 86400) / 3600); - const label = windowHours >= 24 ? "Day" : `${windowHours}h`; + const label = windowHours >= 168 ? "Week" : windowHours >= 24 ? "Day" : `${windowHours}h`; windows.push({ label, usedPercent: clampPercent(sw.used_percent || 0),