fix(coding-plan): correct zhipu weekly tier name by reset time#2420
Merged
Conversation
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.
Contributor
Author
|
@codex review |
|
Codex Review: Didn't find any major issues. Chef's kiss. ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Title:
fix(coding-plan): correct zhipu weekly tier name by reset time
Body:
Summary / 概述
修复智谱 Coding Plan 的「每周额度」在前端被错误显示为「5 小时额度」的问题。
services/coding_plan.rs::query_zhipu把data.limits[]里所有TOKENS_LIMIT条目硬编码为 tier name"five_hour"。新套餐(2026-02-12 后订阅)会回 2 条 TOKENS_LIMIT(5h 桶 + 周限桶),导致周限那条也命中
subscription.fiveHouri18n key 显示成 5 小时。Solution / 修复方案
按
nextResetTime升序排序所有 TOKENS_LIMIT 条目:five_hourweekly_limit老套餐只回 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):cargo test --lib:1027 passed / 0 failedcargo fmt --check:cleancargo clippy:本文件无新增警告Checklist
cargo testpassescargo fmt --checkpassescargo clippy本 PR 改动无新增警告pnpm typecheck(仅改 Rust,无前端改动)weekly_limit已有 i18n 映射)