all: a usage read says what it means for the sign-in, and a renewal clears the mark whatever follows, as the built-ins did (要保证插件跟内置的所有逻辑都要一模一样) — auth.usage returns signIn on every path: expired where the built-in's quota read marked the account (Zed's /users/me 401, Factory's and MiMo's refused renewals, Qoder's refused job refresh), renewed after a renewal, which took the mark off, kept everywhere else, so magpie no longer guesses from the words 'sign in again' (Kiro's, Devin's and ZCode's usage errors marked accounts their built-ins never did) nor clears on a clean read. A request after a renewal says renewed on any status; one without says kept, as the built-ins cleared only on renewal. Kiro, Cursor, Devin, Command Code, WorkBuddy, Grok and ZCode, whose built-ins never marked an account, say kept on every answer. New tests fail against 85d7dd0's index.mjs.
This commit is contained in:
@@ -36,6 +36,7 @@ test("a Max account: its 5 hours, its week and its credits, and its period", asy
|
||||
},
|
||||
})
|
||||
expect(u).toEqual({
|
||||
signIn: "kept",
|
||||
plan: "Max",
|
||||
until: "2026-10-28T00:00:00.000Z",
|
||||
renew: "off",
|
||||
@@ -53,7 +54,7 @@ test("no plan: the credits bought are a balance", async () => {
|
||||
"/alpha/billing/subscriptions": { success: true, data: null },
|
||||
"/alpha/billing/credits": { credits: { monthlyCredits: 0, purchasedCredits: 7.25, freeCredits: 0 } },
|
||||
})
|
||||
expect(u).toEqual({ plan: "No plan", balance: "$7.25", windows: [] })
|
||||
expect(u).toEqual({ signIn: "kept", plan: "No plan", balance: "$7.25", windows: [] })
|
||||
})
|
||||
|
||||
test("Go: the month's $10 is the pool", async () => {
|
||||
@@ -61,7 +62,7 @@ test("Go: the month's $10 is the pool", async () => {
|
||||
"/alpha/billing/subscriptions": { data: { planId: "individual-go", status: "active" } },
|
||||
"/alpha/billing/credits": { credits: { monthlyCredits: 4 } },
|
||||
})
|
||||
expect(u).toEqual({ plan: "Go", windows: [{ name: "Credits", used: 60, display: "$6.00 / $10.00" }] })
|
||||
expect(u).toEqual({ signIn: "kept", plan: "Go", windows: [{ name: "Credits", used: 60, display: "$6.00 / $10.00" }] })
|
||||
})
|
||||
|
||||
test("credits that can't be read keep the plan and say why", async () => {
|
||||
@@ -69,15 +70,15 @@ test("credits that can't be read keep the plan and say why", async () => {
|
||||
"/alpha/billing/subscriptions": { data: { planId: "individual-pro-monthly", status: "active", cancelAtPeriodEnd: false } },
|
||||
"/alpha/billing/credits": 503,
|
||||
})
|
||||
expect(u).toEqual({ plan: "Pro", renew: "auto", error: "Service Unavailable", windows: [] })
|
||||
expect(u).toEqual({ signIn: "kept", plan: "Pro", renew: "auto", error: "Service Unavailable", windows: [] })
|
||||
})
|
||||
|
||||
test("a canceled subscription is No plan; an unread one leaves the plan unsaid", async () => {
|
||||
let { u } = await run(api, { "/alpha/billing/subscriptions": { data: { planId: "individual-pro", status: "canceled" } }, "/alpha/billing/credits": 413 })
|
||||
expect(u).toEqual({ plan: "No plan", error: "Request Entity Too Large", windows: [] })
|
||||
expect(u).toEqual({ signIn: "kept", plan: "No plan", error: "Request Entity Too Large", windows: [] })
|
||||
_internal.subsSeen.clear() // a plan read is kept ten minutes
|
||||
;({ u } = await run(api, { "/alpha/billing/subscriptions": 401, "/alpha/billing/credits": 401 }))
|
||||
expect(u).toEqual({ error: "Unauthorized", windows: [] })
|
||||
expect(u).toEqual({ signIn: "kept", error: "Unauthorized", windows: [] })
|
||||
})
|
||||
|
||||
test("seconds and string amounts read as magpie reads them; a half cent goes to the even one", async () => {
|
||||
@@ -86,6 +87,7 @@ test("seconds and string amounts read as magpie reads them; a half cent goes to
|
||||
"/alpha/billing/credits": { credits: { monthlyCredits: "29.875" }, windowLimits: { fiveHour: { used: "5", cap: 0 }, weekly: { used: 150, cap: "100", resetAt: 0 } } },
|
||||
})
|
||||
expect(u).toEqual({
|
||||
signIn: "kept",
|
||||
plan: "Pro",
|
||||
until: new Date(1790000000 * 1000).toISOString(),
|
||||
windows: [{ name: "Weekly", used: 100, span: 604800 }, { name: "Credits", used: 0.4166666666666667, display: "$0.12 / $30.00" }],
|
||||
@@ -93,7 +95,7 @@ test("seconds and string amounts read as magpie reads them; a half cent goes to
|
||||
})
|
||||
|
||||
test("a sign-in that isn't a key is no account", async () => {
|
||||
expect((await run({ type: "oauth" }, {})).u).toEqual({ error: "not signed in" })
|
||||
expect((await run({ type: "oauth" }, {})).u).toEqual({ signIn: "kept", error: "not signed in" })
|
||||
})
|
||||
|
||||
test("a slow subscription: the windows go without it, and the next card has it", async () => {
|
||||
@@ -111,11 +113,11 @@ test("a slow subscription: the windows go without it, and the next card has it",
|
||||
}
|
||||
const hooks = await CommandCodePlugin()
|
||||
const first = await hooks.auth.usage(async () => api)
|
||||
expect(first).toEqual({ windows: [{ name: "5 hours", used: 1, span: 18000 }] })
|
||||
expect(first).toEqual({ signIn: "kept", windows: [{ name: "5 hours", used: 1, span: 18000 }] })
|
||||
answer()
|
||||
await new Promise((r) => setTimeout(r, 20))
|
||||
const next = await hooks.auth.usage(async () => api)
|
||||
expect(next).toEqual({ plan: "GOAT", renew: "off", windows: [{ name: "5 hours", used: 1, span: 18000 }, { name: "Credits", used: 50, display: "$35.00 / $70.00" }] })
|
||||
expect(next).toEqual({ signIn: "kept", plan: "GOAT", renew: "off", windows: [{ name: "5 hours", used: 1, span: 18000 }, { name: "Credits", used: 50, display: "$35.00 / $70.00" }] })
|
||||
})
|
||||
|
||||
test("a plan read is saved with the key, once", async () => {
|
||||
@@ -148,7 +150,7 @@ test("a plan saved stands in for a subscription slow to read: waited for a momen
|
||||
const t = Date.now()
|
||||
const u = await hooks.auth.usage(async () => ({ ...api, metadata: { plan: "GOAT", planId: "individual-goat" } }))
|
||||
expect(Date.now() - t).toBeLessThan(3_000)
|
||||
expect(u).toEqual({ plan: "GOAT", windows: [{ name: "Credits", used: 50, display: "$35.00 / $70.00" }] })
|
||||
expect(u).toEqual({ signIn: "kept", plan: "GOAT", windows: [{ name: "Credits", used: 50, display: "$35.00 / $70.00" }] })
|
||||
answer()
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user