Skip to content
TypeScript

fix(web,mobile): Limits bars show the even-pace mark as a tick in a gap (#22408)

Julius Marminge5d4c202e3f5b
diff --git a/apps/mobile/src/features/usage/UsageLimitsPooled.tsx b/apps/mobile/src/features/usage/UsageLimitsPooled.tsx
index 9013a3dfcc9..010c902364c 100644
--- a/apps/mobile/src/features/usage/UsageLimitsPooled.tsx
+++ b/apps/mobile/src/features/usage/UsageLimitsPooled.tsx
@@ -41,6 +41,53 @@ function accountName(account: LimitAccount) {
return `${local[0] ?? ""}${domain[0] ?? ""}`.toUpperCase() || "Account";
}
+// Same gap-and-tick as the Limits rows: two clipped copies of the segment leave a see-through gap.
+function PaceGap({
+ timeLeft,
+ children,
+}: {
+ readonly timeLeft: number | null;
+ readonly children: ReactNode;
+}) {
+ const [width, setWidth] = useState(0);
+ const tickX =
+ timeLeft === null || width < 6
+ ? null
+ : Math.min(Math.max((width * timeLeft) / 100, 3), width - 3);
+ return (
+ <View
+ pointerEvents="none"
+ className="absolute inset-0"
+ onLayout={(event) => setWidth(event.nativeEvent.layout.width)}
+ >
+ {tickX === null
+ ? children
+ : (
+ [
+ [0, tickX - 3],
+ [tickX + 3, width],
+ ] as const
+ ).map(([start, end]) => (
+ <View
+ key={start}
+ className="absolute top-0 bottom-0 overflow-hidden"
+ style={{ left: start, width: end - start }}
+ >
+ <View className="absolute top-0 bottom-0" style={{ left: -start, width }}>
+ {children}
+ </View>
+ </View>
+ ))}
+ {tickX !== null ? (
+ <View
+ className="absolute top-0.5 bottom-0.5 w-0.5 rounded-full bg-foreground"
+ style={{ left: tickX - 1 }}
+ />
+ ) : null}
+ </View>
+ );
+}
+
function AccountSegment({
remaining,
color,
@@ -155,22 +202,18 @@ function PoolWindowCard({
accessibilityLabel={`Segment ${index + 1}, ${accountName(account)}, ${remainingPercent(window)}% left${timeLeft === null ? "" : `, ${timeLeft}% of the window left`}`}
accessibilityHint="Show account details"
onPress={() => openAccount(account)}
- className="h-7 min-w-0 flex-1 rounded-md bg-subtle"
+ className="h-7 min-w-0 flex-1 rounded-md"
>
- <View className="absolute inset-0 overflow-hidden rounded-md">
- <AccountSegment
- remaining={remainingPercent(window)}
- color={color}
- refillPercent={window.resetsAt ? member.refillPercent : 0}
- />
- </View>
- {timeLeft !== null ? (
- <View
- pointerEvents="none"
- className="absolute -top-1 -bottom-1 w-0.5 -translate-x-px rounded-full bg-foreground-muted"
- style={{ left: `${timeLeft}%` }}
- />
- ) : null}
+ <PaceGap timeLeft={timeLeft}>
+ <View className="absolute inset-0 rounded-md bg-subtle" />
+ <View className="absolute inset-0 overflow-hidden rounded-md">
+ <AccountSegment
+ remaining={remainingPercent(window)}
+ color={color}
+ refillPercent={window.resetsAt ? member.refillPercent : 0}
+ />
+ </View>
+ </PaceGap>
<View
pointerEvents="none"
className="absolute inset-0 items-center justify-center overflow-hidden rounded-md"
diff --git a/apps/mobile/src/features/usage/UsageLimitsSection.tsx b/apps/mobile/src/features/usage/UsageLimitsSection.tsx
index e5a16a8b75f..c22496741d9 100644
--- a/apps/mobile/src/features/usage/UsageLimitsSection.tsx
+++ b/apps/mobile/src/features/usage/UsageLimitsSection.tsx
@@ -49,6 +49,32 @@ function WindowRow(props: {
const timeLeft = paceRemainingPercent(window, now);
const pace = paceOf(window, now);
const resetsIn = formatResetsIn(window, now);
+ const [barWidth, setBarWidth] = useState(0);
+ const tickX =
+ timeLeft === null || barWidth < 6
+ ? null
+ : Math.min(Math.max((barWidth * timeLeft) / 100, 3), barWidth - 3);
+ const bar = (
+ <View
+ className="h-1.5 flex-row overflow-hidden rounded-full bg-subtle"
+ style={barWidth > 0 ? { width: barWidth } : undefined}
+ >
+ <View
+ className={
+ remaining <= 10
+ ? "h-full rounded-full bg-red-500"
+ : remaining <= 30
+ ? "h-full rounded-full bg-amber-500"
+ : "h-full rounded-full bg-foreground"
+ }
+ style={[
+ { flex: remaining },
+ remaining > 30 && props.color ? { backgroundColor: props.color } : null,
+ ]}
+ />
+ <View style={{ flex: 100 - remaining }} />
+ </View>
+ );
return (
<View className="gap-1">
<View className="flex-row items-baseline justify-between gap-3">
@@ -57,27 +83,35 @@ function WindowRow(props: {
{remaining}% left
</Text>
</View>
- <View className="h-3 justify-center">
- <View className="h-1.5 flex-row overflow-hidden rounded-full bg-subtle">
- <View
- className={
- remaining <= 10
- ? "h-full rounded-full bg-red-500"
- : remaining <= 30
- ? "h-full rounded-full bg-amber-500"
- : "h-full rounded-full bg-foreground"
- }
- style={[
- { flex: remaining },
- remaining > 30 && props.color ? { backgroundColor: props.color } : null,
- ]}
- />
- <View style={{ flex: 100 - remaining }} />
- </View>
- {timeLeft !== null ? (
+ <View
+ className="h-3 justify-center"
+ onLayout={(event) => setBarWidth(event.nativeEvent.layout.width)}
+ >
+ {tickX === null ? (
+ bar
+ ) : (
+ <View className="h-1.5">
+ {/* Clip the same full-width bar so neither fill proportions nor corner radii change. */}
+ {(
+ [
+ [0, tickX - 3],
+ [tickX + 3, barWidth],
+ ] as const
+ ).map(([start, end]) => (
+ <View
+ key={start}
+ className="absolute top-0 bottom-0 overflow-hidden"
+ style={{ left: start, width: end - start }}
+ >
+ <View style={{ marginLeft: -start }}>{bar}</View>
+ </View>
+ ))}
+ </View>
+ )}
+ {tickX !== null ? (
<View
- className="absolute top-0 bottom-0 w-px bg-foreground"
- style={{ left: `${timeLeft}%`, opacity: 0.6 }}
+ className="absolute top-px bottom-px w-0.5 rounded-full bg-foreground"
+ style={{ left: tickX - 1 }}
/>
) : null}
</View>
diff --git a/apps/web/src/components/usage/UsageLimits.browser.test.tsx b/apps/web/src/components/usage/UsageLimits.browser.test.tsx
new file mode 100644
index 00000000000..c0786c675f2
--- /dev/null
+++ b/apps/web/src/components/usage/UsageLimits.browser.test.tsx
@@ -0,0 +1,89 @@
+import { render } from "../../../test/render";
+import { ProviderDriverKind, type ServerProviderUsageWindow } from "@t3tools/contracts";
+import { expect, it, vi } from "vite-plus/test";
+import { page } from "vite-plus/test/browser";
+
+import "~/index.css";
+
+vi.mock("../../state/session", () => ({
+ useEnvironmentScope: () => true,
+ readEnvironmentScope: () => true,
+}));
+vi.mock("../../state/server", () => ({ serverEnvironment: { consumeResetCredit: null } }));
+vi.mock("../../state/use-atom-command", () => ({ useAtomCommand: () => vi.fn() }));
+vi.mock("../../hooks/useSettings", () => ({ usePrimarySettings: () => "24h" }));
+
+import { LimitWindows } from "./UsageLimits";
+
+const codex = ProviderDriverKind.make("codex");
+const now = Date.parse("2026-09-03T12:00:00Z");
+
+const sessionWindow = (minutesUntilReset: number | null): ServerProviderUsageWindow => ({
+ id: "five_hour",
+ kind: "session",
+ label: "Session",
+ usedPercent: 40,
+ ...(minutesUntilReset === null
+ ? {}
+ : {
+ windowDurationMins: 300,
+ resetsAt: new Date(now + minutesUntilReset * 60_000).toISOString(),
+ }),
+});
+
+const sized = (width: string) => {
+ const container = document.createElement("div");
+ container.style.width = width;
+ return container;
+};
+
+const bar = () => {
+ const element = page.getByRole("img", { name: /^Session:/ }).element();
+ const mark = element.querySelector(":scope > span[aria-hidden]");
+ return {
+ rect: element.getBoundingClientRect(),
+ mark: mark?.getBoundingClientRect(),
+ clip: getComputedStyle(element.querySelector(":scope > div")!).clipPath,
+ };
+};
+
+it("places the even-pace tick in a gap at the share of the window left", async () => {
+ await using _screen = await render(
+ <LimitWindows driver={codex} windows={[sessionWindow(90)]} now={now} />,
+ { container: sized("640px") },
+ );
+ const { rect, mark, clip } = bar();
+ expect(mark!.left + mark!.width / 2 - rect.left).toBeCloseTo(rect.width * 0.3, 0);
+ expect(clip).toMatch(/^polygon/);
+});
+
+it("keeps the tick inside the bar at both ends of the window", async () => {
+ for (const minutesUntilReset of [0, 300]) {
+ await using _screen = await render(
+ <LimitWindows driver={codex} windows={[sessionWindow(minutesUntilReset)]} now={now} />,
+ { container: sized("640px") },
+ );
+ const { rect, mark } = bar();
+ expect(mark!.left).toBeGreaterThanOrEqual(rect.left);
+ expect(mark!.right).toBeLessThanOrEqual(rect.right);
+ }
+});
+
+it("draws a continuous bar when the window timing is unknown", async () => {
+ await using _screen = await render(
+ <LimitWindows driver={codex} windows={[sessionWindow(null)]} now={now} />,
+ { container: sized("640px") },
+ );
+ expect(bar()).toMatchObject({ mark: undefined, clip: "none" });
+});
+
+it("draws neither gap nor tick on a bar narrower than 6px", async () => {
+ // 11rem + 1rem + 3.5px + 1rem + 7rem: the bar column gets 3.5px.
+ await using _screen = await render(
+ <LimitWindows driver={codex} windows={[sessionWindow(300)]} now={now} />,
+ { container: sized("323.5px") },
+ );
+ const { rect, mark, clip } = bar();
+ expect(rect.width).toBeCloseTo(3.5, 1);
+ expect({ mark, clip }).toEqual({ mark: undefined, clip: "none" });
+});
diff --git a/apps/web/src/components/usage/UsageLimits.tsx b/apps/web/src/components/usage/UsageLimits.tsx
index 0ac9cf23629..bac2682a024 100644
--- a/apps/web/src/components/usage/UsageLimits.tsx
+++ b/apps/web/src/components/usage/UsageLimits.tsx
@@ -18,9 +18,10 @@ import {
remainingPercent,
} from "@t3tools/shared/usageLimits";
import { GaugeIcon, TrendingDownIcon, TrendingUpIcon } from "lucide-react";
-import { Fragment, type ReactNode, useState } from "react";
+import { Fragment, type ReactNode, useLayoutEffect, useState } from "react";
import { usePrimarySettings } from "../../hooks/useSettings";
+import { observeResize } from "../../lib/observeResize";
import { environmentPresentations } from "../../state/presentation";
import { useEnvironmentScope, readEnvironmentScope } from "../../state/session";
import { serverEnvironment } from "../../state/server";
@@ -73,6 +74,43 @@ export function PaceIcon({ pace }: { readonly pace: LimitPace }) {
);
}
+// The tick sits in a transparent gap cut from the bar, clamped so it stays inside at 0% and 100%.
+// The gap is a clip-path slot rather than a mask: a mask composites its layer and re-antialiases
+// the bar's rounded ends, and the polygon reaches 1px past the box so only the slot edges clip.
+function paceMarkStyles(timeLeft: number | null) {
+ if (timeLeft === null) return null;
+ const at = `clamp(3px, ${timeLeft}%, calc(100% - 3px))`;
+ const [left, right] = [`calc(${at} - 3px)`, `calc(${at} + 3px)`];
+ const [near, far] = ["-1px", "calc(100% + 1px)"];
+ return {
+ tick: { left: at },
+ gap: {
+ clipPath: `polygon(${near} ${near}, ${left} ${near}, ${left} ${far}, ${right} ${far}, ${right} ${near}, ${far} ${near}, ${far} ${far}, ${near} ${far})`,
+ },
+ // For a track painted on an element that also draws focus rings, which a clip would cut.
+ gappedTrack: {
+ backgroundColor: "transparent",
+ backgroundImage: `linear-gradient(to right, var(--color-muted) ${left}, transparent ${left}, transparent ${right}, var(--color-muted) ${right})`,
+ },
+ };
+}
+
+/**
+ * Pace mark styles for the bar given the returned ref. Below 6px there is no room for the gap
+ * and tick, so the bar draws neither, as the mobile bars do.
+ */
+export function usePaceMark(timeLeft: number | null) {
+ const [bar, setBar] = useState<HTMLElement | null>(null);
+ const [roomy, setRoomy] = useState(false);
+ useLayoutEffect(() => {
+ if (!bar) return;
+ const measure = () => setRoomy(bar.getBoundingClientRect().width >= 6);
+ measure();
+ return observeResize(bar, measure);
+ }, [bar]);
+ return [setBar, roomy ? paceMarkStyles(timeLeft) : null] as const;
+}
+
function WindowBar({
color,
window,
@@ -85,6 +123,7 @@ function WindowBar({
const timestampFormat = usePrimarySettings((settings) => settings.timestampFormat);
const remaining = remainingPercent(window);
const timeLeft = paceRemainingPercent(window, now);
+ const [barRef, paceMark] = usePaceMark(timeLeft);
const resetsIn = formatResetsIn(window, now);
const resetsAt = window.resetsAt
? formatUpcomingTimestamp(window.resetsAt, timestampFormat, now)
@@ -98,6 +137,7 @@ function WindowBar({
<TooltipTrigger
render={
<div
+ ref={barRef}
role="img"
aria-label={summary}
tabIndex={0}
@@ -105,18 +145,21 @@ function WindowBar({
/>
}
>
- <div className="absolute inset-x-0 inset-y-1.5 rounded-full bg-muted" />
- {remaining > 0 ? (
- <div
- className="absolute inset-y-1.5 left-0 rounded-full"
- style={{ width: `${remaining}%`, backgroundColor: color }}
- />
- ) : null}
- {timeLeft !== null ? (
+ {/* Clip both layers so the gap exposes even a translucent composer surface. */}
+ <div className="absolute inset-0" style={paceMark?.gap}>
+ <div className="absolute inset-x-0 inset-y-1.5 rounded-full bg-muted" />
+ {remaining > 0 ? (
+ <div
+ className="absolute inset-y-1.5 left-0 rounded-full"
+ style={{ width: `${remaining}%`, backgroundColor: color }}
+ />
+ ) : null}
+ </div>
+ {paceMark ? (
<span
aria-hidden
- className="absolute inset-y-0.5 w-px -translate-x-1/2 bg-foreground/60"
- style={{ left: `${timeLeft}%` }}
+ className="absolute inset-y-1 w-0.5 -translate-x-1/2 rounded-full bg-foreground"
+ style={paceMark.tick}
/>
) : null}
</TooltipTrigger>
diff --git a/apps/web/src/components/usage/UsageLimitsPooled.browser.test.tsx b/apps/web/src/components/usage/UsageLimitsPooled.browser.test.tsx
index b5b6f034151..b175bbd3b09 100644
--- a/apps/web/src/components/usage/UsageLimitsPooled.browser.test.tsx
+++ b/apps/web/src/components/usage/UsageLimitsPooled.browser.test.tsx
@@ -177,6 +177,23 @@ it("omits an empty reset plate but keeps countdowns and banked credits visible",
expect(plate()?.textContent).toBe("1");
});
+it("cuts the pace gap through the segment track and keeps the tick inside it", async () => {
+ setup();
+ // Five hours before the reset is the start of the window, the right-hand end of the bar.
+ await using _screen = await render(
+ <UsageLimitsPooled
+ presentations={presentations("2026-09-03T14:00:00Z", 0)}
+ now={Date.parse("2026-09-03T09:00:00Z")}
+ />,
+ );
+ const segment = page.getByRole("button", { name: /^Alpha:/ }).element();
+ const tick = segment.querySelector(':scope > span[style*="left"]')!.getBoundingClientRect();
+ const rect = segment.getBoundingClientRect();
+ expect(getComputedStyle(segment).backgroundImage).toMatch(/^linear-gradient/);
+ expect(tick.left).toBeGreaterThanOrEqual(rect.left);
+ expect(tick.right).toBeLessThanOrEqual(rect.right);
+});
+
it("moves the one limit popover between windows on hover", async () => {
setup();
await using screen = await render(initial());
diff --git a/apps/web/src/components/usage/UsageLimitsPooled.tsx b/apps/web/src/components/usage/UsageLimitsPooled.tsx
index 8fc4b775b85..76be2555ff8 100644
--- a/apps/web/src/components/usage/UsageLimitsPooled.tsx
+++ b/apps/web/src/components/usage/UsageLimitsPooled.tsx
@@ -42,6 +42,7 @@ import {
PaceIcon,
ResetCreditDialog,
barColor,
+ usePaceMark,
resetCreditsSummary,
useResetCredit,
} from "./UsageLimits";
@@ -342,6 +343,7 @@ function SegmentTriggers({
const payload: SegmentPayload = { account, window, reset, redeem };
const remaining = remainingPercent(window);
const timeLeft = paceRemainingPercent(window, now);
+ const [segmentRef, paceMark] = usePaceMark(timeLeft);
const resetsIn = formatResetsIn(window, now);
const credits = account.limits.resetCredits?.availableCount ?? 0;
return (
@@ -352,35 +354,39 @@ function SegmentTriggers({
openOnHover
render={
<button
+ ref={segmentRef}
type="button"
- style={{ gridColumn: index, gridRow: 1 }}
+ style={{ gridColumn: index, gridRow: 1, ...paceMark?.gappedTrack }}
aria-label={`${account.displayName ?? (account.email ? accountInitials(account.email) : account.driver)}: ${remaining}% left${resetsIn ? `, ${resetsIn}` : ""}${timeLeft === null ? "" : `, ${timeLeft}% of the window left`}${credits ? `, ${credits} reset ${credits === 1 ? "credit" : "credits"} banked` : ""}`}
className="relative h-5 min-w-0 cursor-pointer rounded-md bg-muted text-start outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background data-[popup-open]:ring-1 data-[popup-open]:ring-inset data-[popup-open]:ring-border @2xl/pool:h-8"
/>
}
>
<div aria-hidden className="absolute inset-0 overflow-hidden rounded-md">
- <div
- aria-hidden
- className="absolute inset-y-0 left-0 rounded-md opacity-35"
- style={{ width: `${remaining}%`, backgroundColor: color }}
- />
- {remaining < 100 && reset && refillPercent > 0 ? (
+ {/* Clipped inside the rounded clip so the bar's own corners keep their antialiasing. */}
+ <div className="absolute inset-0" style={paceMark?.gap}>
<div
aria-hidden
- className="absolute inset-y-0 right-0 opacity-20"
- style={{
- width: `${Math.min(100 - remaining, refillPercent)}%`,
- backgroundImage: `repeating-linear-gradient(135deg, ${color} 0 1px, transparent 1px 5px)`,
- }}
+ className="absolute inset-y-0 left-0 rounded-md opacity-35"
+ style={{ width: `${remaining}%`, backgroundColor: color }}
/>
- ) : null}
+ {remaining < 100 && reset && refillPercent > 0 ? (
+ <div
+ aria-hidden
+ className="absolute inset-y-0 right-0 opacity-20"
+ style={{
+ width: `${Math.min(100 - remaining, refillPercent)}%`,
+ backgroundImage: `repeating-linear-gradient(135deg, ${color} 0 1px, transparent 1px 5px)`,
+ }}
+ />
+ ) : null}
+ </div>
</div>
- {timeLeft !== null ? (
+ {paceMark ? (
<span
aria-hidden
- className="absolute -inset-y-1 w-0.5 -translate-x-1/2 rounded-full bg-muted-foreground"
- style={{ left: `${timeLeft}%` }}
+ className="absolute inset-y-0.5 w-0.5 -translate-x-1/2 rounded-full bg-foreground"
+ style={paceMark.tick}
/>
) : null}
<span
diff --git a/apps/web/test/fixtures/usage-limits-hub/README.md b/apps/web/test/fixtures/usage-limits-hub/README.md
new file mode 100644
index 00000000000..7a7bc70fb44
--- /dev/null
+++ b/apps/web/test/fixtures/usage-limits-hub/README.md
@@ -0,0 +1,8 @@
+# Usage limits hub fixture
+
+A fake CLIProxyAPI hub that serves the Limits evidence scenarios in `scenarios.json`
+(A mixed, B one account per provider, C six long-named Codex accounts, L named accounts,
+T forty accounts). Run `node hub.mjs state.json 18517` with `state.json` set to
+`{"scenario": "A", "n0": <epoch ms>}`, add `http://127.0.0.1:18517` with any management key
+under Settings → Usage limit sources in a dev server, and freeze the browser clock at `n0`.
+Edit `state.json` and press Refresh limits to switch scenarios.
diff --git a/apps/web/test/fixtures/usage-limits-hub/hub.mjs b/apps/web/test/fixtures/usage-limits-hub/hub.mjs
new file mode 100644
index 00000000000..a2ba8d7c2ef
--- /dev/null
+++ b/apps/web/test/fixtures/usage-limits-hub/hub.mjs
@@ -0,0 +1,91 @@
+// Fake CLIProxyAPI management API serving the Limits scenarios in scenarios.json.
+// Usage: node hub.mjs <state.json> [port]. state.json is {"scenario": "A", "n0": <epoch ms>};
+// it is re-read on every request, so edit it and press Refresh limits to switch scenarios.
+import * as NodeFS from "node:fs";
+import * as NodeHttp from "node:http";
+
+const [statePath, port = "18517"] = process.argv.slice(2);
+if (!statePath) throw new Error("usage: node hub.mjs <state.json> [port]");
+const scenarios = JSON.parse(
+ NodeFS.readFileSync(new URL("./scenarios.json", import.meta.url), "utf8"),
+);
+const MINUTE = 60_000;
+
+// A window is [usedPercent, minutesFromN0 | null]; null is unknown reset timing.
+const at = (n0, minutes) => (minutes === null ? null : n0 + minutes * MINUTE);
+const usage = (account, n0) => {
+ const [session, weekly, fable] = account.windows;
+ if (account.provider === "codex") {
+ const window = ([used, minutes], seconds) => ({
+ used_percent: used,
+ reset_at: at(n0, minutes) === null ? null : Math.floor(at(n0, minutes) / 1000),
+ limit_window_seconds: seconds,
+ });
+ return {
+ plan_type: "pro",
+ rate_limit: {
+ primary_window: window(session, 18_000),
+ secondary_window: window(weekly, 604_800),
+ },
+ };
+ }
+ const window = ([used, minutes]) => ({
+ utilization: used,
+ resets_at: at(n0, minutes) === null ? null : new Date(at(n0, minutes)).toISOString(),
+ });
+ return {
+ five_hour: window(session),
+ seven_day: window(weekly),
+ limits: fable
+ ? [
+ {
+ kind: "weekly_scoped",
+ percent: fable[0],
+ resets_at: window(fable).resets_at,
+ scope: { model: { display_name: "Fable" } },
+ },
+ ]
+ : [],
+ };
+};
+
+const json = (response, body) => {
+ response.writeHead(200, { "content-type": "application/json" });
+ response.end(JSON.stringify(body));
+};
+
+NodeHttp.createServer((request, response) => {
+ let raw = "";
+ request.on("data", (chunk) => (raw += chunk));
+ request.on("end", () => {
+ const { scenario, n0 } = JSON.parse(NodeFS.readFileSync(statePath, "utf8"));
+ const accounts = scenarios[scenario];
+ if (!accounts) return json(response, { files: [] });
+ if (request.url.endsWith("/v0/management/auth-files")) {
+ return json(response, {
+ files: Object.entries(accounts).map(([id, account]) => ({
+ id,
+ auth_index: id,
+ provider: account.provider,
+ ...(account.email ? { email: account.email } : {}),
+ })),
+ });
+ }
+ if (request.url.endsWith("/v0/management/api-call")) {
+ const call = JSON.parse(raw);
+ const account = accounts[call.auth_index];
+ if (!account) return json(response, { status_code: 404, body: "{}" });
+ if (call.url.endsWith("/rate-limit-reset-credits")) {
+ const credits = Array.from({ length: account.credits ?? 0 }, (_, index) => ({
+ id: `${call.auth_index}-credit-${index}`,
+ status: "available",
+ reset_type: "codex_rate_limits",
+ expires_at: new Date(n0 + 3 * 24 * 60 * MINUTE).toISOString(),
+ }));
+ return json(response, { status_code: 200, body: JSON.stringify({ credits }) });
+ }
+ return json(response, { status_code: 200, body: JSON.stringify(usage(account, n0)) });
+ }
+ response.writeHead(404).end();
+ });
+}).listen(Number(port), "127.0.0.1", () => console.log(`usage limits hub on ${port}`));
diff --git a/apps/web/test/fixtures/usage-limits-hub/scenarios.json b/apps/web/test/fixtures/usage-limits-hub/scenarios.json
new file mode 100644
index 00000000000..70e9be83f9a
--- /dev/null
+++ b/apps/web/test/fixtures/usage-limits-hub/scenarios.json
@@ -0,0 +1,516 @@
+{
+ "A": {
+ "c1": {
+ "provider": "codex",
+ "email": "[email protected]",
+ "windows": [
+ [30, 120],
+ [60, 7560.0]
+ ]
+ },
+ "c2": {
+ "provider": "codex",
+ "email": "[email protected]",
+ "windows": [
+ [0, 310],
+ [40, null]
+ ]
+ },
+ "c3": {
+ "provider": "codex",
+ "email": "[email protected]",
+ "windows": [
+ [20, -1],
+ [50, 5040.0]
+ ],
+ "credits": 2
+ },
+ "a1": {
+ "provider": "claude",
+ "email": "[email protected]",
+ "windows": [
+ [50, 150.0],
+ [10, 9273.6],
+ [0, 10140]
+ ]
+ },
+ "a2": {
+ "provider": "claude",
+ "email": "[email protected]",
+ "windows": [
+ [100, 60],
+ [92, 5040.0],
+ [75, 7200]
+ ]
+ },
+ "a3": {
+ "provider": "claude",
+ "email": "[email protected]",
+ "windows": [
+ [30, 180],
+ [100, 120]
+ ]
+ }
+ },
+ "B": {
+ "c1": {
+ "provider": "codex",
+ "email": "[email protected]",
+ "windows": [
+ [30, 120],
+ [60, 7560.0]
+ ]
+ },
+ "a1": {
+ "provider": "claude",
+ "email": "[email protected]",
+ "windows": [
+ [50, 150.0],
+ [10, 9273.6],
+ [0, 10140]
+ ]
+ }
+ },
+ "C": {
+ "m1": {
+ "provider": "codex",
+ "email": "[email protected]",
+ "windows": [
+ [0, 310],
+ [0, 10140]
+ ]
+ },
+ "m2": {
+ "provider": "codex",
+ "email": "[email protected]",
+ "windows": [
+ [100, -1],
+ [100, 60]
+ ]
+ },
+ "m3": {
+ "provider": "codex",
+ "email": "[email protected]",
+ "windows": [
+ [45, 165.0],
+ [30, 7200]
+ ]
+ },
+ "m4": {
+ "provider": "codex",
+ "email": "[email protected]",
+ "windows": [
+ [10, 30.0],
+ [80, 8640]
+ ]
+ },
+ "m5": {
+ "provider": "codex",
+ "email": "[email protected]",
+ "windows": [
+ [40, null],
+ [40, null]
+ ]
+ },
+ "m6": {
+ "provider": "codex",
+ "email": "[email protected]",
+ "windows": [
+ [60, 240],
+ [5, 1440]
+ ]
+ }
+ },
+ "L": {
+ "platform-team-primary": {
+ "provider": "codex",
+ "windows": [
+ [30, 120],
+ [60, 7560.0]
+ ]
+ },
+ "platform-team-backup": {
+ "provider": "codex",
+ "windows": [
+ [0, 310],
+ [40, null]
+ ]
+ },
+ "contractor-shared-pool": {
+ "provider": "codex",
+ "windows": [
+ [20, -1],
+ [50, 9072.0]
+ ],
+ "credits": 2
+ },
+ "research-lab-claude-seat-1": {
+ "provider": "claude",
+ "windows": [
+ [50, 150.0],
+ [10, 9273.6],
+ [0, 10140]
+ ]
+ },
+ "research-lab-claude-seat-2": {
+ "provider": "claude",
+ "windows": [
+ [100, 60],
+ [92, 5040.0],
+ [75, 7200]
+ ]
+ },
+ "research-lab-claude-seat-3": {
+ "provider": "claude",
+ "windows": [
+ [30, 180],
+ [100, 120]
+ ]
+ },
+ "research-lab-claude-seat-4": {
+ "provider": "claude",
+ "windows": [
+ [50, 150.0],
+ [10, 9273.6],
+ [0, 10140]
+ ]
+ },
+ "research-lab-claude-seat-5": {
+ "provider": "claude",
+ "windows": [
+ [100, 60],
+ [92, 5040.0],
+ [75, 7200]
+ ]
+ },
+ "research-lab-claude-seat-6": {
+ "provider": "claude",
+ "windows": [
+ [30, 180],
+ [100, 120]
+ ]
+ }
+ },
+ "T": {
+ "t01": {
+ "provider": "codex",
+ "email": "[email protected]",
+ "windows": [
+ [7, 37],
+ [13, 697]
+ ]
+ },
+ "t02": {
+ "provider": "codex",
+ "email": "[email protected]",
+ "windows": [
+ [14, 44],
+ [26, 794]
+ ]
+ },
+ "t03": {
+ "provider": "codex",
+ "email": "[email protected]",
+ "windows": [
+ [21, 51],
+ [39, 891]
+ ]
+ },
+ "t04": {
+ "provider": "codex",
+ "email": "[email protected]",
+ "windows": [
+ [28, 58],
+ [52, 988]
+ ]
+ },
+ "t05": {
+ "provider": "codex",
+ "email": "[email protected]",
+ "windows": [
+ [35, 65],
+ [65, 1085]
+ ]
+ },
+ "t06": {
+ "provider": "codex",
+ "email": "[email protected]",
+ "windows": [
+ [42, 72],
+ [78, 1182]
+ ]
+ },
+ "t07": {
+ "provider": "codex",
+ "email": "[email protected]",
+ "windows": [
+ [49, 79],
+ [91, 1279]
+ ]
+ },
+ "t08": {
+ "provider": "codex",
+ "email": "[email protected]",
+ "windows": [
+ [56, 86],
+ [4, 1376]
+ ]
+ },
+ "t09": {
+ "provider": "codex",
+ "email": "[email protected]",
+ "windows": [
+ [63, 93],
+ [17, 1473]
+ ]
+ },
+ "t10": {
+ "provider": "codex",
+ "email": "[email protected]",
+ "windows": [
+ [70, 100],
+ [30, 1570]
+ ]
+ },
+ "t11": {
+ "provider": "codex",
+ "email": "[email protected]",
+ "windows": [
+ [77, 107],
+ [43, 1667]
+ ]
+ },
+ "t12": {
+ "provider": "codex",
+ "email": "[email protected]",
+ "windows": [
+ [84, 114],
+ [56, 1764]
+ ]
+ },
+ "t13": {
+ "provider": "codex",
+ "email": "[email protected]",
+ "windows": [
+ [91, 121],
+ [69, 1861]
+ ]
+ },
+ "t14": {
+ "provider": "codex",
+ "email": "[email protected]",
+ "windows": [
+ [98, 128],
+ [82, 1958]
+ ]
+ },
+ "t15": {
+ "provider": "codex",
+ "email": "[email protected]",
+ "windows": [
+ [5, 135],
+ [95, 2055]
+ ]
+ },
+ "t16": {
+ "provider": "codex",
+ "email": "[email protected]",
+ "windows": [
+ [12, 142],
+ [8, 2152]
+ ]
+ },
+ "t17": {
+ "provider": "codex",
+ "email": "[email protected]",
+ "windows": [
+ [19, 149],
+ [21, 2249]
+ ]
+ },
+ "t18": {
+ "provider": "codex",
+ "email": "[email protected]",
+ "windows": [
+ [26, 156],
+ [34, 2346]
+ ]
+ },
+ "t19": {
+ "provider": "codex",
+ "email": "[email protected]",
+ "windows": [
+ [33, 163],
+ [47, 2443]
+ ]
+ },
+ "t20": {
+ "provider": "codex",
+ "email": "[email protected]",
+ "windows": [
+ [40, 170],
+ [60, 2540]
+ ]
+ },
+ "t21": {
+ "provider": "codex",
+ "email": "[email protected]",
+ "windows": [
+ [47, 177],
+ [73, 2637]
+ ]
+ },
+ "t22": {
+ "provider": "codex",
+ "email": "[email protected]",
+ "windows": [
+ [54, 184],
+ [86, 2734]
+ ]
+ },
+ "t23": {
+ "provider": "codex",
+ "email": "[email protected]",
+ "windows": [
+ [61, 191],
+ [99, 2831]
+ ]
+ },
+ "t24": {
+ "provider": "codex",
+ "email": "[email protected]",
+ "windows": [
+ [68, 198],
+ [12, 2928]
+ ]
+ },
+ "t25": {
+ "provider": "codex",
+ "email": "[email protected]",
+ "windows": [
+ [75, 205],
+ [25, 3025]
+ ]
+ },
+ "t26": {
+ "provider": "codex",
+ "email": "[email protected]",
+ "windows": [
+ [82, 212],
+ [38, 3122]
+ ]
+ },
+ "t27": {
+ "provider": "codex",
+ "email": "[email protected]",
+ "windows": [
+ [89, 219],
+ [51, 3219]
+ ]
+ },
+ "t28": {
+ "provider": "codex",
+ "email": "[email protected]",
+ "windows": [
+ [96, 226],
+ [64, 3316]
+ ]
+ },
+ "t29": {
+ "provider": "codex",
+ "email": "[email protected]",
+ "windows": [
+ [3, 233],
+ [77, 3413]
+ ]
+ },
+ "t30": {
+ "provider": "codex",
+ "email": "[email protected]",
+ "windows": [
+ [10, 240],
+ [90, 3510]
+ ]
+ },
+ "t31": {
+ "provider": "codex",
+ "email": "[email protected]",
+ "windows": [
+ [17, 247],
+ [3, 3607]
+ ]
+ },
+ "t32": {
+ "provider": "codex",
+ "email": "[email protected]",
+ "windows": [
+ [24, 254],
+ [16, 3704]
+ ]
+ },
+ "t33": {
+ "provider": "codex",
+ "email": "[email protected]",
+ "windows": [
+ [31, 261],
+ [29, 3801]
+ ]
+ },
+ "t34": {
+ "provider": "codex",
+ "email": "[email protected]",
+ "windows": [
+ [38, 268],
+ [42, 3898]
+ ]
+ },
+ "t35": {
+ "provider": "codex",
+ "email": "[email protected]",
+ "windows": [
+ [45, 275],
+ [55, 3995]
+ ]
+ },
+ "t36": {
+ "provider": "codex",
+ "email": "[email protected]",
+ "windows": [
+ [52, 282],
+ [68, 4092]
+ ]
+ },
+ "t37": {
+ "provider": "codex",
+ "email": "[email protected]",
+ "windows": [
+ [59, 289],
+ [81, 4189]
+ ]
+ },
+ "t38": {
+ "provider": "codex",
+ "email": "[email protected]",
+ "windows": [
+ [66, 296],
+ [94, 4286]
+ ]
+ },
+ "t39": {
+ "provider": "codex",
+ "email": "[email protected]",
+ "windows": [
+ [73, 33],
+ [7, 4383]
+ ]
+ },
+ "t40": {
+ "provider": "codex",
+ "email": "[email protected]",
+ "windows": [
+ [80, 40],
+ [20, 4480]
+ ]
+ }
+ }
+}
diff --git a/knip.jsonc b/knip.jsonc
index aaf5f6e7ffe..fd258711615 100644
--- a/knip.jsonc
+++ b/knip.jsonc
@@ -69,8 +69,9 @@
"ignoreDependencies": ["playwright-core", "electron-builder"],
},
"apps/web": {
- // Worktree setup (scripts/setup-worktree.ts) runs this directly.
- "entry": ["scripts/warm-dep-cache.ts"],
+ // Worktree setup (scripts/setup-worktree.ts) runs this directly, and evidence
+ // fixtures run under node.
+ "entry": ["scripts/warm-dep-cache.ts", "test/fixtures/**/*.mjs"],
// UI component modules are copied and adapted as cohesive sets. Keep their
// named subcomponents even before they have callers; the file audit still
// reports an entire component module when nothing imports it.