Repository navigation
fix(change-window): preserve LF in managed Git scripts - #8598
huangruiteng merged 1 commit into
Conversation
Signed-off-by: xiaobaifly7 <196511160+xiaobaifly7@users.noreply.github.com>
loopx-agent
left a comment
There was a problem hiding this comment.
Reviewer: model_agent · gpt-6.1-sol · OpenAI · runtime_reported · max
本次评审对应提交 40b9210490106c61e3d6d3da14c7f31f6334efee。
动机 / Motivation
明确为本地 Git 仓库启用 change-window 的操作员,需要在安装后确认提交和传输保护已经可用。文本写入采用平台换行。当默认换行为 CRLF 时,install 成功后 verify 将未修改的脚本标为 drifted。模拟默认 CRLF 时,两种模式的安装从 verify=drifted 变为 ready,已安装的 CRLF fixture 可通过 --replace 恢复。模拟默认 CRLF 时,两种模式的安装从 verify=drifted 变为 ready,已安装的 CRLF fixture 可通过 --replace 恢复。独立验证用 macOS Git,并在两个文本写点模拟 Windows 默认 CRLF。Windows 原机结果来自作者,已安装版本和托管 CI 未纳入验证。
改动思路 / Approach
LF 是现有脚本模板和摘要的共同字节约定,写入时明确编码即可。代码保留在现有 Python Git IO provider。策略决定和 typed CLI 状态沿用当前结构。 现有模板以 LF 构造,旧 writer 在默认 CRLF 环境会把 LF 转换成 CRLF。verify 按真实磁盘字节做摘要并判漂移。在两个写点指定 newline,让字节与既有摘要协议对齐。
具体改动 / Changes
关键代码讲解
- 在两种模式逐个检查受管脚本的原始字节、可执行位和保存的 SHA-256。模拟默认 CRLF 时基线 install 成功但 verify 漂移,当前提交生成 LF 且立即 ready。 文件写入
- macOS 临时仓库使用真实 Git hook。允许时转交原 hook,受限窗口拒绝提交前 hook,reference_guard 的 SSH wrapper 将读取请求实参交给原有本地命令。 校验
- 两种模式的篡改均被拒绝。把基线生成的两套 CRLF 安装交给新提交,保留旧窗口执行 --replace 后恢复 ready。卸载恢复原有 hooksPath 与 sshCommand。 回归
适用协议 loopx/capabilities/repository_change_window/README.md,按基线 23bc2e0 核对。对应检查为 portable_script_bytes、exact_byte_drift 和 existing_recovery_route。 协议
对主干的风险 / Risks
作用范围限于明确启用 provider 的仓库和生成的 Git shell 脚本。预览与默认关闭在两版均没有写 provider 文件。历史 CRLF 安装会继续报告漂移,显式按原窗口执行 --replace 后可恢复。我在 macOS 使用真实 Git,并在文件写入处模拟 Windows 默认换行。Windows 原机验收为作者报告,已安装版与托管 CI 未复验。
语义与 CI 对齐
28 项相关测试通过,Ruff、DCO、RFC 双语差异与 git diff --check 通过。两版在 macOS 上普通安装、受管 hook、原命令转交和卸载的观测一致,两种模式模拟 CRLF 都有红绿结果。
我的整体评价 / Verdict
两种安装模式现在都能落盘 LF 并通过原有校验。实际字节篡改、默认关闭、已有配置和修复路径均有独立证据。改动集中在现有文件 writer,可以通过评审。本次评审覆盖现有宿主与 CLI 行为。独立验证用 macOS Git,并在两个文本写点模拟 Windows 默认 CRLF。Windows 原机结果来自作者,已安装版本和托管 CI 未纳入验证。
English verdict: APPROVE. Both enforcement levels now write stable LF bytes, which the existing exact-byte verification accepts. Matched macOS Git execution and CRLF translation simulation confirm install, drift, replacement, and restoration. The author supplied the native Windows run.
Goal And Delivered Outcome
status=driftedandenabled=false; after this change, the same fresh-repository journey returnsstatus=ready,verified=true, andenabled=true. Both enforcement levels have regression coverage.main, reproduced at23bc2e0ed8dc8233620b3e349d686a55941dfc41.Author Declaration
Implemented against
loopx/capabilities/repository_change_window/README.mdat the base revision above.git_hook.py::_write_provider_filestest_cli_install_verify_round_trip_preserves_lf_scriptsgit_hook.py::_provider_checksremains unchangedgit_hook.pyEnforcementLevelvaluesScope And Continuation
install --replacerecovery path.Validation
40b9210490106c61e3d6d3da14c7f31f6334efee.regression_parityuv run --extra test python -m pytest -q tests/capabilities/test_repository_change_window.py -k test_cli_install_verify_round_trip_preserves_lf_scriptsfailed both enforcement cases at immediate verify. After the fix, both passed.unituv run --extra test python -m pytest -q tests/capabilities/test_repository_change_window.py tests/capabilities/test_repository_change_window_negative.py -k 'test_cli_install_verify_round_trip_preserves_lf_scripts or policy': 5 passed, 23 deselected on Windows / Python 3.12.13. Includes script-tampering rejection and existing policy cases.real_entrypointuv run --extra test loopxconsole against a fresh synthetic Git repository. Install succeeded and verify returned ready/enabled/verified after the fix; the same console journey reproduced drift on the unchanged base.staticuv run --extra test python -m ruff check loopx/capabilities/repository_change_window/git_hook.py tests/capabilities/test_repository_change_window.py;git diff --check.git mktreestdin adds CRLF on Windows; the new regression uses a fresh empty commit instead, leaving that unrelated fixture unchanged. The focused selection is not a claim that the full existing module passes on Windows.Frontend / Visual Evidence
Type of Change
LoopX Area
Technical Direction
repository-change-windowcapability, bundledgit-hookprovider. This bounded Python IO fix retains the existing owner and public contracts.Shared-authority RFC fixture impact
N/A; no shared-authority routing, persistence or migration behavior changes.
Boundary Checklist
none.Signed-off-bytrailer (git commit -s).🤖 Generated with Claude Code