From 63748b9d67ff546b2bef249af52dda0dd8a74ea6 Mon Sep 17 00:00:00 2001 From: yetone Date: Fri, 30 Oct 2026 10:31:28 +0800 Subject: [PATCH] zcode 0.1.36: a gift bucket beside a Coding Plan is named by its model first (#504) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Danbuth's GLM Coding Max account had claimed ZCode's Start Plan (plan_id zcode-v3-start-plan-1029, named "ZCODE GLOBAL BUILD") and found no Start Plan on magpie's card. The plugin did read it: usage asks /billing/balance beside /quota/limit and adds every live gift plan's buckets after the Coding windows, whatever the plan type, every plan and not only the first. The bucket was the panel's third ring, named "ZCODE GLOBAL BUILD · GLM-5.3-Trial", which magpie's ring and account row cut to "ZCODE GLOBAL BUI…": neither the model nor the plan's kind. ZCode 3.16.3's own popover (host getStartPlanSnapshot, renderer "Today's balance") lists these buckets by show_name, apart from the Coding Plan's windows. So a gift bucket's name now starts with that (the picker's -Trial id when it counts a model) and the plan follows: "GLM-5.3-Trial · ZCODE GLOBAL BUILD". A gift-only account with several plans names them the same way round. Run (on mote, HOME=$(mktemp -d)): `bun test packages/zcode`, 151 pass 0 fail; `bun scripts/check.mjs`, every package ok, exit 0. The new test uses a real /quota/limit reply (owner's account, read in a sandbox HOME copy with GETs only) and the real ZCODE GLOBAL BUILD plan row from #503, times moved to now. Broken by hand (old label order): the new test and five others red; put back, green. Not tried: a real balance of the ZCODE GLOBAL BUILD plan (the owner's account has none), so its buckets take the shape of ganlerk's Start Plan balance. Not changed: magpie's tray panel shows at most three rings and the account row two windows, so beside a Coding Plan's 5h and weekly only the first gift bucket is on the panel; the rest are in the tooltip and on the Usage page. --- packages/zcode/README.md | 9 ++++--- packages/zcode/dual.test.mjs | 4 +-- packages/zcode/gift.test.mjs | 46 ++++++++++++++++++++++++++------- packages/zcode/index.mjs | 14 ++++++---- packages/zcode/package.json | 2 +- packages/zcode/pending.test.mjs | 2 +- packages/zcode/usage.test.mjs | 2 +- 7 files changed, 57 insertions(+), 22 deletions(-) diff --git a/packages/zcode/README.md b/packages/zcode/README.md index bc7257d..0f2b9d5 100644 --- a/packages/zcode/README.md +++ b/packages/zcode/README.md @@ -166,9 +166,12 @@ and end. The card's plan and term stay the coding plan's. A gift read that fails leaves just the coding card — magpie hides a card's windows behind an error, so a gift hiccup must not black out a working Coding Plan. A gift that goes out of date while requests use it simply stops -showing. Beside the coding plan's windows each gift bucket is named -after its plan ("Start Plan · GLM-5.1-Trial"), one plan or several, so -the two allowances can't be read as one. +showing. Beside the coding plan's windows each gift bucket is named by +its model first, as ZCode's own "Today's balance" lists it, then by its +plan ("GLM-5.1-Trial · Start Plan"), one plan or several, so the two +allowances can't be read as one. The model comes first because magpie's +ring and account row cut a long name short: "ZCODE GLOBAL BUI…" (the +Start Plan claimed on 10-29) said neither (#504). **Gift plans that start later.** A plan on the balance whose `starts_at` is still to come (a Start Plan taking effect at 23:00 today) serves diff --git a/packages/zcode/dual.test.mjs b/packages/zcode/dual.test.mjs index bf96759..4c9290e 100644 --- a/packages/zcode/dual.test.mjs +++ b/packages/zcode/dual.test.mjs @@ -198,7 +198,7 @@ test("the card shows the Coding windows and the gift's buckets together", async expect(u.plan).toBe("GLM Coding Pro") expect(u.signIn).toBe("kept") expect(u.error).toBeUndefined() - expect(u.windows.map((w) => w.name)).toEqual(["5 hours", "Start Plan · Trust Build"]) + expect(u.windows.map((w) => w.name)).toEqual(["5 hours", "Trust Build · Start Plan"]) expect(u.windows[1]).toMatchObject({ used: 25, display: "250 / 1000", models: ["GLM-5.3-Flash-Trial"] }) expect(u.until).toBeUndefined() expect(u.renew).toBeUndefined() @@ -381,7 +381,7 @@ test("every live plan spends first by its buckets' models, and the card shows th // the card shows both plans' live buckets, spent ones included, none of the // ended plan's, each named after its plan as there are two const u = await (await hooks()).usage(async () => coding, { id: "zcode" }) - expect(u.windows.map((w) => w.name)).toEqual(["5 hours", "Start Plan · Trust Build", "GLM Festival Grant · GLM-5.2-Trial", "GLM Festival Grant · GLM-5.2 late"]) + expect(u.windows.map((w) => w.name)).toEqual(["5 hours", "Trust Build · Start Plan", "GLM-5.2-Trial · GLM Festival Grant", "GLM-5.2 late · GLM Festival Grant"]) expect(u.windows.some((w) => w.name === "Old")).toBe(false) expect(u.windows[0].notModels).toEqual(["glm-5.3-flash-trial", "glm-5.2-trial"]) expect(u.windows.at(-1).aside).toBe(true) // a spent sibling cannot cap a live bucket diff --git a/packages/zcode/gift.test.mjs b/packages/zcode/gift.test.mjs index e4f904b..d9e3f2c 100644 --- a/packages/zcode/gift.test.mjs +++ b/packages/zcode/gift.test.mjs @@ -208,7 +208,7 @@ test("a gift-only account's spent Start Plan bucket doesn't hold up a model its } expect(counting("GLM-5.3")[0].used).toBe(0) // the spent bucket is still on the card, as ZCode shows it - expect(u.windows.find((w) => w.used === 100)).toMatchObject({ name: "ZCode Start Plan · GLM-5.3-Flash", aside: true }) + expect(u.windows.find((w) => w.used === 100)).toMatchObject({ name: "GLM-5.3-Flash · ZCode Start Plan", aside: true }) expect(u.windows).toHaveLength(3) }) @@ -273,13 +273,13 @@ test("two gift plans' GLM-5.3 each show, named by plan, the live one first (01hu const names = u.windows.map((w) => w.name) expect(new Set(names).size).toBe(names.length) // the 1024 plan's GLM-5.3 shows its own amount left, and counts the model - expect(u.windows.find((w) => w.name === "ZCode 1024 Dev Day · GLM-5.3")).toMatchObject({ used: 25, amount: 50_000_000, limit: 200_000_000, models: ["glm-5.3", "GLM-5.3-Trial"] }) - expect(u.windows.find((w) => w.name === "ZCode 1024 Dev Day · GLM-5.3").aside).toBeUndefined() + expect(u.windows.find((w) => w.name === "GLM-5.3 · ZCode 1024 Dev Day")).toMatchObject({ used: 25, amount: 50_000_000, limit: 200_000_000, models: ["glm-5.3", "GLM-5.3-Trial"] }) + expect(u.windows.find((w) => w.name === "GLM-5.3 · ZCode 1024 Dev Day").aside).toBeUndefined() // the spent new-user plan's GLM-5.3 still shows, used up, set aside - expect(u.windows.find((w) => w.name === "ZCode Start Plan · GLM-5.3")).toMatchObject({ used: 100, amount: 3_000_000, aside: true }) + expect(u.windows.find((w) => w.name === "GLM-5.3 · ZCode Start Plan")).toMatchObject({ used: 100, amount: 3_000_000, aside: true }) // magpie's account row shows a card's first two windows: what is spent now expect(u.windows.slice(0, 2).every((w) => !w.aside)).toBe(true) - expect(u.windows.slice(0, 2).some((w) => w.name === "ZCode 1024 Dev Day · GLM-5.3")).toBe(true) + expect(u.windows.slice(0, 2).some((w) => w.name === "GLM-5.3 · ZCode 1024 Dev Day")).toBe(true) }) test("a coding plan account's two gift plans' GLM-5.3 each show, named by plan", async () => { @@ -287,10 +287,10 @@ test("a coding plan account's two gift plans' GLM-5.3 each show, named by plan", const u = await (await hooks()).auth.usage(async () => auth, { id: "zcode" }) const gift = u.windows.slice(1) expect(gift.map((w) => w.name)).toEqual([ - "ZCode Start Plan · GLM-5.3-Flash-Trial", - "ZCode 1024 Dev Day · GLM-5.3-Trial", - "ZCode Start Plan · GLM-5.3", - "ZCode 1024 Dev Day · GLM-5.3-Flash", + "GLM-5.3-Flash-Trial · ZCode Start Plan", + "GLM-5.3-Trial · ZCode 1024 Dev Day", + "GLM-5.3 · ZCode Start Plan", + "GLM-5.3-Flash · ZCode 1024 Dev Day", ]) expect(gift[1]).toMatchObject({ used: 25, models: ["GLM-5.3-Trial"] }) expect(gift[2]).toMatchObject({ used: 100, aside: true }) @@ -355,3 +355,31 @@ test("a coding plan with no live ZCode session says its gift plans need ZCode's expect(line(live)).toBeUndefined() expect(live.windows.some((w) => w.name.includes("-Trial") || (w.models ?? []).some((m) => m.endsWith("-Trial")))).toBe(true) }) + +// Danbuth (plugins#504): a GLM Coding Max account that claimed ZCode's +// Start Plan (plan_id zcode-v3-start-plan-1029, named "ZCODE GLOBAL +// BUILD") found no Start Plan on the card. It was there, as the third +// window, but magpie's ring and account row cut a long name short and +// "ZCODE GLOBAL BUI…" named neither the model nor the plan's kind. The +// Coding windows are a real /quota/limit reply (the owner's account, 10-30); +// the plan row is the real /billing/balance plan kongbai01203 read in +// #503, its times moved to now; its buckets have the shape of ganlerk's +// Start Plan balance (no balance of this plan was read). ZCode's own +// "Today's balance" lists a bucket by its show_name, so the window's name +// starts with it and the plan follows. +test("a coding plan account's ZCODE GLOBAL BUILD gift is named by its model first (Danbuth, #504)", async () => { + const limit = { limits: [{ type: "CREDIT_LIMIT", unit: 3, number: 5, usage: 2000, currentValue: 0, remaining: 2000, percentage: 0 }, { type: "CREDIT_LIMIT", unit: 6, number: 1, usage: 10000, currentValue: 68, remaining: 9931, percentage: 1, nextResetTime: (now + 86400) * 1000 }], level: "lite" } + const mocked = globalThis.fetch + globalThis.fetch = async (input, init) => new URL(String(input)).pathname === "/api/monitor/usage/quota/limit" + ? new Response(JSON.stringify({ code: 200, msg: "Operation successful", data: limit, success: true }), { headers: { "content-type": "application/json" } }) + : mocked(input, init) + balance.plans = [{ plan_id: "zcode-v3-start-plan-1029", name: "ZCODE GLOBAL BUILD", status: "active", starts_at: now - 45440, ends_at: now + 3737 }] + balance.balances = [ + { plan_id: "zcode-v3-start-plan-1029", show_name: "GLM-5.3", capabilities: ["model:GLM-5.3"], total_units: 3_000_000, used_units: 450_000, remaining_units: 2_550_000 }, + { plan_id: "zcode-v3-start-plan-1029", show_name: "GLM-5.3-Flash", capabilities: ["model:GLM-5.3-Flash"], total_units: 5_000_000, used_units: 0, remaining_units: 5_000_000 }, + ] + const u = await (await hooks()).auth.usage(async () => auth, { id: "zcode" }) + expect(u.windows.map((w) => w.name)).toEqual(["5 hours", "Weekly", "GLM-5.3-Trial · ZCODE GLOBAL BUILD", "GLM-5.3-Flash-Trial · ZCODE GLOBAL BUILD"]) + expect(u.windows[2]).toMatchObject({ used: 15, amount: 450_000, limit: 3_000_000, models: ["GLM-5.3-Trial"] }) + expect(u.windows[3]).toMatchObject({ used: 0, limit: 5_000_000, models: ["GLM-5.3-Flash-Trial"] }) +}) diff --git a/packages/zcode/index.mjs b/packages/zcode/index.mjs index 09045e5..f51faf5 100644 --- a/packages/zcode/index.mjs +++ b/packages/zcode/index.mjs @@ -800,7 +800,7 @@ async function startUsage(s) { return g } -// byPlan names a bucket after its plan ("ZCode 1024 Dev Day · GLM-5.3") +// byPlan names a bucket after its plan ("GLM-5.3 · ZCode 1024 Dev Day") // when the gift's buckets come from more than one plan: two plans each // give a GLM-5.3, and named alike a spent one and a live one can't be // told apart (01huadalang, Discord: the new-user plan's spent GLM-5.3 @@ -808,7 +808,7 @@ async function startUsage(s) { // their own names, as the card's header names the plan. function byPlan(windows) { const several = new Set(windows.map((w) => w._plan || "")).size > 1 - return (name, plan) => (several && plan ? plan + " · " + name : name) + return (name, plan) => (several && plan ? name + " · " + plan : name) } // countedFirst puts the buckets a request spends before those set aside @@ -869,9 +869,13 @@ async function dualUsage(s, out) { // Several buckets may serve one model: one spent sibling cannot block it. const best = bestBuckets(g.windows) // beside the Coding Plan's windows every gift bucket is named after - // its plan, one plan or several: "Start Plan · GLM-5.1-Trial" can't - // be read as the Coding Plan's own (windy, Discord) - const label = (name, plan) => first(plan, "Start Plan") + " · " + name + // its plan, one plan or several: "GLM-5.1-Trial · Start Plan" can't + // be read as the Coding Plan's own (windy, Discord). The bucket's + // own name (ZCode's show_name, as its "Today's balance" lists it) + // comes first: magpie's ring and account row cut a long name short, + // and "ZCODE GLOBAL BUI…" said neither the model nor the plan's + // kind, so the Start Plan read as missing (Danbuth, plugins#504) + const label = (name, plan) => name + " · " + first(plan, "Start Plan") out.windows.push(...countedFirst(g.windows.map(({ _plan: p, _spent, ...w }, i) => { const selected = gift.allModels.filter((m) => best.get(m.toLowerCase()) === i) const models = selected.map(giftID) diff --git a/packages/zcode/package.json b/packages/zcode/package.json index 561f2f4..6d18b68 100644 --- a/packages/zcode/package.json +++ b/packages/zcode/package.json @@ -1,6 +1,6 @@ { "name": "@magpie-community/opencode-zcode-auth", - "version": "0.1.35", + "version": "0.1.36", "description": "OpenCode provider plugin: signs in to Z.ai's or BigModel's (智谱) GLM Coding Plan as ZCode does, including team seats and ZCode's Start Plan, and claims its gift plans daily", "type": "module", "main": "./index.mjs", diff --git a/packages/zcode/pending.test.mjs b/packages/zcode/pending.test.mjs index db24a92..048e6ff 100644 --- a/packages/zcode/pending.test.mjs +++ b/packages/zcode/pending.test.mjs @@ -90,7 +90,7 @@ for (const status of ["active", "pending_unknown_word"]) { test("beside the Coding Plan, a live gift's buckets carry their plan's name, and the next plan its start", async () => { zcode({ plans: [live, next("active")], balances: [bucket("up1", 400), bucket("up2", 1000)] }, true) const u = await usage(codingAuth()) - expect(u.windows.map((w) => w.name)).toEqual(["5 hours", "Start Plan · GLM-5.1-Trial", PENDING]) + expect(u.windows.map((w) => w.name)).toEqual(["5 hours", "GLM-5.1-Trial · Start Plan", PENDING]) // the live plan's bucket is the one counted; the coming plan's full one isn't expect(u.windows[1]).toMatchObject({ used: 60, display: "600 / 1000", models: ["GLM-5.1-Trial"] }) expect(u.windows[2]).toEqual({ name: PENDING, used: 0, aside: true, display: `Start Plan · ${local(later)}` }) diff --git a/packages/zcode/usage.test.mjs b/packages/zcode/usage.test.mjs index a7a10d7..bc6727d 100644 --- a/packages/zcode/usage.test.mjs +++ b/packages/zcode/usage.test.mjs @@ -467,7 +467,7 @@ test("a coding account's line goes after its coding and gift windows", async () const auth = oauth({ site: "zai", key: "k", jwt: token, device: "d" }) const u = await usage(auth) expect(u.plan).toBe("GLM Coding Pro") - expect(u.windows.map((w) => w.name)).toEqual(["5 hours", "Start Plan · GLM-5.1-Trial", "Gift plans to claim in the ZCode app"]) + expect(u.windows.map((w) => w.name)).toEqual(["5 hours", "GLM-5.1-Trial · Start Plan", "Gift plans to claim in the ZCode app"]) expect(u.windows.at(-1)).toEqual(TRUST_BUILD) expect(calls.filter((c) => c.url.pathname.endsWith("/preview"))).toHaveLength(1) })