Skip to content

Commit 9572ae4

Browse files
committed
fix(mobile): distinguish retained widget quota readings
1 parent 0f355e7 commit 9572ae4

2 files changed

Lines changed: 41 additions & 16 deletions

File tree

‎apps/mobile/src/widgets/subscriptionUsageSnapshot.test.ts‎

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ describe("subscription widget snapshots", () => {
100100
expect(snapshot.providers[0]?.name).toBe("Codex");
101101
expect(JSON.stringify(snapshot)).not.toContain("example.com");
102102
const source = input.get(EnvironmentId.make("env"))!.serverConfig.usageLimitSources[0]!;
103-
const failed = buildSubscriptionUsageSnapshot(
103+
const failedInput = (windows: typeof limits.windows, includeHealthy = false) =>
104104
new Map([
105105
[
106106
EnvironmentId.make("env"),
@@ -111,22 +111,26 @@ describe("subscription widget snapshots", () => {
111111
usageLimitSources: [
112112
{
113113
...source,
114-
accounts: source.accounts.map((account) => ({
115-
...account,
116-
usageLimits: {
117-
checkedAt,
118-
windows: [],
119-
unavailable: { reason: "probeFailed" as const },
120-
},
121-
})),
114+
accounts: [
115+
...(includeHealthy ? source.accounts : []),
116+
...source.accounts.map((account) => ({
117+
...account,
118+
id: "failed-account",
119+
120+
usageLimits: {
121+
checkedAt,
122+
windows,
123+
unavailable: { reason: "probeFailed" as const },
124+
},
125+
})),
126+
],
122127
},
123128
],
124129
},
125130
},
126131
],
127-
]),
128-
deepLink,
129-
);
132+
]);
133+
const failed = buildSubscriptionUsageSnapshot(failedInput([]), deepLink);
130134
expect(failed.providers).toEqual([
131135
{
132136
name: "Codex",
@@ -136,6 +140,17 @@ describe("subscription widget snapshots", () => {
136140
totalWindows: 0,
137141
},
138142
]);
143+
const partial = buildSubscriptionUsageSnapshot(failedInput([], true), deepLink);
144+
expect(partial.providers[0]?.detail).toBe("Available subscription limits");
145+
expect(partial.providers[0]?.windows[0]?.remaining).toBe(60);
146+
const retained = buildSubscriptionUsageSnapshot(failedInput(limits.windows), deepLink);
147+
expect(retained.providers[0]?.detail).toBe("Last known limits");
148+
expect(retained.providers[0]?.windows[0]).toMatchObject({
149+
label: "Stale · 5 hours",
150+
remaining: 60,
151+
});
152+
expect(retained.checkedAt).toBe(now);
153+
expect(retained.providers[0]?.expiresAt).toBe(now + 10 * 60_000);
139154
});
140155
it("bounds OS storage and puts the most constrained windows first", () => {
141156
const windows = Array.from({ length: 20 }, (_, index) => ({

‎apps/mobile/src/widgets/subscriptionUsageSnapshot.ts‎

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,25 @@ function subscriptionUsageProps(
9595
name,
9696
detail: !fresh
9797
? "Open T3 to refresh"
98-
: pool.accounts.length > 1
99-
? `${pool.accounts.length} accounts · pooled`
100-
: "Subscription remaining",
98+
: pool.accounts.some(
99+
(account) =>
100+
account.limits.windows.length > 0 &&
101+
account.limits.unavailable?.reason === "probeFailed",
102+
)
103+
? "Last known limits"
104+
: pool.accounts.length > 1
105+
? "Available subscription limits"
106+
: "Subscription remaining",
101107
expiresAt: fresh ? expiresAt : 0,
102108
totalWindows: fresh ? pool.windows.length : 0,
103109
windows: fresh
104110
? selectedWindows.map((window) => ({
105111
kind: window.kind,
106-
label: window.label,
112+
label: window.members.some(
113+
(member) => member.account.limits.unavailable?.reason === "probeFailed",
114+
)
115+
? `Stale · ${window.label}`
116+
: window.label,
107117
remaining: Math.round(window.remainingPercent),
108118
reset: window.resets[0]
109119
? `Next reset ${new Date(window.resets[0].at).toLocaleString(undefined, {

0 commit comments

Comments
 (0)