Skip to content
This repository was archived by the owner on Sep 28, 2026. It is now read-only.

修复 doctor 对嵌套源 Git 生效门禁的假阴性 - #14

Merged
Eridanus117 merged 2 commits into
feature-portfrom
fix/doctor-effective-git-hook
Sep 7, 2026
Merged

Eridanus117 merged 2 commits into
feature-portfrom
fix/doctor-effective-git-hook

Conversation

@Eridanus117

@Eridanus117 Eridanus117 commented Sep 7, 2026 •

Copy link
Copy Markdown
Owner

问题与范围

注册源可以是 Git 仓内的嵌套知识目录。此前 doctor 只看 source 根的 lefthook/precommit 配置,即使父仓实际生效的 pre-commit 已执行 rhizome check,gate-present 仍失败。

本 PR 仅修改 README、src/rhizome/doctor.py、tests/test_doctor.py;不改 registry、hook 安装、PATH、uv 环境或依赖。

实现与静态边界

  • 既有 lefthook/precommit 配置及 run: Python/TypeScript wrapper 优先探测,原契约保持不变。未命中时才新增 Git 后备。
  • 通过 git -C <source> rev-parse --path-format=absolute --git-path hooks/pre-commit 获取唯一生效路径,不猜 .githooks 或 source/.git。支持嵌套源、linked worktree、相对/绝对 core.hooksPath;被覆盖的 .git/hooks 不得提供假证据。
  • argv 列表调用、不使用 shell;Git 路径输出显式按 UTF-8 解码,避免 Windows 默认 locale 破坏中文路径。Git 不可用/失败/超时维持有诊断的 FAIL,不执行 hook。
  • 仅识别行首直接 rhizome check 或 exec rhizome check,支持引号参数及行尾注释。注释/echo/近似命令不算;heredoc、跨行引号保守失败。不追踪任意 shell wrapper,不证明条件可达性,也不升级为全面 hook enforcement 审计。

已实际验证

  • Windows 真实 Git 回归含中文、空格、& 路径,并经过 doctor 新增 helper:旧 base cd6060e 为 5 failed / 2 passed / 1 skipped;修后 7 passed / 1 skipped;均另有 9 subtests passed。跳过项仅为 POSIX 执行位测试。
  • 真正 CLI 入口 python -m rhizome.cli doctor --sources --json,临时 registry + 嵌套 Git source + INDEX:旧 base exit 1 / gate FAIL,修后 exit 0 / gate PASS;切换 hooksPath 至不存在目录后 exit 1 / gate FAIL。未执行 fixture hook;临时目录已清理。
  • pyrefly 1.1.1 使用既有 Python 3.12 环境:0 errors。变更 Python 文件已由 Ruff 0.15.16 formatter 格式化。

Windows 完整测试的真实限制(未删失败项)

  • 实际完整 pytest:66 failed / 225 passed / 3 skipped,另 9 subtests passed。
  • 完整 tests/test_doctor.py:16 failed / 20 passed / 1 skipped,另 9 subtests passed。新增 Git 回归单独结果见上,不能冒充旧测试全绿。
  • 主要旧问题:tests/test_adopt.py、test_sources.py、test_relocate.py、test_config.py 及既有 doctor fixture 把 Windows C:\Users\... 原样插入 TOML 双引号字符串,触发 tomllib.TOMLDecodeError: Invalid hex value (at line 1, column 23),派生 CLI exit 2 断言失败。
  • 既有 amend shell fixture 未安全引用 Python 路径,代表性错误:.git/hooks/pre-commit: line 4: C:Workspacerhizome.venvScriptspython.exe: command not found;另有冻结 HEAD 判定失败。
  • 上述 test_adopt/test_amend/test_cli/test_config/test_relocate/test_sources 及对应生产模块未修改;本 PR 不扩大为 Windows 平台迁移。
  • 初始 head 的真实 Linux CI #34072471085 在旧 _wrapper_rhizome_check 的 C901 (11 > 10) 失败:实际 job 日志。单独 commit 4e90ce7 仅删除两行重复注释过滤分支;已有锚定 run: 的正则本就排除注释,不改变旧 wrapper 语义。真实 wrapper throwaway 验证 active 命中、普通/缩进注释均不命中。本地 canonical Ruff 全仓通过,format 检查 29 文件全部通过;未添加 noqa 或改规则。

合入与部署验收

只在最终 head 的真实 Linux CI 等适用检查全部成功后,按匹配 head SHA 合入。正常 PATH rhizome 已确认 editable 指向 C:/Workspace/rhizome;合后仅在该主目录 clean 且可 fast-forward 时同步 merge SHA,再用正常 PATH 命令对当前 desk/knowledge 做只读 post gate-present 验收。不重跑已知生产 pre 假阴性,不把隔离 CLI 结果当作日用命令已修复。

最终验收

  • 最终 head 4e90ce79b800500a20233bf2ca1f4dc896ff9864:10 项检查 SUCCESS,3 项 Release 条件检查 SKIPPED(build-library、publish、fleet-e2e);无失败或待运行检查。
  • 真实 Linux CI #34072584408:canonical Ruff 全通过,29 文件 format 通过,pyrefly 0 errors,完整 pytest 292 passed / 2 skipped。Linux 与 macOS 自包含构建和各自 smoke 均成功。
  • 使用 --match-head-commit 4e90ce79b800500a20233bf2ca1f4dc896ff9864 合入,回读状态 MERGED,merge SHA c2df9d7bb2121646f9aa7ef1cc21cc0e4b55209b。
  • 原正常 PATH rhizome 的 editable 部署目录 C:/Workspace/rhizome 保持 clean 且可快进,已从 cd6060e 安全 --ff-only 至 merge SHA,未更换安装、PATH 或 uv 环境。
  • 合后在 C:/Workspace/desk/knowledge 使用正常 rhizome doctor --sources --json(无 PYTHONPATH、registry 覆盖)只读验收:exit 0,knowledge.ok=true;gate-present=pass,证据路径为 C:/Workspace/desk/.githooks/pre-commit;gate-resolvable、index-present 均 pass。原有 notes 39 篇的 domain-capacity WARN 仍如实保留。仅在此次调用关闭 telemetry/bytecode 写入,未改全局环境。
  • 未运行生产 pre 对照,未触发真实 desk hook;Git 探测与新增 fixture 不执行 hook,完整既有测试套件保留其自身原有临时 hook 测试。未改 desk dirty 工作区、registry 或生产 compiled。临时 Git fixture/throwaway 目录已清理,验证证据仅存仓外。

@Eridanus117
Eridanus117 merged commit c2df9d7 into feature-port Sep 7, 2026
13 checks passed
@Eridanus117
Eridanus117 deleted the fix/doctor-effective-git-hook branch September 8, 2026 05:35
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant