trae 0.2.40: an enterprise seat pool of nothing is an error naming what was read, not a blank card (#1143)

shex816's Trae CN enterprise account (#1143) shows in /v1/magpie/quotas
as {plan: "Enterprise", user: "Signed in", windows: []}: no error, no
window. That is ent.read when the console's seat pool is 0 (not
unlimited) and the credits page gives no row, so the card stood empty
with no word of why.

- Trae CN: with no window and no balance, the read is an error naming
  the pool and what the credits page did ("could not be read", "shows
  no allowance", "says unlimited").
- Trae Global: a pool of nothing is an error naming the pool.
- A pool of nothing beside a credits page with an allowance still shows
  the credits row, as before.

Run (mote, HOME=$(mktemp -d)):
- bun test in packages/trae: 277 pass, 0 fail.
- bun scripts/check.mjs trae: ok.

Broken by hand: 0.2.39's index.mjs with the new tests: 3 fail (the two
CN errors, the Global error); the credits-row test passes on both.

Not tried: shex816's real account (the pool of 0 is inferred from the
empty card's shape; their console answer is not in hand).
This commit is contained in:
yetone
2026-11-16 12:41:09 +08:00
parent 5a25075b91
commit 054876c9aa
4 changed files with 47 additions and 1 deletions
+31
View File
@@ -321,6 +321,37 @@ test("a console that names no seat pool is an error, not a blank card", async ()
expect(u.windows).toBeUndefined()
})
// #1143 (shex816): a seat pool of nothing and no credits row gave a card
// with a plan, a name and nothing else, and no word of why
for (const [how, credits, says] of [
["can't be read", () => json({ code: 0, message: "" }, 500), "could not be read"],
["shows no allowance", () => json({ is_credits_billing: true, user_entitlement_pack_list: [] }), "shows no allowance"],
]) {
test(`a seat pool of nothing, and a credits page that ${how}, is an error naming both`, async () => {
f = fakeTrae()
f.route("POST /trae/gtm/tob/api/v1/config/get_personal_quota", () => quota({ seat_pool_currency_quota: 0 }))
f.route("POST /trae/gtm/tob/api/v1/config/get_user_model_usage", () => spent([]))
f.route("POST /trae/gtm/tob/api/v1/config/get_personal_core_data", () => core())
f.route("POST /trae/api/v2/pay/ide_user_ent_usage", credits)
const hooks = await TraeCNAuthPlugin({ client: {} })
const u = await hooks.auth.usage(async () => signedIn({ host: ENT }))
expect(u.error).toBe(`Trae CN usage: the console gives this seat a pool of ¥0, and the credits page ${says}`)
expect(u.windows).toBeUndefined()
})
}
test("a seat pool of nothing beside a credits page with an allowance shows the credits", async () => {
f = fakeTrae()
f.route("POST /trae/gtm/tob/api/v1/config/get_personal_quota", () => quota({ seat_pool_currency_quota: 0 }))
f.route("POST /trae/gtm/tob/api/v1/config/get_user_model_usage", () => spent([]))
f.route("POST /trae/gtm/tob/api/v1/config/get_personal_core_data", () => core())
f.route("POST /trae/api/v2/pay/ide_user_ent_usage", () => page())
const hooks = await TraeCNAuthPlugin({ client: {} })
const u = await hooks.auth.usage(async () => signedIn({ host: ENT }))
expect(u.error).toBeUndefined()
expect(u.windows).toEqual([creditsWindow])
})
// an administrator's console answers with every seat in the tenant: the card
// counts the account's own, not the tenant's
test("an administrator's card counts its own seat, not the tenant's", async () => {
+9
View File
@@ -148,6 +148,15 @@ test("an international enterprise account reads the console's seat pool, in doll
expect(u.windows).toEqual([{ name: "Seat Usage", used: 20, display: "$20.00 / $100.00", amount: 20, limit: 100, unit: "usd", resetsAt: new Date(1796054400000).toISOString() }])
})
test("an international seat pool of nothing is an error, not a blank card (#1143)", async () => {
f = fakeTrae("trae-global")
f.route("POST /trae/gtm/tob/api/v1/config/get_personal_quota", () => json({ code: 0, message: "success", user_model_quota: { user_id: "u-1", seat_pool_currency_quota: 0, has_user_quota: true } }))
const hooks = await TraeGlobalAuthPlugin({ client: {} })
const u = await hooks.auth.usage(async () => signedIn({ host: "https://console.enterprise.trae.ai" }))
expect(u.error).toBe("Trae Global usage: the console gives this seat a pool of $0")
expect(u.windows).toBeUndefined()
})
// The international console is not known to take the IDE's own token — it
// answers 请先登录 to another realm's token exactly as it answers no token,
// so a refusal cannot be told from a lapsed sign-in. Marking the account
+6
View File
@@ -193,6 +193,10 @@ const SITES = {
windows.push(w)
}
if (windows.length) out.windows = windows
// a pool of nothing and no credits row leave the card nothing to
// show: it says what the console and the page answered rather
// than standing empty (#1143)
else if (!out.balance) return { error: `Trae CN usage: the console gives this seat a pool of ¥${q.limit}, and the credits page ${!page ? "could not be read" : c?.unlimited ? "says unlimited" : "shows no allowance"}`, signIn, user: a.name || a.uid }
return out
},
},
@@ -328,6 +332,8 @@ const SITES = {
const out = { plan: "Enterprise", user: a.name || a.uid, signIn }
if (q.unlimited) out.balance = "unlimited"
else if (q.limit > 0) out.windows = [seatUsageWindow(q, seatSpentOf(spent, quota?.user_model_quota?.user_id), entResetOf(core), DOLLARS, "usd")]
// a pool of nothing leaves the card nothing to show (#1143)
else return { error: `Trae Global usage: the console gives this seat a pool of $${q.limit}`, signIn, user: a.name || a.uid }
return out
},
},
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@magpie-community/opencode-trae-auth",
"version": "0.2.39",
"version": "0.2.40",
"description": "OpenCode provider plugins for Trae: Trae CN (trae.cn) and Trae Global (trae.ai), free tier included, with Trae's own browser sign-in",
"type": "module",
"main": "./opencode.mjs",