Skip to content

fix(coding-plan): correct zhipu weekly tier name by reset time#2420

Merged
farion1231 merged 1 commit into
farion1231:mainfrom
TuYv:fix/zhipu-weekly-tier
Apr 30, 2026
Merged

fix(coding-plan): correct zhipu weekly tier name by reset time#2420
farion1231 merged 1 commit into
farion1231:mainfrom
TuYv:fix/zhipu-weekly-tier

Conversation

@TuYv

@TuYv TuYv commented Apr 28, 2026

Copy link
Copy Markdown
Contributor

Title:
fix(coding-plan): correct zhipu weekly tier name by reset time

Body:

Summary / 概述

修复智谱 Coding Plan 的「每周额度」在前端被错误显示为「5 小时额度」的问题。

services/coding_plan.rs::query_zhipudata.limits[] 里所有
TOKENS_LIMIT 条目硬编码为 tier name "five_hour"。新套餐(2026-02-12 后
订阅)会回 2 条 TOKENS_LIMIT(5h 桶 + 周限桶),导致周限那条也命中
subscription.fiveHour i18n key 显示成 5 小时。

Solution / 修复方案

nextResetTime 升序排序所有 TOKENS_LIMIT 条目:

  • 第 0 条 → five_hour
  • 第 1 条 → weekly_limit
  • 多于 2 条丢弃(防御)

老套餐只回 1 条,自然降级为仅产 five_hour,行为与改动前一致。

Hardening

  • eq_ignore_ascii_case 比较 TOKENS_LIMIT:上游若改大小写仍能识别
  • 复用 TIER_FIVE_HOUR / TIER_WEEKLY_LIMIT 常量替代字面量
  • 缺失 nextResetTime 时按 i64::MAX 排到末位,避免抢占 5h 槽位

Related Issue / 关联 Issue

Refs #1588(issue 评论中明确了新老套餐的响应结构差异)

Test Plan / 测试计划

新增 8 个单元测试(services::coding_plan::tests):

  • 新套餐双 tier 排序(输入顺序无关)
  • 老套餐单 tier 降级为 five_hour
  • 无 TOKENS_LIMIT 返回空
  • 缺失 nextResetTime 排到末位
  • type 大小写不敏感
  • percentage 为字符串/null 降级为 0
  • percentage 极端值(负数/>100)原样透传
  • 3+ 条 TOKENS_LIMIT 丢弃多余项

cargo test --lib:1027 passed / 0 failed
cargo fmt --check:clean
cargo clippy:本文件无新增警告

Checklist

  • cargo test passes
  • cargo fmt --check passes
  • cargo clippy 本 PR 改动无新增警告
  • pnpm typecheck(仅改 Rust,无前端改动)
  • Updated i18n files(不需要,weekly_limit 已有 i18n 映射)

Zhipu's `data.limits[]` returns 1 entry for legacy plans (subscribed
before 2026-02-12) and 2 entries for current plans. Previously every
TOKENS_LIMIT entry was hardcoded as `five_hour`, so the weekly bucket
was rendered with the 5-hour i18n label.

Sort TOKENS_LIMIT entries by nextResetTime ascending and assign
`five_hour` to index 0, `weekly_limit` to index 1. Legacy plans
naturally degrade to a single five_hour tier.

Also harden the parser: case-insensitive type match (defends against
upstream casing changes), reuse TIER_FIVE_HOUR/TIER_WEEKLY_LIMIT
constants, and add 8 unit tests covering both plan shapes plus
defensive edge cases.
@TuYv

TuYv commented Apr 28, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@farion1231 farion1231 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

非常感谢您的贡献!

@farion1231
farion1231 merged commit fafc122 into farion1231:main Apr 30, 2026
2 checks passed
ManLOK-Chu pushed a commit to ManLOK-Chu/cc-switch that referenced this pull request May 11, 2026
…n1231#2420)

Zhipu's `data.limits[]` returns 1 entry for legacy plans (subscribed
before 2026-02-12) and 2 entries for current plans. Previously every
TOKENS_LIMIT entry was hardcoded as `five_hour`, so the weekly bucket
was rendered with the 5-hour i18n label.

Sort TOKENS_LIMIT entries by nextResetTime ascending and assign
`five_hour` to index 0, `weekly_limit` to index 1. Legacy plans
naturally degrade to a single five_hour tier.

Also harden the parser: case-insensitive type match (defends against
upstream casing changes), reuse TIER_FIVE_HOUR/TIER_WEEKLY_LIMIT
constants, and add 8 unit tests covering both plan shapes plus
defensive edge cases.
dfbb pushed a commit to dfbb/cc-switch that referenced this pull request May 20, 2026
…n1231#2420)

Zhipu's `data.limits[]` returns 1 entry for legacy plans (subscribed
before 2026-02-12) and 2 entries for current plans. Previously every
TOKENS_LIMIT entry was hardcoded as `five_hour`, so the weekly bucket
was rendered with the 5-hour i18n label.

Sort TOKENS_LIMIT entries by nextResetTime ascending and assign
`five_hour` to index 0, `weekly_limit` to index 1. Legacy plans
naturally degrade to a single five_hour tier.

Also harden the parser: case-insensitive type match (defends against
upstream casing changes), reuse TIER_FIVE_HOUR/TIER_WEEKLY_LIMIT
constants, and add 8 unit tests covering both plan shapes plus
defensive edge cases.
delta-lo pushed a commit to delta-lo/cc-switch-mod that referenced this pull request May 31, 2026
…n1231#2420)

Zhipu's `data.limits[]` returns 1 entry for legacy plans (subscribed
before 2026-02-12) and 2 entries for current plans. Previously every
TOKENS_LIMIT entry was hardcoded as `five_hour`, so the weekly bucket
was rendered with the 5-hour i18n label.

Sort TOKENS_LIMIT entries by nextResetTime ascending and assign
`five_hour` to index 0, `weekly_limit` to index 1. Legacy plans
naturally degrade to a single five_hour tier.

Also harden the parser: case-insensitive type match (defends against
upstream casing changes), reuse TIER_FIVE_HOUR/TIER_WEEKLY_LIMIT
constants, and add 8 unit tests covering both plan shapes plus
defensive edge cases.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants