zcode 0.1.26: a gift's -Trial models are listed when ZCode's config is out of reach, a failed gift read is asked again in a minute, and a card with no ZCode session says the gift needs one
bigsteven (Discord #feedback, 10-24): GLM Coding Plan spent, requests go to it, and the model list has no GLM-5.3-Trial. Which sign-in the account has is still asked; three ways the plugin drops a signed-in account's -Trial entries, or drops them unsaid, are fixed here: - ZCode's provider config out of reach (cdn-zcode.z.ai, 8s): the list falls back to the table and is marked magpie.fellBack, and magpie then keeps the list it was told last (internal/plugin/providers.go), from before the gift. The -Trial entries just read from the balance went with it. A list that carries trial entries is no longer marked. - A gift balance read that failed was cached as "no gift" for ten minutes beside a good plan list, so one hiccup hid the -Trial entries and the gift's card section for ten minutes. It is now unknown and asked again in a minute (an expired session is known, and kept for ten). - A key, or a sign-in whose ZCode session has expired (that token can't be renewed, and with a key beside it the account is never marked), reads no gift, so it lists no -Trial models, and the card said nothing. Its card now sets aside a line "ZCode gift plans (-Trial models) need ZCode's sign-in", with why in the display (an API key / no ZCode session / sign-in expired). Run: HOME=<scratch> bun test packages/zcode: 102 pass (3 new tests); bun scripts/check.mjs zcode ok. Broken by hand: each of the three fixes reverted alone turns its tests red (fellBack 1, retry 2, card line 1), restored after. Changed on purpose: dual.test's "a gift read that fails at once still trusts the plan list for ten minutes" now says a minute; usage.test's key and key-only oauth cards carry the new line. Not tried: a real account (no ZCode sign-in with a gift in this session), nor a real CDN failure; the config fallback was forced in the test through _internal.config(null). The new line's name is not yet in magpie's i18n. A team-seat sign-in (an account with no plan of its own) still lists no -Trial entries; not changed here.
This commit is contained in:
@@ -41,6 +41,11 @@ async function usage(auth, sets = []) {
|
||||
return hooks.auth.usage(async () => auth, { id: "zcode" })
|
||||
}
|
||||
const jwt = (exp) => ["{}", JSON.stringify({ exp })].map((s) => Buffer.from(s).toString("base64url")).join(".") + ".sig"
|
||||
// a card read with no ZCode session says the gift plans need one: a key
|
||||
// (or a sign-in with no ZCode token) reads no gift and lists no -Trial
|
||||
const GIFT = "ZCode gift plans (-Trial models) need ZCode's sign-in"
|
||||
const KEY_LINE = { name: GIFT, used: 0, aside: true, display: "not read with an API key: add the account with a ZCode sign-in" }
|
||||
const NO_SESSION = { name: GIFT, used: 0, aside: true, display: "this sign-in has no ZCode session: sign in again" }
|
||||
|
||||
test("a Coding Plan's five hours and week", async () => {
|
||||
const reset = Date.now() + 3600_000
|
||||
@@ -59,12 +64,13 @@ test("a Coding Plan's five hours and week", async () => {
|
||||
windows: [
|
||||
{ name: "5 hours", used: 25, display: "500 / 2000", amount: 500, limit: 2000, resetsAt: new Date(reset).toISOString(), span: 5 * 3600 },
|
||||
{ name: "Weekly", used: 10, display: "1000 / 10000", amount: 1000, limit: 10000, resetsAt: new Date(reset).toISOString(), span: 7 * 86400 },
|
||||
NO_SESSION,
|
||||
],
|
||||
})
|
||||
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({ 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(await usage({ type: "api", key: "k", metadata: { site: "bigmodel" } })).toEqual({ signIn: "kept", plan: "GLM Coding Lite", windows: [KEY_LINE] })
|
||||
expect(bm[0].url.origin).toBe("https://open.bigmodel.cn")
|
||||
})
|
||||
|
||||
@@ -82,7 +88,7 @@ test("a key with no GLM Coding Plan says a ZCode gift plan needs ZCode's sign-in
|
||||
}
|
||||
// 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: [] })
|
||||
expect(await usage({ type: "api", key: "k", metadata: { site: "zai" } })).toEqual({ signIn: "kept", windows: [KEY_LINE] })
|
||||
// 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()
|
||||
@@ -234,7 +240,7 @@ test("a Coding Plan of a person's own shows its resets, each with its end, as th
|
||||
expect(await usage(auth)).toEqual({
|
||||
signIn: "kept",
|
||||
plan: "GLM Coding Pro",
|
||||
windows: [],
|
||||
windows: [NO_SESSION],
|
||||
resets: { count: 2, byWindow: true, fiveHour: 1, weekly: 1, until: "2026-10-30T15:59:59.000Z", each: [
|
||||
{ until: "2026-10-30T15:59:59.000Z", window: "weekly" },
|
||||
{ until: "2026-11-02T15:59:59.000Z", window: "fiveHour" },
|
||||
|
||||
Reference in New Issue
Block a user