From 311d62867c14947c0d03496959aa08e7b0aa6946 Mon Sep 17 00:00:00 2001 From: yetone Date: Tue, 3 Nov 2026 16:53:50 +0800 Subject: [PATCH] workbuddy 0.2.20: extra credits only the detail lists have say when they lapse on the window routing reads (Kayphoon) Kayphoon on Discord asked that routing spend the WorkBuddy CN account whose extra-credit packs expire first, before they lapse. magpie's smart routing already does that (Allowance.Renewal, Lapse and Pace read a window's runsOutAt/runsOut), and the plugin already put the soonest lapse of the summary's packages on the window that stops the account. But extra credits that only the detail lists have (listedExtra, the China free-account shape from jiabubu's report, 0.2.17) said their lapse only on their own "Extra credits" window, which is set aside, and routing reads no window set aside. So for those accounts routing knew no expiry at all. Now the soonest of them to lapse is also put on the Credits window, when it is sooner than what that window already says (summed when the same). Per-pack expiry isn't sent: routing only orders accounts by the soonest lapse and how much lapses then, so a list would change no choice. Run at this head (mote, HOME under TMPDIR): bun test packages/workbuddy, 318 pass 0 fail; bun scripts/check.mjs ok. Broken by hand: the same usage.test.mjs with the old index.mjs fails the jiabubu-shape test at the new assertion (Credits has no runsOutAt). Not tried: a real WorkBuddy CN account with expiring packs; the fixture is CN_FREE's shapes, not Kayphoon's bytes. --- packages/workbuddy/index.mjs | 8 ++++++++ packages/workbuddy/package.json | 2 +- packages/workbuddy/usage.test.mjs | 4 ++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/workbuddy/index.mjs b/packages/workbuddy/index.mjs index 329560d..a227ea4 100644 --- a/packages/workbuddy/index.mjs +++ b/packages/workbuddy/index.mjs @@ -3909,6 +3909,14 @@ function makePlugin(site) { const { runsOutAt, runsOut, ...counts } = more const w = { ...creditWindow("Extra credits", counts), aside: true, ...(runsOutAt ? { runsOutAt, runsOut } : {}) } out.windows.splice(out.windows.indexOf(credits) + 1, 0, w) + // and, as with the split's, the soonest of them to lapse is + // the account's too, on the window that stops it: routing + // reads none set aside, so an account whose extra credits + // expire first went unknown to it (Kayphoon on Discord) + const at = runsOutAt ? Date.parse(runsOutAt) : 0 + const was = credits.runsOutAt ? Date.parse(credits.runsOutAt) : 0 + if (at > 0 && (!was || at < was)) Object.assign(credits, { runsOutAt, runsOut }) + else if (at > 0 && at === was) credits.runsOut = (credits.runsOut ?? 0) + runsOut } } catch {} } diff --git a/packages/workbuddy/package.json b/packages/workbuddy/package.json index 5ef4dd8..d5e01ad 100644 --- a/packages/workbuddy/package.json +++ b/packages/workbuddy/package.json @@ -1,6 +1,6 @@ { "name": "@magpie-community/opencode-workbuddy-auth", - "version": "0.2.19", + "version": "0.2.20", "description": "OpenCode provider plugins for WorkBuddy's plans: WorkBuddy (CodeBuddy, copilot.tencent.com) and WorkBuddy AI (www.workbuddy.ai)", "type": "module", "main": "./opencode.mjs", diff --git a/packages/workbuddy/usage.test.mjs b/packages/workbuddy/usage.test.mjs index 0f6d2ba..10fd241 100644 --- a/packages/workbuddy/usage.test.mjs +++ b/packages/workbuddy/usage.test.mjs @@ -567,6 +567,10 @@ test("extra credits only the detail lists have are a window of their own, set as expect(u.windows.slice(0, 2).map((w) => [w.name, w.display, !!w.aside])).toEqual([["Credits", "0 / 500", false], ["Extra credits", "20 / 1300", true]]) // the soonest to lapse is the activity's, on the window that says them expect(u.windows[1]).toMatchObject({ amount: 20, limit: 1300, runsOut: 280, runsOutAt: new Date(on(gift).DeductionEndTime).toISOString() }) + // and the window that stops the account says it too, as routing reads + // none set aside: an account whose extra credits lapse first is spent + // first (Kayphoon on Discord) + expect(u.windows[0]).toMatchObject({ runsOut: 280, runsOutAt: u.windows[1].runsOutAt }) // the plan's window keeps its cycle expect(u.windows[0].resetsAt).toBe("2036-10-31T15:59:59.000Z")