zcode 0.1.39: gift plans are also claimed from the ZCode app's banner feed (#503)

kongbai01203 found on 10-30 that a ZCode claim banner's plan (ZCODE
WEEKEND BUILD, 500M GLM-5.3-Flash tokens) is in neither
/billing/preview nor /billing/current while the app shows the banner,
so 0.1.35's daily claim said "no ZCode gift plan to claim". The app
reads the banner from GET /api/v1/marketing/touch?seq=<n>: each
delivery's banner button with action type claim_zcode_plan carries the
plan_id, and the claim is the same POST /billing/claim. Their capture
has a real code 0 claim reply ("Plan claimed successfully.").

- toClaim reads both lists (the feed first, then the preview) and keeps
  each plan_id once; claimDaily and the card's claim line use it.
- The feed goes out with what the capture shows the app sends: the
  session, X-Device-Mid, X-ZCode-App-Version and X-Client-Language
  (the system locale), seq counting up from 0 per process.
- A list that doesn't read is failed (asked again later), never
  "nothing to claim"; a plan claimed beside it is still named.
- claimOne is unchanged; README says the two lists and that a plan just
  claimed may show in neither billing list until its effective_at.

Run on mote (macOS, Bun 1.4.2, temp HOME), on eee889a:
- packages/zcode `bun test`: 178 pass 0 fail.
- Red on the old index.mjs (origin/main's, with the new tests): 3 fail
  (the banner claimed from the feed, an unreadable feed is failed, the
  banner named on the card).
- Broken by hand: claiming each plan per list (no dedupe) and dropping
  the "list unread with nothing listed" return: 3 fail (plan both lists
  name claimed once, unreadable feed, unreadable preview).
- Full `HOME=$(mktemp -d) bun test` from the root: first run 3870 pass
  1 fail, its name lost (the log was cut by tail); two reruns with the
  whole log kept: 3871 pass 0 fail. `bun scripts/check.mjs`: ok.

Not tried: a real claim through the plugin. The feed fixture is built
from the capture's description of its fields, not its literal bytes
(only the claim reply was posted whole); the touch/action call the app
makes for a banner's confirm/close is not sent.
This commit is contained in:
yetone
2026-10-30 23:08:10 +08:00
parent b177d69b83
commit 2e580cfead
5 changed files with 207 additions and 40 deletions
+16
View File
@@ -408,6 +408,22 @@ test("a gift plan ZCode holds but has not granted is named on the card, to claim
expect(calls.some((c) => c.url.pathname.endsWith("/claim"))).toBe(false)
})
// #503, 10-30: a banner plan is in the app's marketing feed and in no
// preview; the card names it too, and still claims nothing
test("a banner plan from the app's marketing feed is named on the card", async () => {
const now = Math.trunc(Date.now() / 1000)
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" } } }] } }] })
})
const u = await usage(oauth({ site: "zai", jwt: token, device: "11111111-2222-4333-8444-555555555555" }))
expect(u.windows.at(-1)).toEqual({ name: "Gift plans to claim in the ZCode app", used: 0, aside: true, display: "1 · ZCODE WEEKEND BUILD" })
expect(calls.some((c) => c.url.pathname.endsWith("/claim"))).toBe(false)
})
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))