qoder 0.2.45: a free account with no credits shows none left, not nothing

Ariel on Discord: an international free Qoder account signed in fine but
showed no credits. A free account (userType personal_standard, Qoder's
"Experience" plan) has a plan pool of 0 and, until it gets add-on credits,
nothing else. parseUsage drops every pool whose total is 0, so such an
account came out with no window at all and magpie had nothing to show.
Qoder's own client (Qoder.app's buildUsageItemGroups) shows every pool
present, 0/0 included, and counts the account out of credits when what the
pools have left adds up to 0. Now, when no pool gives a window and the plan,
add-on or shared pool reads a total of 0, the account has one "Credits"
window, "0 credits left", used up. A pool that can't be read (a string
total) or no pools at all still say nothing. An account with credits in any
pool is shown as before (the owner's free account: plan 0, add-on 7 / 600,
one Add-on window, unchanged). Same parser for qoder-cn.

Run: HOME=$(mktemp -d) bun test in packages/qoder on mote (299 pass) and
bun scripts/check.mjs qoder (ok).
Broken by hand: the new test against origin/main's index.mjs, red (it reads
no windows).
Read-only real read of the owner's intl account's /sash/api/v2/me/usage
for the envelope's shape (personal_standard, usageType credits, plan 0/0).
Not tried: Ariel's own account; the fixture is the owner's free envelope
with the add-on pool at 0 or absent, since the owner's has add-on credits.
This commit is contained in:
yetone
2026-10-28 12:34:33 +08:00
parent 1fb8d68c99
commit c0a0fd1955
3 changed files with 36 additions and 1 deletions
+9
View File
@@ -2179,6 +2179,15 @@ function parseUsage(env) {
}
const dedicated = field("dedicatedResourcePackages", "dedicated_resource_packages")
for (const b of Array.isArray(dedicated) ? dedicated : []) add(b, "Dedicated credits")
// A free account (personal_standard) with no add-on credits has a plan of
// 0 and nothing else: Qoder's client shows that pool as 0/0 and counts the
// account as out of credits. Without a window of its own magpie showed no
// credits at all (Ariel on Discord), so it reads as none left.
if (out.windows.length === 0) {
const zero = (b) => b !== null && typeof b === "object" && !Array.isArray(b) && (b.total ?? b.cap) === 0
const pools = [field("userQuota", "user_quota"), field("addOnQuota", "add_on_quota"), field("orgResourcePackage", "org_resource_package")]
if (pools.some(zero)) out.windows.push({ name: "Credits", used: 100, display: "0 credits left" })
}
return out
}
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@magpie-community/opencode-qoder-auth",
"version": "0.2.44",
"version": "0.2.45",
"description": "Qoder and QwenWork (千问办公) subscriptions in OpenCode and magpie: qoder.com, qoder.cn, gateway.qwenwork.cn and the enterprise flagship (VPC)",
"type": "module",
"main": "./index.mjs",
+26
View File
@@ -527,3 +527,29 @@ test("a job token the models hook renewed is said renewed by the next answer", a
const again = await l.fetch(API_CHAT, { method: "POST", body: JSON.stringify({ model: "nomodel", messages: [] }) })
expect(again.headers.get("X-Magpie-Sign-In")).toBe(null)
})
// Ariel on Discord: an international free account (personal_standard) signed
// in but showed no credits. Its envelope is the owner's free account's
// (2026-10-28, read-only) with no add-on credits: a plan of 0 beside add-on
// credits of 0, or none at all. Qoder's client shows it 0/0, out of credits.
test("a free account with no credits shows none left, not nothing", () => {
const free = (extra) => ({
displayMode: "qoder",
qoderUsage: {
userType: "personal_standard",
usageType: "credits",
totalUsagePercentage: 0,
isQuotaExceeded: true,
expiresAt: 253402214400000,
userQuota: { total: 0, used: 0, remaining: 0, percentage: 0, unit: "credits" },
...extra,
isPlanQuotaProrated: false,
},
})
const none = [{ name: "Credits", used: 100, display: "0 credits left" }]
expect(_internal.parseUsage(free({})).windows).toEqual(none)
expect(_internal.parseUsage(free({ addOnQuota: { total: 0, used: 0, remaining: 0, percentage: 0, unit: "credits" } })).windows).toEqual(none)
// a pool that can't be read is no word that the account has none
expect(_internal.parseUsage({ displayMode: "qoder", qoderUsage: { userType: "personal_standard", userQuota: { total: "0" } } }).windows).toEqual([])
expect(_internal.parseUsage({ displayMode: "qoder", qoderUsage: { userType: "personal_standard" } }).windows).toEqual([])
})