Skip to content

feat(quota): show reset credit expiry details - #56

Merged
Cmochance merged 4 commits into
Cmochance:mainfrom
Baker4real:codex/pr-reset-credit-expiry
Jul 26, 2026
Merged

feat(quota): show reset credit expiry details#56
Cmochance merged 4 commits into
Cmochance:mainfrom
Baker4real:codex/pr-reset-credit-expiry

Conversation

@Baker4real

Copy link
Copy Markdown
Contributor

背景

当前账号额度接口只返回重置卡数量,用户无法确认每张卡的发放时间和到期时间,也无法在多个账号之间判断哪张卡仍然有效。

改动

  • 在成功读取 /wham/usage 后,使用同一轮请求最终采用的 access token 和 chatgpt-account-id 请求 /wham/rate-limit-reset-credits
  • 解析每张重置卡的 granted_at / expires_at,只持久化时间字段,不持久化卡片 ID。
  • 在账号卡片和当前账号面板显示可用卡数量,以及每张卡的发放/到期时间;统一按 Asia/Shanghai 显示。
  • 详情接口失败时保留主 quota,不让附加详情故障阻断额度刷新。
  • 更新的 session JSONL 没有重置卡详情时,保留已确认的卡片到期时间;切换写回同样不会清空这些详情。
  • 为旧版 profile.json 增加默认兼容,并补充后端解析、前端展示、时区和持久化回归测试。

安全边界

  • 详情请求严格复用对应账号的 OAuth 身份和账号作用域 header。
  • 不记录 token、cookie、完整账号 ID、卡片 ID 或失败响应正文。

验证

  • npm run test:rust:windows:135 passed
  • cargo fmt --manifest-path src-tauri/Cargo.toml -- --check
  • npx tsc --noEmit
  • npx vitest run --root .:3 passed
  • npm run build:成功

来源分支:Baker4real/Codex_Account_Switch:codex/pr-reset-credit-expiry

Codex and others added 4 commits July 17, 2026 09:42
…tail failure

- Add vitest as a devDependency with a standalone vitest.config.ts (the
  Vite root points at the per-platform front-end, so an inherited root
  would never scan the shared tests), a test:front script, and a CI
  step so the new front-end tests actually run in CI.
- Move the reset-credit card styles from win/front/styles.css into
  shared/front/base.css and mirror the flex-to-grid quota-stack
  adaptation into the macOS layer: the markup is rendered by the shared
  front-end on both platforms, but only Windows had the styles, leaving
  macOS cards unstyled inside the old flex row.
- Backfill previously confirmed reset-credit details from stored
  metadata when the detail endpoint fails: every API write-back path
  persists the snapshot wholesale, so a transient failure used to wipe
  the cards this feature intends to preserve.
- Align the docs/CHANGELOG additions with the repo's English convention.
@Cmochance

Copy link
Copy Markdown
Owner

@Baker4real 感谢贡献!为加速合并,maintainer 侧直接在分支上补了一个 commit(b842e50),说明如下:

  1. CI 修复:仓库此前没有前端测试框架,新增的 *.test.ts 会让 tsc --noEmit 找不到 vitest 类型声明,CI 的 Type-check step 直接失败。已把 vitest 加进 devDependencies,新增独立 vitest.config.ts(vite.config 的 root 指向平台前端目录,vitest 继承该 root 会扫不到 shared 测试)、test:front script 和对应 CI step,让这两个前端测试真正在 CI 里执行。
  2. macOS 样式补齐:reset-credit 的 markup 在 shared/front/render.ts(mac/win 共用),但样式只加在 win/front/styles.css,macOS 端会渲染出无样式内容。已把组件样式移入两平台共享的 shared/front/base.css,并把 .profile-quota-stack 的 flex→grid 适配同步到 mac 平台层。
  3. 详情接口失败时的存量回填:四条 API 刷新写回路径都是 snapshot.quota.unwrap_or_default() 整体覆盖持久化,详情接口偶发失败一次就会清掉之前已确认的卡片详情,与 PR 描述中"保留已确认详情"的意图不符(原实现只覆盖了 live-session 快照路径)。已在 chatgpt_api.rs 源头增加 stored 回填——仅当本轮完全没有 reset-credit 信息时才整体回填,避免新 count 与旧卡片时间混搭——并补了 4 个单元测试。
  4. 文档语言:docs/SECURITY.mddocs/IMPLEMENTATION.md、CHANGELOG 的新增段落按仓库现有英文惯例改写(README 本就是中文,保持不动)。

本地验证:cargo fmt --check / cargo test --lib(144 passed)/ tsc --noEmit / vitest run(3 passed)/ npm run build 全绿。如对以上任何改动有异议,欢迎在此讨论。

@Cmochance
Cmochance merged commit 27b180f into Cmochance:main Jul 26, 2026
3 checks passed
@Baker4real
Baker4real deleted the codex/pr-reset-credit-expiry branch August 5, 2026 10:01
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