Repository navigation
边界契约审计:三不变量契约测试 + windows-path-contract 文档 + 代理驱动指南 - #570
Merged
Merged
Conversation
…e core / POSIX forms / verbatim) The core design (Windows native, no MSYS/cygwin, POSIX-form tool operands, verbatim where promised) had zero contract tests - agents kept rediscovering the boundaries by trial and error. This pins them against current master: - tests/path_contract_boundary_native_core.rs (invariant A): PE import-table parser (no new deps) proves rubash.exe imports only Windows system DLLs and never an msys/cygwin runtime (the msys-2.0.dll strings in .rdata are the per-child detection probes, so the check reads imports, not bytes); the builtin surface runs with a System32-only PATH; native children receive Win32 cwd translations, never the POSIX persona. The installed winuxcmd toolchain (WINUXCMD_HOME-guarded) gets the same zero-POSIX- runtime check per tool. - tests/path_contract_boundary_posix_forms.rs (invariant B): POSIX-in / POSIX-out for cd/pwd/$PWD/$(pwd)/redirect targets (the #537/#556 contract, native-style host vars inert); native D:/ operands accepted; winuxcmd touch/ls/env/timeout/xargs + find -exec child lookup take explicit POSIX operands (find start-path gap is filed, not pinned); literal $-operands stay verbatim through the tool layer; PWD reaches POSIX-aware AND native children verbatim on the env channel. - tests/path_contract_boundary_verbatim.rs (invariant C): the #511/#555 family (cat/rm/cp/touch vs '$FIX/x' operands) never touches the expansion neighbor; git rev specs (origin/feat/x, HEAD~1..HEAD, HEAD -- path, slash branches) cross verbatim; commit -m-shaped message bytes survive rubash's native-argv quoting byte-exactly; GIT_SSH_COMMAND-style env values pass through untouched. 15 cases, all green; Windows-boundary tests no-op on POSIX. Known red edges are filed as issues, deliberately not pinned: rubash#566 (bare cd /c under a configured shell root), WinuxCmd#1170 (find POSIX start paths), niu-git#7 (git.exe launcher drops argv quotes), rubash#568 (/mnt/c verbatim-vs-translate contract contradiction, master --lib red on Windows). - docs/windows-path-contract.md: the four-layer boundary table (in-shell semantics / tool operands / sub-command lookup / native-child argv) - POSIX-form availability, verbatim guarantees, and who owns the conversion at each layer - plus how to drive niu correctly (POSIX inside the shell, native or per-tool POSIX outside, when D:/ forms are mandatory) and the agent-driving guide (why probes hit rubash.exe directly, why D:/ for git literals, why LF script files beat nested -c quoting) for future task briefs. AGENTS.md gets a pointer at the WinuxCmd section. Full cargo test --no-fail-fast vs a pristine eb06295 worktree, same session: failure sets identical (46 pre-existing host-env failures, zero new, zero fixed). cargo fmt --check clean.
The contract's verification target IS the Windows-native behavior, so the three path_contract_boundary_* files are now #![cfg(windows)]-gated as a whole: unix CI cfg-strips them to empty test binaries and proves only compilation, not the cases (the cases need a Windows runner; the winuxcmd toolchain leg additionally self-skips without WINUXCMD_HOME). Module docs state this explicitly. The redundant per-test runtime guards and the require_windows helper (cfg(windows)-gated but referenced unconditionally - the actual linux/darwin/android build break) are gone with the gate. Verified locally: cargo check --tests --target x86_64-unknown-linux-gnu and --target aarch64-linux-android both finish clean; Windows-side the suites are unchanged (5 + 6 + 4, all green); cargo fmt --check clean.
This was referenced Oct 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
Owner 质询"核心设计(Windows native、无 MSYS/cygwin、POSIX 原生二进制都可用、该 verbatim 的不转换)有没有被近期合并推翻"。主会话判断没有,但边界保证从未被契约测试固化,代理全靠试错绕行。本 PR 把边界契约从部落知识变成测试 + 成文文档。纯增量:3 个测试文件 + 1 个文档 + AGENTS.md 指针,零 src/ 改动。
三不变量验证结论(对 master eb06295 逐边界实测)
.rdata里的 msys 字符串是子进程检测探针非依赖;洗空 PATH 内建面照常工作cd /c裸盘根(#566)、winuxcmd find POSIX 起点(WinuxCmd#1170)rm '$FIX/r'报 GNU 同款错误且邻居无损);rev spec/分支名零转换;消息字节到 native 子进程逐位保真;GIT_SSH_COMMAND 通道 verbatim。外部违规:niugit stub 吃双引号(niu-git#7)交付物
tests/path_contract_boundary_{native_core,posix_forms,verbatim}.rs— 15 用例全绿(正面+反面;每不变量 ≥3);Windows 边界测试在 POSIX 平台自动 no-op;依赖安装树的单元(WINUXCMD_HOME)缺失时跳过并留提示。docs/windows-path-contract.md— 四层边界表(shell 内语义层 / 工具参数层 / 子进程查找层 / 原生子进程 argv 层)各自的 POSIX 形态可用性、verbatim 保证、转换归属;"如何正确驱动 niu"(shell 内 POSIX / 外部 native 或各工具自证 / 何时必须 D:/);"代理驱动指南"(§5,供以后所有代理任务书引用)。AGENTS.md 在 WinuxCmd 节加了指针。cd /c(裸盘根 POSIX 形态)ENOENT(fix(pwd): PWD family unconditionally POSIX /<drive>/ form — retire the native-PWD style hatch (#537) #556 区间暴露;/c/正常,/d能用是 winuxcmd 根下恰有 d/ 目录的巧合)/c/...、/d/...ENOENT(工具层唯一例外;-exec子命令查找不受影响)--libWindows 恒红:/mnt/cverbatim 断言与 fix(path): translate /mnt/X drive argv for every child class (niubash#164) #444"全类翻译"互相矛盾(两测试指证相反;且 fix(path): translate /mnt/X drive argv for every child class (niubash#164) #444 的前提——工具链不认 /mnt——已被 WinuxCmd 1.1.5 实测消解),需 owner 裁决方向全量验证
cargo test --no-fail-fast:与干净 eb06295 worktree 同环境对比,失败集逐字节一致(46 个预存宿主环境失败:--lib 1(即 #568)+ cli_tests 28 + executor_tests 17;零新增、零消失)。cargo fmt --check干净。非边界类旁证(记录在文档 §6,未开票)
external_rmdir失败操作恒 rc=0 且无 stderr(GNU 应报错 rc=1)external_mkdir自动补齐缺失父链(GNU 裸 mkdir 应 ENOENT)两者是语义差异而非路径形态违规,留给语义车道。