Skip to content

Commit 2afe062

Browse files
committed
test(quota): pin live Cursor GetCurrentPeriodUsage remaining
Signed-in Ultra session returned planUsage remaining/limit 40000 and totalPercentUsed 0. Parse billingCycleEnd as reset time.
1 parent be0817f commit 2afe062

2 files changed

Lines changed: 36 additions & 2 deletions

File tree

src/lib/subscription-quota.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,31 @@ describe("subscription quota inventory", () => {
188188
expect(parsed?.remaining).toBe(25)
189189
})
190190

191+
it("parses the live Cursor GetCurrentPeriodUsage envelope from this machine", () => {
192+
// Sanitized from a signed-in Ultra cursor-agent session on 2026-08-16.
193+
// Token never stored. Numbers are the real planUsage fields.
194+
const payload = {
195+
enabled: true,
196+
billingCycleStart: "1786889793000",
197+
billingCycleEnd: "1789568193000",
198+
planUsage: {
199+
remaining: 40000,
200+
limit: 40000,
201+
remainingBonus: false,
202+
autoPercentUsed: 0,
203+
apiPercentUsed: 0,
204+
totalPercentUsed: 0,
205+
},
206+
}
207+
const parsed = remainingFromOfficialPayload("cursor", payload)
208+
expect(parsed?.remaining).toBe(100)
209+
expect(parsed?.resetsAt).toBe(1_789_568_193)
210+
expect(parsed?.extras?.map((e) => e.label).sort()).toEqual([
211+
"API",
212+
"Auto / Composer",
213+
])
214+
})
215+
191216
it("does not invent Cursor remaining from about/status identity", () => {
192217
expect(
193218
remainingFromOfficialPayload("cursor", {

src/lib/subscription-quota.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,17 @@ function percentRemaining(usedPercent: unknown): number | null {
126126
}
127127

128128
function parseResetsAt(value: unknown): number | undefined {
129-
if (typeof value === "number" && Number.isFinite(value)) return value
129+
if (typeof value === "number" && Number.isFinite(value)) {
130+
return value > 1e12 ? Math.floor(value / 1000) : value
131+
}
130132
if (typeof value === "string") {
131-
const ms = Date.parse(value)
133+
const trimmed = value.trim()
134+
if (/^\d+$/.test(trimmed)) {
135+
const n = Number(trimmed)
136+
if (!Number.isFinite(n)) return undefined
137+
return n > 1e12 ? Math.floor(n / 1000) : n
138+
}
139+
const ms = Date.parse(trimmed)
132140
if (!Number.isNaN(ms)) return Math.floor(ms / 1000)
133141
}
134142
return undefined
@@ -338,6 +346,7 @@ export function remainingFromCursorPeriodUsage(
338346
limit: 100,
339347
source: "cursor DashboardService/GetCurrentPeriodUsage",
340348
extras: extras.length ? extras : undefined,
349+
resetsAt: parseResetsAt(rec.billingCycleEnd ?? rec.billing_cycle_end),
341350
}
342351
}
343352

0 commit comments

Comments
 (0)