zcode 0.1.25: a key with no GLM Coding Plan says a ZCode gift plan (Start Plan, 1024 Dev Day) needs ZCode's sign-in

rtbeilin (X, 10-24) has ZCode 1024 Dev Day and no GLM Coding Plan.
"ZCode app's sign-in" works in magpie; the browser sign-in and the API
key don't.

The key: ZCode's gift plans are served by zcode.z.ai to ZCode's session
token (zcodejwttoken, the poll's `token`). A key carries none, so a key
reaches api.z.ai's / open.bigmodel.cn's coding plan alone, and a
gift-only account has nothing there. The card was empty, no error
(usage.test's own "API key, BigModel's" case: an empty list and no
limits gave {windows: []}), and each request got Z.ai's 1113 "no
resource package" with nothing saying why. Now:
- codingUsage: a subscription list read as having no VALID plan, with no
  level, no counted window and no saved plan, is the card's error
  NO_PLAN_KEY, which names the gift plans and says to add the account
  with "ZCode app's sign-in" or a ZCode browser sign-in. A list that
  can't be read keeps the card as it was.
- the fetch: a coding-plan refusal >= 400 to a sign-in with no ZCode
  session, whose code is 1113 (error.code, error.type or the envelope's
  code), keeps its status and Z.ai's words and adds NO_PLAN_KEY. The
  body is read only after the request failed. A sign-in with a session
  and any other code go as they came.
README says it under the key method.

The browser sign-in: no cause found. 3.16.3's bundle (the current
stable, downloaded from zcode.z.ai's release manifest) starts, polls
and reads the flow as the plugin does: same init body, the same
redirect / redirect_uri override, the same ready fields, Z.ai's token
exchanged at /api/auth/z/login. yg6888's screenshot in the same thread
shows two Dev Day accounts working in magpie. Not changed here.

Run:
- bun test packages/zcode, scratch HOME: 99 pass. The two new tests
  (usage "a key with no GLM Coding Plan...", signin "a key's 1113...")
  fail on 0.1.24's index.mjs. bun scripts/check.mjs zcode: ok.
- Real: the owner's real Z.ai key through the new usage hook: card
  "GLM Coding Lite", 5 hours + Weekly, no error. A bogus key: card
  "Authentication Failed", a request 401 {"error":{"message":
  "Authentication Failed","type":"1000"}} unchanged.

Not tried: a real key with no plan (none at hand), so the 1113 body is
magpie's zhipu_coding_test fixture, not a captured one. BigModel's real
answer neither. The browser sign-in with a Dev Day account.
This commit is contained in:
yetone
2026-10-24 16:37:39 +08:00
parent 663ce131cb
commit 71021b8f72
5 changed files with 112 additions and 4 deletions
+24 -2
View File
@@ -63,11 +63,33 @@ test("a Coding Plan's five hours and week", async () => {
})
expect(calls.every((c) => c.url.origin === "https://api.z.ai")).toBe(true)
// an API key, BigModel's, is asked on its own site
const bm = serve(({ url }) => (url.pathname.endsWith("/limit") ? ok({ limits: [] }) : ok([])))
expect(await usage({ type: "api", key: "k", metadata: { site: "bigmodel" } })).toEqual({ signIn: "kept", windows: [] })
const bm = serve(({ url }) => (url.pathname.endsWith("/limit") ? ok({ level: "lite", limits: [] }) : ok([{ productName: "GLM Coding Lite", status: "VALID" }])))
expect(await usage({ type: "api", key: "k", metadata: { site: "bigmodel" } })).toEqual({ signIn: "kept", plan: "GLM Coding Lite", windows: [] })
expect(bm[0].url.origin).toBe("https://open.bigmodel.cn")
})
// rtbeilin (X, 10-24): ZCode 1024 Dev Day, no GLM Coding Plan, "API Key
// doesn't work". The gift is ZCode's session's alone; a key's card says
// so instead of showing nothing
test("a key with no GLM Coding Plan says a ZCode gift plan needs ZCode's sign-in", async () => {
const none = /no GLM Coding Plan; ZCode's gift plans .* are spent only with ZCode's sign-in, never with a key/
for (const site of ["zai", "bigmodel"]) {
serve(({ url }) => (url.pathname.endsWith("/limit") ? ok({ limits: [] }) : ok([])))
expect((await usage({ type: "api", key: "k", metadata: { site } })).error).toMatch(none)
// a subscription that ran out is no plan in force either
serve(({ url }) => (url.pathname.endsWith("/limit") ? ok({ limits: [] }) : ok([{ productName: "GLM Coding Lite", status: "EXPIRED" }])))
expect((await usage({ type: "api", key: "k", metadata: { site } })).error).toMatch(none)
}
// a list that couldn't be read is not "no plan"
serve(({ url }) => (url.pathname.endsWith("/limit") ? ok({ limits: [] }) : new Response("", { status: 500 })))
expect(await usage({ type: "api", key: "k", metadata: { site: "zai" } })).toEqual({ signIn: "kept", windows: [] })
// a counted window or a level is a plan, whatever the list says
serve(({ url }) => (url.pathname.endsWith("/limit") ? ok({ limits: [{ unit: 3, number: 5, percentage: 3 }] }) : ok([])))
expect((await usage({ type: "api", key: "k", metadata: { site: "zai" } })).error).toBeUndefined()
serve(({ url }) => (url.pathname.endsWith("/limit") ? ok({ level: "pro", limits: [] }) : ok([])))
expect((await usage({ type: "api", key: "k", metadata: { site: "zai" } })).error).toBeUndefined()
})
test("windows, names and terms as Go reads them", () => {
const ws = _internal.limitWindows({ limits: [
{ unit: 3, usage: 1000, currentValue: 420, percentage: 42 }, // the percentage stands