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.
This commit is contained in:
yetone
2026-11-03 16:53:50 +08:00
parent 1984cf65dd
commit 311d62867c
3 changed files with 13 additions and 1 deletions
+8
View File
@@ -3909,6 +3909,14 @@ function makePlugin(site) {
const { runsOutAt, runsOut, ...counts } = more const { runsOutAt, runsOut, ...counts } = more
const w = { ...creditWindow("Extra credits", counts), aside: true, ...(runsOutAt ? { runsOutAt, runsOut } : {}) } const w = { ...creditWindow("Extra credits", counts), aside: true, ...(runsOutAt ? { runsOutAt, runsOut } : {}) }
out.windows.splice(out.windows.indexOf(credits) + 1, 0, w) 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 {} } catch {}
} }
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@magpie-community/opencode-workbuddy-auth", "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)", "description": "OpenCode provider plugins for WorkBuddy's plans: WorkBuddy (CodeBuddy, copilot.tencent.com) and WorkBuddy AI (www.workbuddy.ai)",
"type": "module", "type": "module",
"main": "./opencode.mjs", "main": "./opencode.mjs",
+4
View File
@@ -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]]) 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 // 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() }) 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 // the plan's window keeps its cycle
expect(u.windows[0].resetsAt).toBe("2036-10-31T15:59:59.000Z") expect(u.windows[0].resetsAt).toBe("2036-10-31T15:59:59.000Z")