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")