Skip to content

Commit b821f34

Browse files
drewwellsrobinebers
authored andcommitted
fix(cursor): use REST fallback for team-inferred accounts missing planUsage.limit
When an account is team-inferred via spendLimitUsage but planUsage.limit is missing and plan info is unavailable, the previous code threw a hard failure. Now falls back to the REST usage API instead. Made-with: Cursor
1 parent 6a5145b commit b821f34

1 file changed

Lines changed: 50 additions & 0 deletions

File tree

plugins/cursor/plugin.test.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,56 @@ describe("cursor plugin", () => {
598598
expect(reqLine.limit).toBe(500)
599599
})
600600

601+
it("falls back to REST usage for team-inferred account with percent-only and unavailable plan info", async () => {
602+
const ctx = makeCtx()
603+
const accessToken = makeJwt({ sub: "google-oauth2|user_abc123", exp: 9999999999 })
604+
605+
ctx.host.sqlite.query.mockReturnValue(JSON.stringify([{ value: accessToken }]))
606+
ctx.host.http.request.mockImplementation((opts) => {
607+
if (String(opts.url).includes("GetCurrentPeriodUsage")) {
608+
return {
609+
status: 200,
610+
bodyText: JSON.stringify({
611+
enabled: true,
612+
billingCycleStart: "1772556293029",
613+
billingCycleEnd: "1775234693029",
614+
planUsage: {
615+
totalPercentUsed: 35,
616+
},
617+
spendLimitUsage: {
618+
limitType: "team",
619+
pooledLimit: 5000,
620+
},
621+
}),
622+
}
623+
}
624+
if (String(opts.url).includes("GetPlanInfo")) {
625+
return { status: 503, bodyText: "" }
626+
}
627+
if (String(opts.url).includes("cursor.com/api/usage")) {
628+
return {
629+
status: 200,
630+
bodyText: JSON.stringify({
631+
"gpt-4": {
632+
numRequests: 150,
633+
maxRequestUsage: 500,
634+
},
635+
startOfMonth: "2026-02-01T06:12:57.000Z",
636+
}),
637+
}
638+
}
639+
return { status: 200, bodyText: "{}" }
640+
})
641+
642+
const plugin = await loadPlugin()
643+
const result = plugin.probe(ctx)
644+
const reqLine = result.lines.find((l) => l.label === "Requests")
645+
expect(reqLine).toBeTruthy()
646+
expect(reqLine.used).toBe(150)
647+
expect(reqLine.limit).toBe(500)
648+
expect(reqLine.format).toEqual({ kind: "count", suffix: "requests" })
649+
})
650+
601651
it("handles team account with request-based usage", async () => {
602652
const ctx = makeCtx()
603653
const accessToken = makeJwt({ sub: "google-oauth2|user_abc123", exp: 9999999999 })

0 commit comments

Comments
 (0)