fix: label Codex weekly usage window as "Week" instead of "Day" (#26267)
The secondary window label logic treated any window >= 24h as "Day", but Codex plans can have a weekly (604800s / 168h) quota window. The reset timer showed "resets 2d 4h" while the label said "Day", which was confusing. Now windows >= 168h are labeled "Week", >= 24h remain "Day", and shorter windows show the hour count. Closes #25812 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -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 },
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user