Repository navigation
fix(path): POSIX drive-form operand pre-translation covers every child class, context/position/existence invariant (closes #592) - #600
Merged
Conversation
…d class, context/position/existence invariant (closes #592) The argv funnel handed drive-form operands (/d/...) to POSIX-aware children verbatim on the Option-B premise that each tool resolves them itself. The shipped toolchain breaks that premise three ways: sed/du 1.1.5 have no operand resolution at all (WinuxCmd#1178), usr/bin/git.exe existence-gates it (git -C /d/existing works while worktree add /d/new silently lands at D:\d\new), and the niubash host's name-list translation (normalize_winuxcmd_slash_drive_args) runs only at top-level AST points - so the same command drifted by execution context (issue #592: sed/du fail inside for-loops/subshells, fine at top level). The engine now owns path-form pre-translation for EVERY non-shell-wrapped child class: the POSIX-aware arm routes non-exempt words through external_argument_path (the native funnel), making the translation invariant across execution context (single funnel: -c, script files, loops, subshells, functions, pipelines, command substitution), argument position (positional operands, -C-style flag values, to-be-created targets - no existence gate outside the legacy hatch) and target existence. Data operands stay verbatim (invariant C, niubash#62 - shape cannot separate ls /d/ from grep -F /h/): argv_data_primary_positions ports the niubash host's winuxcmd_path_translation_mask table (grep/sed/awk first positional pattern/script/program text, find pattern-primary values) and adds the filesystem-blind string transforms basename/dirname (GNU dirname.c/basename.c never stat their operand; issue71 pins dirname /a/b/c.txt -> /a/b). All pre-existing exemptions keep their exact behavior: natives, shell-wrapped children, /cygdrive/d (folds in-child, #568 probe), /dev/*, bare /, cmd switches, attached --opt=/x values, the env channel, rev specs. __RUBASH_ARGV_DIALECT=legacy reverts the whole widening to the pre-#592 existence-gated funnel. Superseded pins flipped (#444 precedent): /c/Windows and /d/x verbatim pins for the applet class now assert the translated form; the B2 negative ls-$nosuchvar pin keeps its no-re-expansion intent. New pins: funnel-level drive-form/mask/legacy tests plus tests/issue592_argv_translation_completeness.rs (context x position x existence matrix with real sed/tee, verbatim exemption probes with real grep -F/sed/find/env, legacy bypass regression, and a real git worktree add /d/new end-to-end asserting the worktree list location). cargo check -D warnings clean (windows + unix + macos targets), fmt clean, full cargo test --no-fail-fast failure set identical to fresh master fcf7be1 bidirectionally (41 pre-existing host-environment failures, zero new, zero lost).
…-8 boundary hygiene)
caomengxuan666
added a commit
that referenced
this pull request
Oct 13, 2026
…601) 40 commits (PRs #496-#600) folded into [1.4.0] by theme instead of per-commit listing: - GNU semantics waves 1-4b with their issue families - argv re-expansion P0 pair (#511/#555), PWD POSIX persona (#537) - -s on-demand stdin driver as the canonical library reader (#586) - CLI entry-shape semantics (#589-#591) and the GNU usage contract (#585) - diagnostic message fidelity (#551) and parser diagnostic tokens - Windows path contract (#568/#592) - lexer/executor performance rounds (#554/#562/#501) - docs: boundary invariants, platform gap, baselines, debugger M0 Commit message deliberately carries no release/version claim.
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.
fix(path): POSIX 路径操作数预翻译对上下文/参数位/存在性无条件生效 (closes #592)
现象(issue 三实证,全部在本 PR 上复现→修复后转绿)
for循环/子壳/函数里sed -n 1p /d/...、du -s /d/...ENOENT,顶层同命令 OK;find | xargs sed -i链失败——报错伪装成 ENOENT。git -C /d/已存在 status正常;git worktree add /d/待建路径 branch不翻译——实际落到D:\d\...(当前盘根下相对路径),agent 实踩。根因(file:line)
src/executor/path.rsexternal_command_for_named_program(修复前 L896-920)的 argv 漏斗里preserve_native_args || shell_wrapped || posix_aware → arg.clone()——POSIX-aware 子类(winuxcmd 树内一切,含 sed/du/usr/bin/git.exe)整类 verbatim,盘符形态(/d/x)从不翻译。Option B"子进程自有 POSIX 层自解析"的前提对在售工具链三处不成立:usr/bin/sed.exe -n 1p /d/...直打 ENOENT 实测;[bug] fc -e - <n> with empty history silently succeeds #1178 为工具侧补齐);-C /d/已存在✅、worktree add /d/待建❌(GetFullPathName 类规范化只对 stat 得到的路径生效);$THIS_SH script.sh(in-process re-exec suspect): following output written into the redirect file #164/fix(path): translate /mnt/X drive argv for every child class (niubash#164) #444)恰好证明引擎有能力兜底,唯独盘符形态漏了。crates/niubash-runtime/src/shell.rs::normalize_winuxcmd_slash_drive_args,挂点 L838/2101/4992/5004/5045)在顶层 AST 点按工具名单做翻译 → 顶层 OK;for/子壳/函数/script 内不经宿主 → 引擎 verbatim → ENOENT。这正是 issue 标题"随执行上下文漂移"的机制。引擎补齐后两个层面收敛到同一行为。git.exe -C /d/已存在 statusrc=0,git.exe worktree add /d/新路径落D:\d\新路径——存在性门在 git 侧,rubash verbatim 放大了它。设计判据(规则表)
什么算 path 形操作数(候选,对所有非 shell 包裹子类):
/X/...单字母盘符形/d/repo/xD:\repo\x(#592 起 POSIX-aware 子类也翻;此前仅原生类)/c/...显示路径拼写/c/Windows/mnt/X[/...]/mnt/c/Users/tmp、/usr/bin、/etc/.../cygdrive/X/.../cygdrive/d/xnormalize_api_operand_w自折叠,#568 四路复测)/dev、/dev/*/dev/null///X...(非盘符)/nologo、/CN=test/C由 preserve_native_args 兜住)x:/...、x:\...D:/repoC://宿主伪影由 repair 规则修复)\rel/file、\n参数位豁免/处理:
sed -n 1p /d/fgit -C /d/repo、find /d/start -name xgit worktree add /d/new、tee /d/new__RUBASH_ARGV_DIALECT=legacy恢复旧存在性门)--opt=/xgit --git-dir=/x、--flag=/usr/bin--git-dir /x的路径词照常翻译且实测可用)env VAR=/posix ls-name族值grep -F /d/x、sed /n/d、awk '{...}'、find -name /d*winuxcmd_path_translation_mask同一张表,不新开豁免口子。-e/--regexp/-f/--file语义与宿主一致:-e值是数据,-f值是文件)dirname /a/b/c.txt→/a/borigin/feat/x、HEAD~1..HEAD、feat/slash.main执行上下文:顶层 / for 循环 / 子壳 / 花括号组 / 函数 / 管道 / 命令替换 / script 文件 /
-c——全部经同一漏斗external_command_for_named_program,上下文无关是结构性保证(漏斗不感知上下文),矩阵测试逐格锁定。verbatim 红线对照(#568 裁决 / #444 断言 / 既有豁免表,零新增豁免):
windows_native_argv_never_mixed_dialect等既有 pin 全绿);#!子进程:verbatim 不变(rubash#259 混域教训);/cygdrive、/dev/*、裸/、开关、附着值、env 值、rev spec:全部维持既有豁免;修法
external_command_for_named_program:POSIX-aware 臂不再整类 verbatim——非豁免词走external_argument_path(与原生类同一漏斗:盘符形态无条件翻译、/cygdrive//dev/裸//开关/相对词规则共用);argv_data_primary_positions按命令名+词位算出数据主位置(宿主同表移植:grep/sed/awk/find 语法数据 + 不触 FS 的 dirname/basename 字符串变换),命中即 verbatim。legacy 方言下posix_aware仍为 false → 落回原生漏斗的旧存在性门语义(回滚阀保留不动)。windows_virtual_system_root_arguments_keep_option_b_shapes_verbatim(/c/Windows移出)、windows_mnt_drive_argument_translates_for_every_child(/d/repo/x翻转)、virtual_system_root_operand_resolution_keeps_option_b_and_legacy_verbatim(同)、windows_native_argv_never_mixed_dialect(POSIX-aware 阶段改为双类同形断言)。drive_form_arguments_translate_for_the_posix_aware_child/data_primary_operands_stay_verbatim_for_the_applet/legacy_dialect_reverts_drive_form_translation_for_the_applet;集成级tests/issue592_argv_translation_completeness.rs(①上下文×参数位×存在性矩阵——真实 sed/tee 子进程,含 script 文件上下文;②verbatim 豁免对照——真实 grep -F/sed 地址/find -name/env 值;③legacy 绕过回归;④真实git worktree add /d/新路径端到端,worktree list 验位)。docs/windows-path-contract.md(L2/L4 行 + §2 L2 [path][P2] POSIX absolute-path operand translation drifts by execution context: sed/du fail inside for-loops/subshells, fine at top level #592 条目 + §6 台账)、docs/platform-identity.md(per-child dialect 段落改为"引擎拥有全类 path 形翻译")。验证
cargo check+RUSTFLAGS=-D warnings✅;cargo fmt --check✅;unix/macos 目标cargo check✅(新代码全在#[cfg(windows)]内;unix 下cargo check --tests -D warnings的 issue544/531/530 告警为预存,fresh master 同)。cargo test --lib660 全绿(含 3 个新漏斗 pin);tests/path_contract_boundary_*、issue177/331/566/588 全绿(1 个 B② 反例 pin 按 [path][P2] POSIX absolute-path operand translation drifts by execution context: sed/du fail inside for-loops/subshells, fine at top level #592 契约更新:$nosuchvar字面分量不再展开的本质不变,回显形态随漏斗翻译)。cargo test --no-fail-fast(RUST_TEST_THREADS=1,.cargo/config 强制):失败集与 fresh master(fcf7be16,独立基线 worktree + 子模块主仓复制/gitdir 指向)双向 comm 为空(43 个预存宿主环境失败:bashdb fixture/pwsh 缺失/prompt/heredoc 环境类;零新增、零消失)。for循环/子壳/函数/花括号/管道/命令替换/script 文件 ×sed -n 1p /d/...全部 rc=0;git worktree add /d/tmp/wt-fixed wtbranch落位D:\tmp\wt-fixed(修复前D:\d\tmp\wt-fixed);__RUBASH_ARGV_DIALECT=legacy循环内旧行为复现(已存在翻译/缺失 verbatim)。xargs/find -exec链中由工具自构造的子 argv(xargs sed -i /d/...)不经引擎漏斗,归 WinuxCmd 工具侧([bug] fc -e - <n> with empty history silently succeeds #1178/[bug] Negative index on unset array drops bad-subscript diagnostic #1170 车道);commit -m '/d/x'类自由文本以形状契约为准(与原生类既有行为一致)。回滚阀:
__RUBASH_ARGV_DIALECT=legacy原样保留。closes #592