Skip to content

fix(review-gate): 审查前 checkout 到被审 head sha + 回读校验 - #18

Merged
tizerluo merged 2 commits into
mainfrom
fix/review-gate-checkout-head
Aug 15, 2026
Merged

fix(review-gate): 审查前 checkout 到被审 head sha + 回读校验#18
tizerluo merged 2 commits into
mainfrom
fix/review-gate-checkout-head

Conversation

@tizerluo

Copy link
Copy Markdown
Owner

Fixes #17

问题

mimosa 扫描读的是 clone 工作区文件而非 git 对象库——fetch 只更新对象、不动工作区。不 checkout 时,PR 推新 commit 后工作区仍停留在上一轮的旧代码上,扫描基于陈旧代码:误报已修复的问题、漏报新引入的问题。

修复

  • 新增 checkout_review_head()git checkout --force --detach <head_sha> + rev-parse HEAD 回读校验,不一致抛 GitError 拒绝继续(防浅 clone 缺对象等静默失败让扫描基线名不副实)
  • process_prfetch_pr_refs 后、--call 前接线,失败走 mark_failure 退避
  • 评论表头 head 行标注「mimosa 扫描基线」语义,供与 PR head 对账
  • README 流程图与说明同步

测试

  • 单测 3 例:正常路径命令形状 / rev-parse 不一致拒绝 / checkout 失败上抛
  • 全链路 fake git 记账 checkout 与 rev-parse 回显;full_cycle 断言审查链路中 checkout 命令的 sha 与 --call 的 head 一致
  • python3 tests/test_review_gate.py 75 全绿 + ruff 通过

mimosa 扫描读的是 clone 工作区文件而非 git 对象库 — fetch 只更新对象、
不动工作区, 不 checkout 会扫在上一轮旧代码上 (误报已修复/漏报新引入)。

- checkout_review_head(): --force --detach 到被审 sha, rev-parse 回读校验,
  不一致抛 GitError 拒绝继续 (防浅 clone 缺对象等静默失败)
- process_pr 在 fetch_pr_refs 后、--call 前接线, 失败走 mark_failure 退避
- 评论表头 head 行标注扫描基线语义
- 单测 3 例 + 全链路 fake git 记账 checkout/rev-parse 回显
PR #18 用 zcode_pr_review 自审发现的跟进修复:

- P1-1 实例互斥: checkout 发生在 bridge 侧文件锁之外, 双实例共享同一
  state/clone_root 时, 第二实例 (守护进程跑长审查期间手工 --once 调试)
  会在 mimosa 扫描中途换掉工作区 (TOCTOU) → 静默扫错代码。
  修法: 启动时对 <state_file>.lock 非阻塞 flock, 拿不到锁 exit 2;
  正常退出释放, 崩溃时 OS 自动回收。
- P2-1 checkout --force 只丢弃 tracked 改动, untracked 残留跨轮存活
  (mimosa 扫工作区文件) → checkout 前补 git clean --force -d -x,
  clone 为 gate 专有目录, 清到严格基线。

P2-2 (README 三态 verdict) 是跨分支审查视角产物, #19 合入后自然消解。
测试: fake git 补 clean 处理; +2 例 (clean 先于 checkout / 实例锁退出码
2 且不跑审查, 释放后可续跑); 77 全绿。
@tizerluo

Copy link
Copy Markdown
Owner Author

狗食审查(zcode_pr_review 自审)

结论:可以合并(P0 × 0 / P1 × 1 / P2 × 3),P1/P2 已在 f20cdd0 闭环:

  • ✅ P1-1 实例互斥锁:checkout 发生在 bridge 锁外,双实例共享 state/clone_root 会在 mimosa 扫描中途换工作区(TOCTOU)→ 新增 <state_file>.lock 非阻塞 flock,拿不到锁 exit 2
  • ✅ P2-1 untracked 残留:checkout 前补 git clean --force -d -x
  • ℹ️ P2-2(README 三态 verdict 与代码不符)为跨分支审查视角产物,fix: verdict 结构化标记 + 解析失败降级'需人工核对' #19 合入后自然消解
  • ℹ️ P2-3(报告嵌评论注入面)为存量路径,本次未触碰

@tizerluo
tizerluo merged commit 50a5b57 into main Aug 15, 2026
4 checks passed
@tizerluo
tizerluo deleted the fix/review-gate-checkout-head branch August 15, 2026 21:50
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.

mimosa 扫描跑在过期 checkout,审查基于陈旧代码(工具链债)

1 participant