Skip to content

feat(selfupdate): 自动更新提醒 + 一键更新 - #2

Merged
suny911 merged 5 commits into
mainfrom
worktree-self-update
Jul 4, 2026
Merged

feat(selfupdate): 自动更新提醒 + 一键更新#2
suny911 merged 5 commits into
mainfrom
worktree-self-update

Conversation

@suny911

@suny911 suny911 commented Jul 4, 2026

Copy link
Copy Markdown
Collaborator

概要

guling-trader 启动时对比 GitHub 最新 Release 版本号,发现新版本在主窗口内联横幅提醒;用户点「立即更新」后程序自己下载新 exe、校验 SHA256、Windows 下重命名自替换并重启,无需手动下载。

设计定稿见 docs/superpowers/specs/2026-07-04-self-update-design.md,实施计划见 docs/superpowers/plans/2026-07-04-self-update.md

改了什么

  • 新增 src/trader/selfupdate/:check.py(查 GitHub Release 比三段式版本号,非 Windows / 网络异常一律 fail-closed 返回 None)、apply.py(下载→SHA256 校验→os.rename 自替换含失败回滚→释放单例 mutex→拉新进程→os._exit;含孤儿 .old/.new 清理)。
  • main_window.py:SharedState 新增 3 字段(info/progress/status)、内联横幅 UI(idle/downloading/error 三态)、「立即更新」防重入置灰。
  • main.py:启动 Step 1.5 孤儿清理 + Step 2.5 自更新检查;「立即更新」按钮回调经 run_coroutine_threadsafe 丢后台 loop;release_singleton_mutex()(含 None 保护、依赖注入避免循环导入)。
  • 不改 ui_dialogs.py(其弹窗类是全仓未实例化的死代码,本次不复活)。

关键设计取舍

  • 跨线程严格分离:Tk 只在主线程碰,跨线程一律经带 lock 的 SharedState
  • 只做启动查一次,不做后台轮询、不做静默更新、不做「忽略此版本」持久化。
  • SHA256 只防传输损坏/篡改,不是代码签名,防不了仓库本身被攻破(已知局限,见设计文档)。
  • 仅 Windows 生效(exe 只发 Windows),非 Windows 不查不弹。

测试

  • 新增 20 个单元测试(check 8 / apply 10 / main_window state 2),全量 pytest tests/ 95 passed / 10 skipped(skip 均为 Windows-only,macOS 上按预期跳过),项目原有 75 个测试无回归。
  • 未做端到端真机自动化(Windows 重命名运行中 exe + mutex 时序 + Tk 渲染无法在 CI 覆盖,ROI 低)→ 计划 Task 6 列了 7 项发布前真机人工验证清单,合入后发版前需在 Windows 真机走一遍

独立 code-review 结论

已过两轮独立审查(code-reviewer + 人工复核):0 BLOCKER。若干 WARNING/INFO 均为已在设计中拍板的取舍(三段式版本不引 packaging、SharedState 保持零依赖、双保险 try/except)或概率可忽略的极端边界(两次 rename 同时失败,上层已拦住不会拉起坏进程),不阻塞合入。

🤖 Generated with Claude Code

suny911 and others added 5 commits July 4, 2026 09:15
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@suny911
suny911 marked this pull request as ready for review July 4, 2026 01:44
@suny911
suny911 merged commit b2df3ef into main Jul 4, 2026
1 check passed
@suny911
suny911 deleted the worktree-self-update branch July 4, 2026 02:03
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