raccoon 0.1.10: a balance a little over the listed grants keeps the Credits window (#936)

The reporter's income bills, pasted after 0.1.9, have no expired grant:
3000 + 300 + 3000 + 300 + 3000 = 9,600, while the balance is 9,623. So
0.1.9's count-back of expired grants added nothing and the card stayed
balance-only. The extra 23 comes back outside income bills.

A balance at most 10% over the listed grants now becomes the window's
limit (0 / 9623 here). A balance far over them (5,270 against 600 in the
existing test) stays balance-only, since the bills don't explain it.

Run: win-run bun test packages/raccoon (52 pass; the new test uses the
reporter's bills as pasted, with the expiry years moved ahead so it
holds after 11-15). Broken by hand: with the 10% branch made false, the
new test goes red (51 pass, 1 fail). bun scripts/check.mjs green.
Not tried: a real Raccoon account.

Reported-by: ULTIMATE215
This commit is contained in:
yetone
2026-11-10 22:27:04 +08:00
parent 4a063646cc
commit 8f4a8ec496
3 changed files with 41 additions and 1 deletions
+8
View File
@@ -714,6 +714,14 @@ async function queryUsage(token) {
if (grantedFromBills >= avail) break
grantedFromBills += g.pts
}
// A balance a little over every grant the bills list (plugins #936: 9,623
// against 9,600 of grants, none expired) holds credits that come back
// outside income bills. That remainder is counted into the window, so
// the card still shows one. A balance far over the bills is left
// balance-only: the bills don't explain it.
if (grantedFromBills > 0 && avail > grantedFromBills && avail - grantedFromBills <= avail / 10) {
grantedFromBills = avail
}
const runsOutAt = soonestExpMs ? new Date(soonestExpMs).toISOString() : null
const runsOut = soonestExpMs ? Math.min(avail, expiringPts) : 0
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@magpie-community/opencode-raccoon-auth",
"version": "0.1.9",
"version": "0.1.10",
"description": "OpenCode & Magpie provider plugin for SenseTime Raccoon (商汤小浣熊, xiaohuanxiong.com)",
"type": "module",
"main": "./opencode.mjs",
+32
View File
@@ -513,6 +513,38 @@ test("expired grants that cannot make up the balance leave it balance-only (plug
expect(u.windows).toEqual([])
})
// plugins #936's second reply: the reporter's income bills, as pasted
// (three grants with no expire_at, none expired), sum to 9,600 while the
// balance is 9,623.
test("a balance a little over every listed grant keeps the Credits window (plugins #936)", async () => {
const validTok = fakeJwt({ iss: "74350b", name: "Mason", exp: Math.floor(Date.now() / 1000) + 3600 })
startServer({
"GET /api/web/points/v1/balance": forbidden,
"GET /api/web/auth/v1/entitlement_info": () => Response.json({ code: 0, data: { office: { pro_enable: false } } }),
"GET /api/web/office/v3/setting_info": () => Response.json({ code: 0, data: { available_points: 9623 } }),
"GET /api/web/points/v1/bills": () =>
Response.json({
code: 0,
message: "success",
data: {
items: [
{ biz_id: "19966029", points: 3000 },
{ biz_id: "19692994", points: 300, expire_at: "2099-11-15T23:59:59+08:00" },
{ biz_id: "19659600", points: 3000 },
{ biz_id: "19659491", points: 300, expire_at: "2099-11-14T23:59:59+08:00" },
{ biz_id: "activity:1", points: 3000 },
],
has_more: false,
next_cursor: "",
},
}),
})
const hooks = await RaccoonAuthPlugin({ client: {} })
const u = await hooks.auth.usage(async () => ({ type: "oauth", access: validTok, refresh: "rt1", expires: Date.now() + 3600_000 }))
expect(u.balance).toBeUndefined()
expect(u.windows[0]).toMatchObject({ name: "Credits", amount: 0, limit: 9623, display: "0 / 9623", runsOut: 300 })
})
test("a readable balance asks setting_info nothing (plugins #520)", async () => {
const validTok = fakeJwt({ iss: "74350b", name: "Mason", exp: Math.floor(Date.now() / 1000) + 3600 })
let asked = 0