codearts 0.3.11: OfficeAce routes by its total credit, not each bucket (#986)

An OfficeAce account is now routed by one 总积分 window: the total of every unexpired plan bucket (`skus[].quotas`) and activity bonus (`bonus_skus`). Each bucket stays visible as an `aside` detail, so a spent daily check-in bonus (每日签到有礼 0 / 100) no longer pauses an account with thousands of credits left elsewhere (#981).

What changed (packages/codearts, 0.3.10 -> 0.3.11)
- fetchOfficeAceUsage sums unexpired buckets into 总积分 (amount, limit, two-decimal rounding; sub-half-cent totals keep their raw value). Every per-bucket window is `aside`.
- 总积分's `runsOutAt` is the soonest expiry among unexpired buckets that still hold credit, and `runsOut` is what those buckets hold on that Beijing day (soonestLapse, shared with #982), never more than the total's remainder. Trial and spent buckets never choose the expiry.
- Overspent buckets are capped at their own total; an empty or unparseable `expired_time` is no expiry instead of Invalid Date.
- When every bucket has expired, a used-up 总积分 (0 / total, used 100) stays so the account is paused, not routed without a limit.
- README (en, zh) says the same.

Rebased onto dea9e4e3 (0.3.10, #998): merge-base is origin/main, and the diff touches only the OfficeAce usage hunks, the tests, the README and the version. The international station signing, the Tokens window, the state.vscdb temp copy and the statement finalize are unchanged.

What was run at the reviewed head 4c454b99 (mica, macOS, Bun 1.4.2, HOME=$(mktemp -d))
- bun test packages/codearts: 201 tests; green except a pre-existing flake on main, "an IDE sign-in is renewed by reading the IDE's file again" (red 3 of 6 on origin/main 4b0aef53, 2 of 6 here; cause found and injected, filed as #1007).
- bun scripts/check.mjs and check.mjs codearts: exit 0.
- Root bun test under suite.lock: 8321 pass, 20 skip, 0 fail.

Broken by hand, each restored before the next, each red:
- a spent bucket choosing runsOutAt (the open item from the last review): "a spent OfficeAce daily bonus does not pause credits left in other buckets";
- runsOut as one bucket instead of the Beijing day's sum; runsOutAt from the latest expiry instead of the soonest;
- details not aside; no 总积分 window; an expired bonus counted; no used-up total when all expired;
- 0.3.10: a credential signed for every station's hosts; reading state.vscdb in place instead of a copy; no Tokens window.

Not tried
- No real Huawei Cloud / OfficeAce account; every response is a fake fetch.
- Windows: the diff doesn't touch the state.vscdb path, so the codearts tests weren't run there for this change.

Refs #981, #982

Co-authored-by: zhou.han <18181754+yetihan@users.noreply.github.com>
This commit is contained in:
zhou.han
2026-11-11 22:16:09 +08:00
committed by GitHub
co-authored by zhou.han
parent 4b0aef5327
commit 1e5b1c8317
4 changed files with 275 additions and 26 deletions
+12 -6
View File
@@ -223,10 +223,14 @@ naming the Basic pair) renews the credential once and sends it again — but onl
changed the pair; the same pair would get the same refusal. An account that signed in without
opening MaaS gets a `400` saying so, not an empty Basic header sent upstream.
**Usage and check-in.** `GET {subscription}/v1/subscription`: plan buckets (`skus[].quotas`) and
activity bonuses (`bonus_skus`) become magpie windows; a `.trial` bucket carries no expiry and
gets none invented; an expired bucket is folded away (`aside`) and takes no part in routing. The
check-in is `POST {subscription}/v1/subscription/bonus/claim` once a Beijing day: a 2xx with no
**Usage and check-in.** `GET {subscription}/v1/subscription`: the total of all unexpired plan
buckets (`skus[].quotas`) and activity bonuses (`bonus_skus`) is the one routing window; each
bucket remains visible as an `aside` detail. A `.trial` bucket carries no expiry and gets none
invented; an expired bucket is folded away and takes no part in the active total. The total's
`runsOutAt` is the soonest still-funded bucket to expire, and `runsOut` is the remaining credit
that expires on that Beijing day. When every bucket has expired, a used-up total remains so the
account is paused instead of being routed without a limit. The check-in is
`POST {subscription}/v1/subscription/bonus/claim` once a Beijing day: a 2xx with no
`bonus_skus` is 「今日已无新增可领」 (`done`), not a failure. Turn on *Auto check-in* for OfficeAce
under **Settings → Usage → Plugins**.
@@ -338,8 +342,10 @@ measurements and code of [HuHong-Tao](https://github.com/yuweihao17/codearts/pul
去掉 `officeace/` 前缀,发到凭据里自带的 MaaS 地址(为空时用官方直连)。`401`(或 4xx 但报文点名这对 Basic 凭据)
会先续期一次再重发,**但只有续期真的换了这对凭据时才重发**。已登录但没开通 MaaS 的账号会得到一条说清原因的 `400`,
不会把空的 Basic 头发给上游。
- **OfficeAce 的用量与签到**:`/v1/subscription` 的套餐桶(`skus[].quotas`)与活动桶(`bonus_skus`)转成 magpie 的窗口;
`.trial` 桶没有到期时间就不显示;已过期的桶收进折叠区(`aside`)且不参与路由。签到是每个北京自然日一次
- **OfficeAce 的用量与签到**:`/v1/subscription` 中所有未过期套餐桶(`skus[].quotas`)和活动桶(`bonus_skus`)
汇总成唯一参与路由的「总积分」窗口,各桶只作为 `aside` 明细展示;`.trial` 桶没有到期时间就不显示;
已过期的桶收进折叠区且不参与有效余额汇总。「总积分」用仍有余额的桶里最早到期者作为 `runsOutAt`,
并把同一北京自然日到期的余额合为 `runsOut`;如果所有桶都已过期,仍保留一个已用尽的总积分窗口来暂停账号。签到是每个北京自然日一次
`POST /v1/subscription/bonus/claim`:2xx 但 `bonus_skus` 为空是「今日已无新增可领」(`done`),不是失败。
- **已知限制**:STS 的 refresh_token 只能用一次。本包的每张卡各自登录、各自持有一条记录与一个 token,所以两张卡
互不影响;**续期只写被续的那条记录**,因此用户删掉的账号永远不会被写回来(无论它此前有没有被列出/使用过、