zcode 0.1.45: the daily claim reads the feed as the current client does (#678)
The marketing feed (touch) and the claim now go out under ZCode 3.17.2's version header. jinpy666 found that under the pinned 3.16.3 the feed answers empty, while under 3.17.2 the day's banner shows, and checked it against the live API. The check-in no longer reads /billing/preview, which the v3.17 client doesn't poll (docs/marketing-touch-client.md in zai-org/ZCode@a9fe401). Reviewed at f805d97 and run there on mote: - bun test packages/zcode: 187 pass, 0 fail. - bun scripts/check.mjs: clean. - Broken by hand: with MARKETING_VERSION set back to 3.16.3, 4 tests go red (the touch and claim version pins, and the card's feed read). Not tried here: a live feed or claim. No ZCode account was in a sandbox, so the live run is jinpy666's (10 accounts: 7 captcha, 3 inactive). Reported by jinpy666 (#676), who wrote the fix.
This commit is contained in:
@@ -356,31 +356,35 @@ test("a model ZCode's config gives no limits has none made up", () => {
|
||||
expect(_internal.entry({ id: "GLM-9", context: 300_000, output: 8_000, efforts: [] }).limit).toEqual({ context: 300_000, output: 8_000 })
|
||||
})
|
||||
|
||||
// The ZCode app's own list of manual-claim gift plans: GET /billing/preview
|
||||
// is read with the usage card, and a plan it lists that the balance does not
|
||||
// hold is named on the card, to be claimed in the ZCode app (the claim needs
|
||||
// the app's captcha attestation, see claimHint). Both fixtures are real
|
||||
// responses: one account's preview while the day's ZCode Trust Build was
|
||||
// still unclaimed, and one after it had claimed it. Reading the card never asks
|
||||
// the claim endpoint. The window's name is the fixed sentence magpie
|
||||
// translates; the count and the plan's own name are the display.
|
||||
const PREVIEW_CLAIMABLE = {
|
||||
// The ZCode app's list of claimable gift plans is its marketing feed
|
||||
// (touch; see checkin.test.mjs). The v3.17 client reads the feed alone —
|
||||
// the old preview polling is gone — and the rewards center's gifts are
|
||||
// the rewards website's, claimed in the client. Two fixtures: the day's
|
||||
// ZCode Trust Build still in the feed, and the feed after it was claimed.
|
||||
// Reading the card never asks the claim endpoint. The window's name is
|
||||
// the fixed sentence magpie translates; the count and the plan's own
|
||||
// name are the display.
|
||||
const TOUCH_TRUST = {
|
||||
server_time: 1791216750,
|
||||
plans: [{
|
||||
user_plan_id: "upl_2107141892427358208", plan_id: "zcode-v3-start-plan-trust-1006", name: "ZCode Trust Build",
|
||||
description: "ZCode Global Build", priority: 110, status: "active", starts_at: 1791216750, ends_at: 1791302400,
|
||||
entitlements: [{ entitlement_id: "zcode-v3-start-plan-trust-1006", show_name: "GLM-5.3-Flash", meter: "model_usage",
|
||||
unit_type: "token", capabilities: ["model:glm-5.3-flash"], grant_units: 100000000, period: "one_time", priority: 110, effective_at: 0 }],
|
||||
deliveries: [{
|
||||
campaign_id: "2101141259813175296", priority: 100, resource_position: "banner",
|
||||
banner: {
|
||||
layout: "",
|
||||
background: { type: "zcode_plan", args: { zcode_plan: { plan_id: "zcode-v3-start-plan-trust-1006", name: "ZCode Trust Build", grant_units: 100000000, period: "one_time" } } },
|
||||
buttons: [
|
||||
{ text: { format: "", content: "领取" }, action: { type: "claim_zcode_plan", args: { plan_id: "zcode-v3-start-plan-trust-1006" } } },
|
||||
{ text: { format: "", content: "关闭" }, action: { type: "close" } },
|
||||
],
|
||||
},
|
||||
}],
|
||||
}
|
||||
const PREVIEW_CLAIMED = { server_time: 1791276990, plans: [] }
|
||||
const TRUST_BUILD = { name: "Gift plans to claim in the ZCode app", used: 0, aside: true, display: "1 · ZCode Trust Build" }
|
||||
|
||||
// the Start Plan's own card, with the preview answering what preview says
|
||||
async function startCard(now, token, preview) {
|
||||
// the Start Plan's own card, with the feed answering what the app reads
|
||||
async function startCard(now, token, touch) {
|
||||
const calls = serve(({ url }) => {
|
||||
if (url.pathname === "/api/v1/zcode-plan/billing/balance") return ok(startBalance(now, "active"))
|
||||
if (url.pathname === "/api/v1/zcode-plan/billing/preview") return preview(calls)
|
||||
if (url.pathname === "/api/v1/marketing/touch") return touch(calls)
|
||||
})
|
||||
const auth = oauth({ site: "zai", jwt: token, device: "11111111-2222-4333-8444-555555555555" })
|
||||
return { u: await usage(auth), calls }
|
||||
@@ -389,7 +393,7 @@ async function startCard(now, token, preview) {
|
||||
test("a gift plan ZCode holds but has not granted is named on the card, to claim in the app", async () => {
|
||||
const now = Math.trunc(Date.now() / 1000)
|
||||
const token = jwt(now + 86400)
|
||||
const { u, calls } = await startCard(now, token, () => ok(PREVIEW_CLAIMABLE))
|
||||
const { u, calls } = await startCard(now, token, () => ok(TOUCH_TRUST))
|
||||
expect(u.windows).toEqual([
|
||||
{ name: "GLM-5.1", used: 25, display: "250000 / 1000000", amount: 250000, limit: 1000000, resetsAt: new Date((now + 3600) * 1000).toISOString(), span: 86400,
|
||||
models: ["GLM-5.1", "GLM-5.1-Trial"] },
|
||||
@@ -397,15 +401,18 @@ test("a gift plan ZCode holds but has not granted is named on the card, to claim
|
||||
])
|
||||
// it is no allowance: set aside, so routing, caps and the menu bar pass it over
|
||||
expect(u.windows.at(-1).aside).toBe(true)
|
||||
// the preview went out as ZCode's own client asks it
|
||||
const p = calls.find((c) => c.url.pathname.endsWith("/preview"))
|
||||
expect(p.method).toBe("GET")
|
||||
expect(p.url.searchParams.get("app_version")).toBe("3.16.3")
|
||||
expect(p.url.searchParams.get("platform")).toBe(`${process.platform}-${process.arch}`)
|
||||
expect(p.headers.Authorization).toBe("Bearer " + token)
|
||||
expect(p.headers["X-Device-Mid"]).toBe("11111111-2222-4333-8444-555555555555")
|
||||
// the feed went out as ZCode's own client asks it
|
||||
const t = calls.find((c) => c.url.pathname.endsWith("/marketing/touch"))
|
||||
expect(t.method).toBe("GET")
|
||||
expect(Number(t.url.searchParams.get("seq"))).toBeGreaterThanOrEqual(0)
|
||||
expect(t.headers.Authorization).toBe("Bearer " + token)
|
||||
expect(t.headers["X-Device-Mid"]).toBe("11111111-2222-4333-8444-555555555555")
|
||||
expect(t.headers["X-ZCode-App-Version"]).toBe("3.17.2")
|
||||
expect(t.headers["X-Client-Language"]).toBeTruthy()
|
||||
// nothing claims it here
|
||||
expect(calls.some((c) => c.url.pathname.endsWith("/claim"))).toBe(false)
|
||||
// the preview is not asked anymore (the v3.17 client reads the feed alone)
|
||||
expect(calls.some((c) => c.url.pathname.endsWith("/preview"))).toBe(false)
|
||||
})
|
||||
|
||||
// #503, 10-30: a banner plan is in the app's marketing feed and in no
|
||||
@@ -415,7 +422,6 @@ test("a banner plan from the app's marketing feed is named on the card", async (
|
||||
const token = jwt(now + 86400)
|
||||
const calls = serve(({ url }) => {
|
||||
if (url.pathname === "/api/v1/zcode-plan/billing/balance") return ok(startBalance(now, "active"))
|
||||
if (url.pathname === "/api/v1/zcode-plan/billing/preview") return ok(PREVIEW_CLAIMED)
|
||||
if (url.pathname === "/api/v1/marketing/touch")
|
||||
return ok({ deliveries: [{ banner: { background: { args: { zcode_plan: { name: "ZCODE WEEKEND BUILD" } } }, buttons: [{ action: { type: "claim_zcode_plan", args: { plan_id: "zcode-v3-start-plan-1030-wk" } } }] } }] })
|
||||
})
|
||||
@@ -426,12 +432,12 @@ test("a banner plan from the app's marketing feed is named on the card", async (
|
||||
|
||||
test("a claimed account's card has no line at all", async () => {
|
||||
const now = Math.trunc(Date.now() / 1000)
|
||||
const { u } = await startCard(now, jwt(now + 86400), () => ok(PREVIEW_CLAIMED))
|
||||
const { u } = await startCard(now, jwt(now + 86400), () => ok({ deliveries: [] }))
|
||||
expect(u.windows.map((w) => w.name)).toEqual(["GLM-5.1"])
|
||||
expect(u.error).toBeUndefined()
|
||||
})
|
||||
|
||||
test("a preview that fails shows nothing and leaves the card as it was", async () => {
|
||||
test("a feed that fails shows nothing and leaves the card as it was", async () => {
|
||||
const now = Math.trunc(Date.now() / 1000)
|
||||
const token = jwt(now + 86400)
|
||||
const before = (await startCard(now, token, () => new Response("", { status: 404 }))).u
|
||||
@@ -444,28 +450,30 @@ test("a preview that fails shows nothing and leaves the card as it was", async (
|
||||
expect(u.error).toBeUndefined()
|
||||
expect(u.windows.some((w) => w.aside)).toBe(false)
|
||||
}
|
||||
// an expired sign-in is no preview request either
|
||||
// an expired sign-in is no feed request either
|
||||
const calls = serve(() => undefined)
|
||||
expect((await usage(oauth({ site: "zai", jwt: jwt(now - 60) }))).error).toContain("sign-in has expired")
|
||||
expect(calls.some((c) => c.url.pathname.endsWith("/preview"))).toBe(false)
|
||||
expect(calls.some((c) => c.url.pathname.endsWith("/marketing/touch"))).toBe(false)
|
||||
})
|
||||
|
||||
test("the card's error stays the error: no line is added over it", async () => {
|
||||
const now = Math.trunc(Date.now() / 1000)
|
||||
const { u } = await startCard(now, jwt(now + 86400), () => ok(PREVIEW_CLAIMABLE))
|
||||
const { u } = await startCard(now, jwt(now + 86400), () => ok(TOUCH_TRUST))
|
||||
expect(u.windows.at(-1)).toEqual(TRUST_BUILD) // a working card gets it
|
||||
const calls = serve(({ url }) => {
|
||||
if (url.pathname === "/api/v1/zcode-plan/billing/balance") return ok(startBalance(now, "expired"))
|
||||
if (url.pathname === "/api/v1/zcode-plan/billing/preview") return ok(PREVIEW_CLAIMABLE)
|
||||
if (url.pathname === "/api/v1/marketing/touch") return ok(TOUCH_TRUST)
|
||||
})
|
||||
const over = await usage(oauth({ site: "zai", jwt: jwt(now + 86400), device: "d" }))
|
||||
expect(over).toEqual({ signIn: "kept", error: "this account has no GLM Coding Plan, and ZCode's Start Plan has ended or was never started" })
|
||||
expect(calls.some((c) => c.url.pathname.endsWith("/preview"))).toBe(false) // nothing to put it on
|
||||
expect(calls.some((c) => c.url.pathname.endsWith("/claim"))).toBe(false) // nothing to put it on
|
||||
})
|
||||
|
||||
test("several claimable plans are counted", async () => {
|
||||
const now = Math.trunc(Date.now() / 1000)
|
||||
const two = { ...PREVIEW_CLAIMABLE, plans: [PREVIEW_CLAIMABLE.plans[0], { plan_id: "zcode-v3-start-plan-trust-1007", name: "ZCode Trust Build", status: "active" }] }
|
||||
const first = TOUCH_TRUST.deliveries[0]
|
||||
const second = { ...first, campaign_id: "2101141259813175297", banner: { ...first.banner, background: { type: "zcode_plan", args: { zcode_plan: { plan_id: "zcode-v3-start-plan-trust-1007", name: "ZCode Trust Build", grant_units: 100000000, period: "one_time" } } }, buttons: [{ text: { format: "", content: "领取" }, action: { type: "claim_zcode_plan", args: { plan_id: "zcode-v3-start-plan-trust-1007" } } }, { text: { format: "", content: "关闭" }, action: { type: "close" } }] } }
|
||||
const two = { server_time: TOUCH_TRUST.server_time, deliveries: [first, second] }
|
||||
const { u } = await startCard(now, jwt(now + 86400), () => ok(two))
|
||||
expect(u.windows.at(-1)).toEqual({ name: "Gift plans to claim in the ZCode app", used: 0, aside: true, display: "2 · ZCode Trust Build" })
|
||||
})
|
||||
@@ -478,14 +486,14 @@ test("a coding account's line goes after its coding and gift windows", async ()
|
||||
if (url.pathname === "/api/biz/subscription/list") return ok([{ productName: "GLM Coding Pro", status: "VALID" }])
|
||||
if (url.pathname === "/api/monitor/usage/quota/limit") return ok({ level: "pro", limits: [{ type: "CREDIT_LIMIT", unit: 3, number: 5, percentage: 25 }] })
|
||||
if (url.pathname === "/api/v1/zcode-plan/billing/balance") return ok(startBalance(now, "active"))
|
||||
if (url.pathname === "/api/v1/zcode-plan/billing/preview") return ok(PREVIEW_CLAIMABLE)
|
||||
if (url.pathname === "/api/v1/marketing/touch") return ok(TOUCH_TRUST)
|
||||
})
|
||||
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", "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)
|
||||
expect(calls.filter((c) => c.url.pathname.endsWith("/marketing/touch"))).toHaveLength(1)
|
||||
})
|
||||
|
||||
// #503: the same card line from the real marketing/touch reply
|
||||
|
||||
Reference in New Issue
Block a user