Skip to content

feat: 账号发现——识别本机未入册账号并一键补录 - #65

Open
wh-1 wants to merge 1 commit into
changexbc:mainfrom
wh-1:pr/account-discovery
Open

wh-1 wants to merge 1 commit into
changexbc:mainfrom
wh-1:pr/account-discovery

Conversation

@wh-1

@wh-1 wh-1 commented Sep 19, 2026

Copy link
Copy Markdown
Contributor

切号工具只能看到「已经导入过」的账号。可本机真正登录过、凭据还留着的账号,如果当初没导入,用户根本不知道它存在 —— 想切也切不过去。这个 PR 补上发现与补录。

做了什么

账号发现(只读,不动任何数据)
扫官方 auth 登录历史(主)与 settings / storage / 画像缓存残留(辅),跟账号库比对,列出「本机还有哪些账号没入册」,每个账号给出:凭据备份文件数、最近备份时间、access / refresh 凭据过期时间、是否可补录。

一键补录
拿该 uid 最新的 auth 历史备份构造账号记录写进账号库;写入前先备份 accounts.json。

入口
账号页顶部提示条 —— 只在真有未入册账号时出现,补录后自动刷新列表;没有时不占位。

实现说明

  • 新增 crates/wb-switch-core/src/modules/discover.rs
  • 本地新增的 HTTP 路由与 Tauri 命令分别落在 api_local.rs / commands_local.rs(新文件,合并零冲突);api.rs / main.rs / lib.rs 各只加接线行,避免在上游热点文件里堆代码
  • auth_file.rs 的 imported_account_from_root 由 fn 提为 pub(crate) fn 供复用,无行为变化

验证

  • cargo test -p wb-switch-core:336 passed / 9 failed —— 9 个失败与上游 main 完全同一批(对照见下),非本 PR 引入
  • cargo check -p wb-switch-core -p wb-switch-server:通过
  • node node_modules/typescript/bin/tsc --noEmit:通过
  • 实机:识别出未入册账号 → 一键补录 → 账号页出现
9 个失败的对照说明(Windows 环境)

本机 Windows 下,纯净上游 main 跑出与本分支完全相同的 9 个失败项(main 334 passed、本分支 336 passed,失败项逐一相同),涉及 variant / export_import / codebuddy_cli / session / token_stats / rate_limit_hook 的平台相关断言,属上游既有问题(Linux / macOS 不受影响)。本分支未触碰这些文件。

同一批失败已在 #62 中修复(路径断言按 / 归一化 + SetFileTime 用可写句柄 + 兼容实现而非屏蔽测试)。

- 新增「账号发现」:以官方 auth 登录历史为主(含凭据、可补录)、storage/settings
  残留为辅,比对账号库列出「本机还有哪些账号没入册」,附凭据文件数 / 备份时间 /
  凭据是否可续期
- 新增「一键补录」:用该 uid 最新的 auth 历史备份构造账号记录写进账号库
  (写入前备份 accounts.json)
- 账号页顶部提示条:只在存在未入册账号时出现,补录后自动刷新列表
- 复用 `auth_file::imported_account_from_root`(仅提可见性为 pub(crate),无行为变化)
- 本地新增代码集中在 `api_local.rs` / `commands_local.rs`,
  `api.rs` / `main.rs` / `lib.rs` 各只加接线行

This branch has not been deployed

No deployments
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.

1 participant