Skip to content

边界契约审计:三不变量契约测试 + windows-path-contract 文档 + 代理驱动指南 - #570

Merged
caomengxuan666 merged 2 commits into
masterfrom
docs/boundary-contract-audit
Oct 12, 2026
Merged

caomengxuan666 merged 2 commits into
masterfrom
docs/boundary-contract-audit

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

背景

Owner 质询"核心设计(Windows native、无 MSYS/cygwin、POSIX 原生二进制都可用、该 verbatim 的不转换)有没有被近期合并推翻"。主会话判断没有,但边界保证从未被契约测试固化,代理全靠试错绕行。本 PR 把边界契约从部落知识变成测试 + 成文文档。纯增量:3 个测试文件 + 1 个文档 + AGENTS.md 指针,零 src/ 改动。

三不变量验证结论(对 master eb06295 逐边界实测)

不变量 结论 证据
A. native 核心 成立 rubash.exe 导入表纯 Win32/CRT(自写 PE 解析,无新依赖);winuxcmd 工具链同;.rdata 里的 msys 字符串是子进程检测探针非依赖;洗空 PATH 内建面照常工作
B. POSIX 形态可用 成立,2 处边缘违规 L1 shell 内 POSIX-in/POSIX-out(#556 契约)✅;L2/L3 工具操作数与子命令查找 ✅;L4 native 翻译统一 ✅;env 通道双类 verbatim ✅。违规:cd /c 裸盘根(#566)、winuxcmd find POSIX 起点(WinuxCmd#1170)
C. verbatim 保真 rubash 侧成立 #511/#555 家族回归完好(rm '$FIX/r' 报 GNU 同款错误且邻居无损);rev spec/分支名零转换;消息字节到 native 子进程逐位保真;GIT_SSH_COMMAND 通道 verbatim。外部违规:niugit stub 吃双引号(niu-git#7)

交付物

  1. 契约测试 tests/path_contract_boundary_{native_core,posix_forms,verbatim}.rs — 15 用例全绿(正面+反面;每不变量 ≥3);Windows 边界测试在 POSIX 平台自动 no-op;依赖安装树的单元(WINUXCMD_HOME)缺失时跳过并留提示。
  2. 文档 docs/windows-path-contract.md — 四层边界表(shell 内语义层 / 工具参数层 / 子进程查找层 / 原生子进程 argv 层)各自的 POSIX 形态可用性、verbatim 保证、转换归属;"如何正确驱动 niu"(shell 内 POSIX / 外部 native 或各工具自证 / 何时必须 D:/);"代理驱动指南"(§5,供以后所有代理任务书引用)。AGENTS.md 在 WinuxCmd 节加了指针。
  3. 违规台账(已开 issue,不在本 PR 修)

全量验证

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)

两者是语义差异而非路径形态违规,留给语义车道。

…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.
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