zcode 0.1.37: an account with no gift plan to claim is no check-in event, not a failed check-in
hykql (Discord, magpie v0.1.2143, zcode 0.1.36) saw every ZCode account's
daily check-in fail with "gift plans to claim: no plan list in the reply",
a Start Plan account and one with no GLM Coding Plan alike. ZCode's
GET /billing/preview answers an account with nothing to claim with no
data at all, not data.plans []:
{"code":0,"msg":"","logid":"202610300535585c4e3de75769b684da87"}
(the owner's account, read 10-30 with GETs only, with and without the
X-ZCode-App-Version / X-Platform headers; both the same). #503's capture
of 10-29 had "plans": [], so 0.1.35 took a missing list as unreadable.
previewPlans now reads the list for both the claim and the card's claim
line: no data, data null, or data without plans (or plans null) is a
list of none, so the check-in is "inactive" (magpie shows "No check-in
event now"). call has already judged the code, so only a code 0 reply
gets here. Data that isn't an object, or plans that aren't a list, still
don't read and stay failed, never claimed.
Run (wsl-run on magpie-desktop, HOME=$(mktemp -d); mote was at load
220-250): `bun test` in packages/zcode, 152 pass 0 fail; the whole
repo's `bun test`, 3720 pass 0 fail of 3727 across 298 files;
`bun scripts/check.mjs zcode` ok. The new checkin test (the real
no-data reply, data null, data without plans, plans null) is red on
0.1.36's index.mjs (1 fail). Broken by hand: plans that aren't a list
read as none turns "a preview that doesn't read is failed" red; put
back, green.
Not tried: a real claim (no account has a plan to claim now), and the
official ZCode client's own parse of this reply (no ZCode app on hand);
the fixture is the vendor's real bytes. Not changed: #505 (freeFirst)
touches other parts of index.mjs.
This commit is contained in:
@@ -216,7 +216,8 @@ reads the app's preview list and posts each plan it lists to
|
||||
account's ZCode session, as the app does. The answer is judged by the
|
||||
body's code, not the HTTP status:
|
||||
|
||||
- nothing listed: *inactive*;
|
||||
- nothing listed: *inactive* (ZCode answers an account with nothing to
|
||||
claim `{"code":0,"msg":""}`, with no list at all);
|
||||
- code 0: *claimed* (the next request uses the plan);
|
||||
- code 1003 "target already exists" (HTTP 200): *done*, claimed before;
|
||||
- code 3007 "captcha verify failed": *captcha*, the plan is claimed in
|
||||
|
||||
@@ -46,6 +46,9 @@ async function checkin(auth = SIGNED_IN) {
|
||||
|
||||
// #503: the preview of an account with nothing to claim
|
||||
const PREVIEW_NONE = '{"code":0,"msg":"","data":{"plans":[],"server_time":1793318263}}'
|
||||
// 10-30 (the owner's account, read for hykql's report on Discord): the
|
||||
// preview of an account with nothing to claim carries no data at all
|
||||
const PREVIEW_NO_DATA = '{"code":0,"msg":"","logid":"202610300535585c4e3de75769b684da87"}'
|
||||
// usage.test.mjs's real preview, the day's ZCode Trust Build unclaimed
|
||||
const PREVIEW_ONE = {
|
||||
code: 0, msg: "",
|
||||
@@ -143,11 +146,20 @@ test("a claim that doesn't read is failed (unknown), never claimed", async () =>
|
||||
}
|
||||
})
|
||||
|
||||
test("a preview with nothing in it is nothing to claim, not a failed check-in", async () => {
|
||||
for (const body of [PREVIEW_NO_DATA, '{"code":0,"msg":"","data":null}', '{"code":0,"msg":"","data":{"server_time":1793318263}}', '{"code":0,"msg":"","data":{"plans":null}}']) {
|
||||
const calls = serve(({ url }) => (url.pathname === PREVIEW ? json(body) : json(CLAIMED_NOW)))
|
||||
expect(await checkin()).toEqual({ outcome: "inactive", message: "no ZCode gift plan to claim" })
|
||||
expect(claims(calls)).toEqual([])
|
||||
}
|
||||
})
|
||||
|
||||
test("a preview that doesn't read is failed (unknown), and nothing is claimed", async () => {
|
||||
for (const answer of [
|
||||
() => json("", 500),
|
||||
() => json("garbled"),
|
||||
() => json('{"code":0,"data":{}}'), // no plan list
|
||||
() => json('{"code":0,"data":{"plans":"zcode-v3-start-plan-1029"}}'), // a plan list that isn't a list
|
||||
() => json('{"code":0,"data":"plans"}'), // data that isn't an object
|
||||
() => json('{"code":401,"msg":"token invalid"}', 401),
|
||||
() => { throw new Error("no network in tests") },
|
||||
]) {
|
||||
|
||||
@@ -663,7 +663,7 @@ async function claimHint(s) {
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
const plans = (Array.isArray(d?.plans) ? d.plans : []).filter((p) => typeof p?.plan_id === "string" && p.plan_id.trim())
|
||||
const plans = (previewPlans(d) ?? []).filter((p) => typeof p?.plan_id === "string" && p.plan_id.trim())
|
||||
if (!plans.length) return null
|
||||
const n = plans.length
|
||||
const plan = first(...plans.map((p) => (typeof p?.name === "string" ? p.name : "")), "ZCode gift plan")
|
||||
@@ -718,6 +718,20 @@ async function claimOne(s, planID) {
|
||||
return { outcome: "failed", why: `${msg || "error"} (HTTP ${res.status}, code ${code})` }
|
||||
}
|
||||
|
||||
// previewPlans is /billing/preview's plan list. An account with nothing to
|
||||
// claim is answered {"code":0,"msg":"","logid":…}: no data at all, not
|
||||
// "plans": [] (the owner's account read 10-30 for hykql's report on
|
||||
// Discord; the list is left out when it is empty). call has already judged the code, so a reply
|
||||
// without data, or data without plans, is a list of none. Only data that
|
||||
// isn't an object, or plans that are there and aren't a list, don't read
|
||||
// (null, unknown).
|
||||
function previewPlans(d) {
|
||||
if (d == null) return []
|
||||
if (typeof d !== "object" || Array.isArray(d)) return null
|
||||
if (d.plans == null) return []
|
||||
return Array.isArray(d.plans) ? d.plans : null
|
||||
}
|
||||
|
||||
// claimDaily claims every gift plan ZCode's preview lists for the account
|
||||
// (#503), as auth.checkin's answer: inactive when it lists none, claimed
|
||||
// when one was claimed now, done when each was claimed before, captcha
|
||||
@@ -734,8 +748,9 @@ async function claimDaily(s) {
|
||||
} catch (e) {
|
||||
return { outcome: "failed", message: `gift plans to claim: ${e?.message ?? String(e)}` }
|
||||
}
|
||||
if (!Array.isArray(d?.plans)) return { outcome: "failed", message: "gift plans to claim: no plan list in the reply" }
|
||||
const plans = d.plans.filter((p) => typeof p?.plan_id === "string" && p.plan_id.trim())
|
||||
const listed = previewPlans(d)
|
||||
if (!listed) return { outcome: "failed", message: "gift plans to claim: the plan list doesn't read" }
|
||||
const plans = listed.filter((p) => typeof p?.plan_id === "string" && p.plan_id.trim())
|
||||
if (!plans.length) return { outcome: "inactive", message: "no ZCode gift plan to claim" }
|
||||
const got = []
|
||||
for (const p of plans) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@magpie-community/opencode-zcode-auth",
|
||||
"version": "0.1.36",
|
||||
"version": "0.1.37",
|
||||
"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",
|
||||
|
||||
Reference in New Issue
Block a user