Skip to content

Commit 5e4045f

Browse files
committed
feat(web): 额度包明细过滤已消耗成 0 的包
- PackageLadder 只展示剩余 > 0 的包,计数与弹层明细同步 - 全部耗尽时不再渲染「套餐 N 个」入口 - 补用例:已用完包不计入也不出现在明细
1 parent 5137ae0 commit 5e4045f

3 files changed

Lines changed: 12 additions & 3 deletions

File tree

‎src/provider/codebuddy/client.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,9 @@ async def _fetch_personal_quota(self, credential: CodeBuddyCredential) -> Quota:
329329
remaining += package_remaining
330330
end = _cycle_end_epoch(account.get("CycleEndTime"))
331331
# 展示明细:比调度阶梯(下面的 ladder)宽——已用完但仍有效的包
332-
# 也要显示。但「已过期且已用完」的包既不携带积分也不可能再被
333-
# 消耗,只是上游的历史残留,不堆进弹层。
332+
# 也会下发(前端按「剩余 0」再过滤掉,只保留还有余额的)。但
333+
# 「已过期且已用完」的包既不携带积分也不可能再被消耗,只是上游
334+
# 的历史残留,连数据都不留。
334335
if package_remaining > 0 or (end is not None and end > now_epoch):
335336
packages.append({
336337
"name": str(account.get("PackageName") or ""),

‎web/src/pages/CredentialsPage.tsx‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1339,7 +1339,11 @@ export function CredentialsPage() {
13391339
* 几十行不能挤进单元格。无明细(未探测/上游未提供)时不渲染。
13401340
*/
13411341
function PackageLadder({ credential }: { credential: Credential }) {
1342-
const packages = credential.quota_packages ?? [];
1342+
// 已消耗完(剩余 ≤ 0)的包不再展示:它们只是上游按期返回的历史残留,
1343+
// 既不带可用积分、也不会再被消耗,堆在弹层里只会淹没还有余额的包。
1344+
const packages = (credential.quota_packages ?? []).filter(
1345+
(item) => item.total - item.used > 0,
1346+
);
13431347
if (packages.length === 0) return null;
13441348
// 展示按到期升序:快过期的排最前(无到期信息的排最后)
13451349
const ordered = [...packages].sort(

‎web/src/pages/__tests__/CredentialsPage.test.tsx‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,8 @@ describe("CredentialsPage", () => {
248248
{ name: "福利积分", total: 2000, used: 0, end: day },
249249
{ name: "每月登录", total: 500, used: 76.564, end: day + 100_000 },
250250
{ name: "无到期包", total: 100, used: 10, end: null },
251+
// 已消耗成 0 的包不展示(也不计入「套餐 N 个」)
252+
{ name: "已用完包", total: 300, used: 300, end: day + 300_000 },
251253
],
252254
}),
253255
makeCredential({ id: "tr", provider: "trae", quota_packages: null }),
@@ -274,6 +276,8 @@ describe("CredentialsPage", () => {
274276
const tip = await screen.findByRole("tooltip");
275277
const items = within(tip).getAllByTestId("package-cb");
276278
expect(items).toHaveLength(4);
279+
// 已消耗成 0 的包被过滤:明细与计数里都不出现
280+
expect(within(tip).queryByText(/已用完包/)).not.toBeInTheDocument();
277281
// 按到期升序:最近到期的「福利积分」排第一,无到期时间的「无到期包」排最后
278282
expect(items[0]).toHaveTextContent("福利积分");
279283
expect(items[0]).toHaveTextContent("2,000");

0 commit comments

Comments
 (0)