diff --git a/packages/trae/enterprise.test.mjs b/packages/trae/enterprise.test.mjs index f0ce549..dc298fb 100644 --- a/packages/trae/enterprise.test.mjs +++ b/packages/trae/enterprise.test.mjs @@ -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 () => { diff --git a/packages/trae/global.test.mjs b/packages/trae/global.test.mjs index a071128..703f046 100644 --- a/packages/trae/global.test.mjs +++ b/packages/trae/global.test.mjs @@ -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 diff --git a/packages/trae/index.mjs b/packages/trae/index.mjs index 9a1aecd..905307e 100644 --- a/packages/trae/index.mjs +++ b/packages/trae/index.mjs @@ -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 }, }, diff --git a/packages/trae/package.json b/packages/trae/package.json index f2a1e03..d4c0abe 100644 --- a/packages/trae/package.json +++ b/packages/trae/package.json @@ -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",