Skip to content

fix(path): translate /mnt/X drive argv for every child class (niubash#164) - #444

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/mnt-drive-argv
Oct 9, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/mnt-drive-argv

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

现象

同一个路径,内建能用、外部命令不能用:

命令 结果
cd /mnt/c ✅ 能进,pwd 回显 /mnt/c
ls /mnt/c ❌ cannot access '/mnt/c'
cp / grep / cat / find … ❌ 同上

cd 走内建 filesystem_path_for_display -> shell_path_to_windows(有 /mnt 分支);
外部命令走 argv 漏斗,/mnt/X 被归进 verbatim 组原样丢给子进程。

根因:/mnt/X 被归错了类

niubash#164 把 drive form 定义为 verbatim,前提是"子进程自己有 POSIX 层能解析它"。逐形态核对:

形态 WinuxCmd 认吗 证据
/d/x ✅ normalize_api_operand_w(src/utils/native_path.cppm)第 138–153 行,单字母盘符分支
/cygdrive/d/x ✅ 同函数第 112–137 行,先折叠成 /d/... 再走上分支
/mnt/d/x ❌ 不认 盘符判定要求字母后跟分隔符或结尾(is_separator(normalized[2]));/mnt/c 的 bytes[2] == 'n',判定失败
native exe ❌ 本就没 POSIX 层 #164 自己写的 "the child cannot perform itself"

winuxcmd 全仓搜 mnt 只有 8 处命中,全在 DOCS/ 和 scripts/,源码路径解析层零命中。

⇒ /mnt/X 跟虚拟系统根(/usr/bin、/etc…)同类,属于"shell 必须自己翻"那一类。

历史(/mnt 是何时、为何被关掉的)

日期 Commit 结果
2026-08-09 8956c23431bc 最初设计,所有外部参数一律翻译 → /mnt/c 能用
2026-08-13 07bbb81177fd/74638a989fe6 给 drive-shaped 加 verbatim 例外(#62)
2026-09-02 db404a6085ff 修 /mnt/cfoo 的 false positive → 说明当时还在翻
2026-10-03 5f7b1abf1dbd #164 把 /mnt/d/x 写进 verbatim 清单 → 关闭

#164 的 commit message 原文:

Untouched, pinned by tests: real drive forms (/d/x, /mnt/d/x, /cygdrive/d/x) keep the Option B per-child dialect

/mnt/d/x 是"长得像"被顺带归类的——同一个 commit 对 /usr/bin 真的去 probe 了("probe 2026-10-02, WinuxCmd build-dev 1.0.3"),对 /mnt 没有。

两条约束

  • niubash#62:"WinuxCmd (coreutils) must NOT change — the rule stays in the shell layer." → 只能修在 shell 侧。
  • niubash#164:"要么都翻、要么都不翻,不应按命令名单切分" → 现在 cd 翻 / ls 不翻,正是被禁止的切分。

改动

  • 新增 windows_mnt_drive_argument():/mnt/X 形状判定(/mnt/X 或 /mnt/X/...;/mnt/cfoo、/mnt/123 是普通词),单一来源
  • windows_external_absolute_argument_needs_translation 里的内联判定收敛到它(消重)
  • translated_virtual_system_root_argument 纳入该形态 → applet / dispatcher / native exe 一律收到 X:\...
  • /d/x、/cygdrive/d/x 保持 verbatim,字节未动

后果排查

项 结论
误伤 /mnt/cfoo 无,形状判定卡死(db404a6085ff 已修且有测试)
影响 /d/x、/cygdrive/d/x 无,仍在 verbatim 组
影响 Linux/macOS 无,全在 cfg!(windows) 内
重演 #62 的模式误伤 风险极低:/h/ 单字母容易偶然出现,/mnt/ 是完整词且只认单字母
兼容性 变好:/mnt/d/... 正是 WSL 下 GNU 的自然形态(rubash#329 里 GNU 就写 NVM_DIR="/mnt/d/…/nvm")

测试

  • 新增 windows_mnt_drive_argument_translates_for_every_child:形状类、applet 收到的拼写(/mnt/c → C:\,/mnt/d/repo/x → D:\repo\x)、MSYS 形态仍 verbatim
  • 修正 windows_virtual_system_root_arguments_keep_option_b_shapes_verbatim:把 /mnt/c 移出 verbatim 清单(该断言编码的前提是错的)

验证状态(如实说明)

cargo check --lib 在 Linux 侧通过。测试体全部 cfg(windows) 门控,Linux 上不参与编译,需要在 Windows runner 上跑。这不是"已测过"。

Closes unixwin/niubash#164 的遗留格。相关:unixwin/WinuxCmd#1145(/d/... 同族)。

…#164)

`cd /mnt/c` worked but `ls /mnt/c` (and every other external command)
failed on the same path. The builtin resolves through
`shell_path_to_windows`, which owns a `/mnt` branch; the external
argument funnel did not.

`/mnt/X` was classified with the verbatim drive forms (`/d/x`,
`/cygdrive/d/x`) on the premise that the child's own POSIX layer
resolves it. That premise holds for `/d/x` and `/cygdrive/d/x` —
WinuxCmd `normalize_api_operand_w` (`src/utils/native_path.cppm`) folds
`/cygdrive/d/...` into `/d/...` and then maps a bare `/X/...` drive
letter — but not for `/mnt/X`: that letter test requires a separator or
end-of-string after the letter, and `mnt` is `m` followed by `n`. A
repo-wide code search for `mnt` under unixwin/WinuxCmd returns only
docs and scripts, no parsing arm. No native exe has a POSIX layer at
all, so no child resolves the form.

That leaves `/mnt/X` in the same class as the virtual system roots
(niubash#164: shell-owned namespace the child cannot resolve), and the
same two constraints bound the fix: niubash#62 keeps the rule in the
shell layer (WinuxCmd must NOT change), and niubash#164 requires one
argv to arrive in one form for every child class ("要么都翻、要么都
不翻,不应按命令名单切分"). Translation also matches the form's
origin — `/mnt/d/...` is WSL's own spelling, which GNU writes verbatim
under WSL (rubash#329).

- new `windows_mnt_drive_argument()` owns the shape test
  (`/mnt/X` or `/mnt/X/...`; `/mnt/cfoo` and `/mnt/123` are ordinary
  words), and the inline copy in
  `windows_external_absolute_argument_needs_translation` collapses onto
  it so there is one source.
- `translated_virtual_system_root_argument` admits the form, so applets,
  the dispatcher and native exes all receive `X:\...` like every other
  root-class word.
- `/d/x` and `/cygdrive/d/x` stay verbatim, untouched.

Tests: `windows_mnt_drive_argument_translates_for_every_child` pins the
shape class, the applet spelling (`/mnt/c` -> `C:\`,
`/mnt/d/repo/x` -> `D:\repo\x`) and that the MSYS forms stay verbatim;
`windows_virtual_system_root_arguments_keep_option_b_shapes_verbatim`
drops `/mnt/c` from its verbatim list (that assertion encoded the wrong
premise). cfg(windows)-gated: cargo check --lib is the Linux-side line;
the test bodies need the Windows runner.
@caomengxuan666

Copy link
Copy Markdown
Member Author

Cross-link: filed the reporting side as unixwin/niubash#208 (the user-visible symptom — cd /mnt/c works, ls /mnt/c does not) and the platform roadmap as unixwin/niubash#207.

Related design constraints, both already quoted in the PR body:

No new target is invented: shell_path_to_windows has owned the /mnt/X -> X:\ mapping since 2026-08; this PR only routes the external-argument funnel through it.

@caomengxuan666 caomengxuan666 added the P1-high 高:核心语义或高频路径受损,影响日常使用/发布 label Oct 9, 2026
@caomengxuan666
caomengxuan666 merged commit 46d7942 into master Oct 9, 2026
6 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/mnt-drive-argv branch October 9, 2026 15:11
caomengxuan666 added a commit that referenced this pull request Oct 12, 2026
…ation - the /mnt contract belongs to the #444 translation tests (#574)

The verbatim loop in virtual_system_root_operand_resolution_keeps_option_b_
and_legacy_verbatim (ea36410, #177) still listed /mnt/c, contradicting the
#444 pin (46d7942) one file over - Windows --lib was permanently red.

The #568 'audit evidence' that the toolchain resolves /mnt natively was
measurement pollution: Git Bash converts /mnt/c -> C:\\ at spawn (MSYS2
WSL-interop), so ls.exe rc=0 tested Git Bash, not WinuxCmd. PowerShell
side-by-side (no POSIX layer): /d/repo ok, /cygdrive/d/repo ok,
/mnt/c/Windows ENOENT, touch rc=1 no file. Source audit to v1.1.6
(c40e939): normalize_api_operand_w only folds /cygdrive and single-letter
/X/; zero /mnt commits v1.1.2..v1.1.6.

- remove /mnt/c from the loop; comment pins the boundary (shape-class test
  proves windows_virtual_system_root_argument("/mnt/c") == false) and
  hands the /mnt contract to the #444 test, untouched
- docs/windows-path-contract.md L2: correct the polluted 1.1.5 note and
  the violation ledger entry
- feature ask for a native /mnt arm: WinuxCmd#1172

cargo test --lib executor::path: 68 passed (was 67+1). Full --no-fail-fast
failure set identical to fresh master by name.
caomengxuan666 added a commit that referenced this pull request Oct 13, 2026
…d class, context/position/existence invariant (closes #592) (#600)

* fix(path): POSIX drive-form operand pre-translation covers every child 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).

* fix(path): legacy-gate test takes the drive designator as a char (UTF-8 boundary hygiene)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P1-high 高:核心语义或高频路径受损,影响日常使用/发布

Projects

None yet

1 participant