Skip to content

feat(native-path): resolve /mnt/X WSL interop drive operands (closes #1172) - #1227

Merged
caomengxuan666 merged 2 commits into
mainfrom
feat/1172-mnt-drive-dialect
Oct 18, 2026
Merged

caomengxuan666 merged 2 commits into
mainfrom
feat/1172-mnt-drive-dialect

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

fix(native-path): resolve /mnt/X WSL interop drive operands (closes #1172)

现象与需求面(实测定位)

normalize_api_operand_w 只有 /cygdrive 折叠(#1145)+ 单字母 /X/ 盘符臂 + niubash#346 的 shell-root 门控 shell-ns 臂。standalone(无 shell root 环境变量)时 /mnt/c/... 落空:

实测矩阵(本机 Win10 19045,PowerShell 原生 argv,本 PR 构建物;修复前 → 修复后):

场景 命令 修复前 修复后 走的层
直接调用(清四个 shell-root 变量) winuxcmd ls /mnt/c/Windows/System32/attrib.exe rc=2 ❌ rc=0 ✅ 本 PR(native 折叠臂)
直接调用(同上) winuxcmd du -s /mnt/c/Windows rc=1 ❌ rc=0 ✅ 同上(#1178 共享边界)
直接调用(同上) winuxcmd sed -n 1p /mnt/c/Windows/win.ini ❌ rc=0 ✅ 同上
直接调用(同上) winuxcmd touch /mnt/c/<tmp> ❌ 未落盘 文件落在 C: 目标位 ✅ 同上
直接调用(__RUBASH_SHELL_ROOT 在场) winuxcmd ls /mnt/c/... rc=0 rc=0(不变) niubash#346 shell-ns 臂
niu -c 'ls /mnt/c/...'(niu 1.4.0 = rubash e785c3c8,含 #592) rc=0 rc=0(不变) rubash 引擎 #444 全类预翻译

两个关键实证:

  1. rubash#568 "v1.1.5 直打已通" 的假象定位:那轮 PowerShell 直打继承了 Niubash 安装注入的 __RUBASH_SHELL_ROOT/NIU_ROOT,走的是 [candidate] vdir: bug(vdir): when using -R with a large nested file it leads to a no human readable err (uutils#12827) #346 shell-ns 门控臂;清掉变量即复现缺口。本次实测坐实,rubash#568 方向 A(维持 [wording] Split enters endless loop (uutils#14118) #444)的裁决前提无误。
  2. rubash 顶层已覆盖(niu -c 实测 ✅):feature: native 层解析 /mnt/X 形态(WSL 互操作路径;rubash#568 裁决实证全系无支持) #1172 的真实需求面 = 不经 rubash 的直接调用 + rubash PR#600"已知边界"显式归工具侧的 xargs/find -exec 自构造子 argv 链。

归属裁决:native 单层落地,rubash 侧不动(两层各管各的面)

与 rubash#592(PR#600)的层面对照表

维度 rubash 引擎侧(#444 + #592/PR#600,不动) WinuxCmd native 侧(本 PR)
覆盖面 顶层漏斗 external_command_for_named_program:一切外部命令、一切执行上下文(for/子壳/函数/管道/-c/script) 工具进程内部:直接调用(无 rubash)+ xargs/find -exec 自构造子 argv 链(PR#600 显式划归工具侧车道)
/mnt/X 处理 windows_mnt_drive_argument 恒翻译(#444 起,非豁免) normalize_api_operand_w 新折叠臂 → /X/ → 既有盘符臂 → X:\
形状规则 小写 mnt 字面量;盘符 [A-Za-z];精确 /mnt/X 或 /mnt/X/...([6] 分隔符或串尾) 逐字一致(注释里点名字节对齐,两仓不漂移)
/mnt、/mnt/data 不翻译(普通 POSIX 词,rubash 同注释) 不翻译(同)
/cygdrive/X/ verbatim(native 自折叠) cygdrive 折叠在前,不变
翻译叠加? rubash 翻完后 winuxcmd 收到 C:\... 原生形,native 各臂不触发、原样放行 同左——两层无双译冲突
红线/豁免 PR#600 豁免表零新增 本 PR 豁免表零新增、零修改

结论:与 /X/ 盘符形的既有双层格局(#1145 工具侧 + #592 引擎侧)完全同构;rubash 侧 #444 carve-out 维持现状,撤除预翻译仍按票面"先 probe 后迁移"另议。

设计决策((a)-(e),票上已记录:#1172#issuecomment-6249391156)

修法(一个点,全工具受益)

验证

  • 新增 3 测试全绿:ctest -R ls_mnt → 100% tests passed, 0 tests failed out of 3。
  • 全量 ctest:改动前基线(origin/main = b4f7834,独立运行)99% tests passed, 3 tests failed out of 2975;本 PR 后 99% tests passed, 2 tests failed out of 2978(2975 + 本 PR 3 个新测试)。基线 3 个失败逐一溯源均与本 PR 无关且非代码回归:
    • mktemp.mktemp_p_cygdrive_dir_outputs_cygdrive_form:本开发 shell 继承 Niubash 注入的 __RUBASH_SHELL_ROOT 所致的会话污染;env -u __RUBASH_SHELL_ROOT -u NIU_ROOT -u WINUXSH_ROOT -u RUBASH_ROOT 下单独复跑即绿(同一注入也正是 [noise-panic] # seq -f %a aborts (out-of-memory) on a large-magnitude exponent that GNU formats fine (uutils#13222) #568 复测假象的来源)。
    • winuxcmd.locale_hint_* × 2:本机已安装 zh-CN catalog(Niubash 安装树),"catalog missing → 建议 wpm install" 的前提不成立,机器状态类预存失败,clean 基线上同样失败。
    • 本 PR 全量复跑(同环境、同四个变量已清):失败集 = 基线减去 mktemp(其随变量清空转绿),仅剩 2 个 locale_hint——零新增、零消失。
  • 端到端直打(PowerShell 原生 argv,standalone):ls/du/sed/touch 过 /mnt/c 全通(矩阵见上);边界 /mnt、/mnt/data 仍 verbatim。
  • clang-format:仓库惯例(Google 80 列);diff 严格限定 3 个文件(native_path.cppm / ls_unit_test.cpp / CHANGELOG.md),无无关重排。

红线自查

  • 只按票面与 (a)-(e) 边界实现;cygpath -u/-w 转换器有自己的契约(mktemp/cygpath 认裸前缀文本),不动,翻译面未扩大。
  • rubash#592 豁免表逐项对照:两仓对 /mnt/X 形状规则一致,无新增豁免、无新增漂移。

closes #1172

…1172)

normalize_api_operand_w folds /mnt/X to the MSYS /X spelling before the
drive branch, so a single drive-letter arm keeps owning every POSIX drive
form (#1145 structure). WSL mounts the Windows drives under /mnt and that
spelling reached argv verbatim whenever a tool was invoked directly -
PowerShell, cmd, a scheduler, an agent - or built its own child argv
(xargs / find -exec chains, the rubash PR#600 tool-side lane); rubash's
argv funnel already pre-translates the form for every child (#444, #592),
so the two layers now agree on the same shape without double-translation
(rubash hands the applet C:\... and the native arms stay inert).

Shape matches rubash's windows_mnt_drive_argument byte-for-byte so the
two repos never drift: a lowercase mnt literal (unlike the case-insensitive
cygdrive name - deliberate, two-repo parity over local symmetry), a drive
letter of either case folded to uppercase, exactly /mnt/X or /mnt/X/...

Boundaries (ticket (a)-(e)):
- /mnt and /mnt/ (the WSL root) never fold: verbatim standalone, and the
  niubash#346 shell-tree mount semantics (<root>/mnt) under a shell root.
- Non-drive children (/mnt/data, /mnt/cfoo, /mnt/123) stay verbatim.
- /mnt/cygdrive/d cannot fold twice (load-bearing negative test).
- Zero new or modified verbatim exemptions: /cygdrive/*, /dev/*, bare /,
  /X... switches, relative words all untouched.

Every tool on the shared operand boundary (ls, du, sed, cp, ...) picks
the form up at once via make_api_path_operand_w (#1178 routed du/sed);
canonicalize (realpath/readlink) deliberately stays out - its GNU
semantics do not fold /d/x either.

Tests (ls_unit_test.cpp, the #1145 style; standalone cases clear all
four shell-root variables, drive letters derived from TempDir):
- ls_mnt_drive_dialect_resolves: lower/upper drive x file/-d/bare root,
  operand echoed as typed.
- ls_mnt_non_drive_forms_stay_verbatim: /mnt, /mnt/, /mnt/data,
  /mnt/cfoo, /mnt/123, /mnt/cygdrive/<drive>/<existing> double-fold
  guard; rc=2 with the operand echoed verbatim.
- ls_mnt_forms_keep_shell_root_semantics: /mnt/c still resolves with a
  shell root configured (fold result = the old shell-ns arm result) and
  ls -1 /mnt still lists <root>/mnt (no #346 regression).

Full ctest: baseline origin/main (b4f7834) 2975 cases / post-change 2978
cases (3 new); failure sets identical modulo the machine-state locale_hint
pair (installed zh-CN catalog on this machine) and the mktemp cygdrive
case that only fails under an inherited __RUBASH_SHELL_ROOT - the same
Niubash injection that produced the rubash#568 probe artifact.
@caomengxuan666

Copy link
Copy Markdown
Member Author

独立评审(PR #1227 / #1172 /mnt 折叠臂)

结论:REQUEST-CHANGES — 1 个可证实的边界实现缺陷(一行修复),其余设计决策、双层无冲突、测试与改动面全部实证通过。

F1(需修改):折叠臂漏掉 [4] 分隔符检查,/mnt+字母+字母 词被误折成盘符

src/utils/native_path.cppm:387-403。条件校验了 [0] 分隔符、[1..3]=="mnt"、[5] 盘符、(size==6 或 [6] 分隔符),但从未要求 is_separator(normalized[4])。

实测(本机构建物,cmd 内清空四个 shell-root 变量后直打):

操作数 rc 实际效果
ls /mntcc 0 列出 C:\ 根(= ls /c)
ls /mntcd 0 列出 D:\ 根(= ls /d,输出逐行一致)
ls /mntcc/Windows 0 列出 C:\Windows
ls /mntab/c 2 词法上已折成 B:\c(本机无 B: 才表现为 ENOENT)
  • 违反本 PR 自述契约:注释(native_path.cppm:379-384)与 CHANGELOG:18-20 都承诺"exactly /mnt/X or /mnt/X/..."、与 rubash windows_mnt_drive_argument "byte-for-byte"。rubash 侧(src/executor/path.rs:1857-1863)用 starts_with("/mnt/") 要求字节 4 是 /,本臂没有 —— 逐字一致的主张对这一类输入不成立,两层真实漂移。
  • 与紧邻其上的 cygdrive 臂不对称:后者显式有 is_separator(normalized[1 + k_cygdrive_name.size()])(:366 附近)。设计记录 (c) 自己写的"[5] 为字母且 [6] 为分隔符或串尾"也隐含 [4] 已是 /。
  • 修复(一行,与 cygdrive 臂对齐):条件中加 is_separator(normalized[k_mnt_name.size() + 1]) &&。is_separator 接受 \\,故既有 backslash 形(\mnt\c)不受影响(已实测 \mnt\c 路径当前可折,修复后同样可折)。
  • 建议补承重负例(现有负例全是 [4]=='/' 形,抓不到这一类,已变异验证):在 ls_mnt_non_drive_forms_stay_verbatim 的 forms 表加机器无关的 L"/mnt" + drive + drive + text.substr(2)(如 /mntcc/Users/... 指向 TempDir 本身):修复前 rc=0(折到真实盘路径),修复后 rc=2 verbatim。

F2(nit,随 F1 一并改):"byte-for-byte" 表述在修复前为假

CHANGELOG.md:19 与 native_path.cppm:380。F1 修复后该表述成立,保留即可;仅提醒不要只改代码忘改文案(当前两处都在)。

已实证通过的部分(均亲手复现,非转述)

  1. 设计决策核实:用 cmd 清变量 + 本机 Niubash 安装的原 1.1.14(修复前)二进制复现完整矩阵——ls /mnt/c/Windows 清四变量 rc=2(缺口);注入 __RUBASH_SHELL_ROOT rc=0([candidate] vdir: bug(vdir): when using -R with a large nested file it leads to a no human readable err (uutils#12827) #346 门控臂);niu -c 顶层 rc=0(引擎翻完传 C:\...,安装树 ls 是修复前版本,能通只能是引擎侧翻译)。[noise-panic] # seq -f %a aborts (out-of-memory) on a large-magnitude exponent that GNU formats fine (uutils#13222) #568"直打已通"的假象归因(env 注入→shell-ns 臂)成立。
  2. 双层无冲突:ls.exe 'C:\Windows'(已是 Win32 形)原样放行、缺路径报错回显原操作数——native 各臂均需 [0] 为分隔符,不触发。find/xargs 端到端:echo /mnt/c/Windows | xargs ls -d rc=0;find /mnt/cygdrive/cc/Windows -maxdepth 0 rc=1(verbatim)。
  3. 边界 (a)-(e)(F1 之外全部成立):(a) /MNT、/Mnt verbatim(小写字面量契约与 rubash starts_with 一致;GNU/cygwin 对 /mnt 无既定行为,对齐 rubash 是自洽选择);(b) /mnt、/mnt/ standalone verbatim,配 shell root 时 <root>/mnt 挂载语义保持(手测 marker.txt 用例通过);(c) /mnt/data|cfoo|123 verbatim;(d) /mnt/cygdrive/d 无双折;(e) 豁免表零新增、零修改(diff 仅一个折叠臂)。
  4. 变异测试(改源→重建→跑 3 个新测试,用后已还原):删臂 → ls.ls_mnt_drive_dialect_resolves 转红(正例锁臂);仅换序 → 全绿(前缀互斥,换序行为中性,与设计记录一致);仅放宽 [6] 条件 → 本机 ctest 仍绿但手动探测 /mnt/data 已被折到 D:\data(存在性撞运气);放宽+换序 → ls.ls_mnt_non_drive_forms_stay_verbatim 转红(双折护栏确为承重负例,与测试注释一致)。shell-root 用例(1416)在删臂下仍绿——它护的是 [candidate] vdir: bug(vdir): when using -R with a large nested file it leads to a no human readable err (uutils#12827) #346 不回归,不是新臂,合理。
  5. 全量 ctest:2978 项(= 2975 基线 + 3),2976 过,失败恰为 2 个预存 locale_hint(winuxcmd_unit_test.cpp:681/682/699,i18n 目录环境态,与本 PR 改动面无关)。
  6. 改动面:严格 3 文件(CHANGELOG/native_path.cppm/ls_unit_test.cpp),纯新增 192 行;新增行零超 80 列、零尾随空白(本机无 clang-format 可执行文件,按 .clang-format ColumnLimit=80 及风格逐行核对,格式与相邻 cygdrive 臂一致);L"/mnt/" 拼接全部走 operator+(const wchar_t*, std::wstring),无指针算术残留;CHANGELOG [Unreleased]/### Added/- **native path**: 与仓库既有惯例一致。
  7. 许可证:实现为原创小匹配器(与仓内 Per-command gaps resolving verbatim POSIX argv: cp/mv/ls(file,-d) fail on /d/... drive paths while cat/mktemp/ls(dir) resolve them (blocks niubash#124 Option B) #1145 cygdrive 臂同构同风格),无 WSL/cygwin 代码搬运标识(无 lxss/wslpath/cygwin_conv 等符号),LICENSE 不变;canonicalize(realpath/readlink)走 canonicalize_path_w,有意不在面内,现状对称。

建议

修 F1(一行条件 + 一个负例 + CHANGELOG/注释核对口径)后即可合入。其余全部放行。

…1172)

CR finding on #1227: the fold arm checked the mnt name, the drive letter
and the tail boundary but not the separator between "mnt" and the
letter, so /mntcc lexically folded to /c and named C:\ - "ls /mntcc"
listed the drive root and /mntab/c folded to B:\c. rubash's
windows_mnt_drive_argument gets this constraint from
starts_with("/mnt/") and the sibling cygdrive arm from its
is_separator check; the arm now requires
is_separator(normalized[k_mnt_name.size() + 1]) and the byte-for-byte
claim against rubash's matcher is true again (the comment now spells out
the separator and the /mntcc trap; the CHANGELOG shape sentence was
already "exactly /mnt/X or /mnt/X/..." and needed no change).

Load-bearing negatives added to ls_mnt_non_drive_forms_stay_verbatim
(both land on existing paths when the check is missing, so
verbatim-missing is the only distinguishable outcome): /mnt<drive><drive>
(the CR repro - lists the drive root when broken) and
/mnt<drive><drive>/<existing tmp file> (exercises the tail-separator
arm). Verified red on the pre-fix build - exactly the 2 new forms failed
with rc=0 - and green after the one-line condition fix; ls_mnt suite
3/3; full ctest re-run 2978 cases, failure set unchanged (only the
machine-state locale_hint pair).
@caomengxuan666

Copy link
Copy Markdown
Member Author

F1 已修复(42d8841),三件套齐

① 条件修复(src/utils/native_path.cppm):折叠臂补上 is_separator(normalized[k_mnt_name.size() + 1])——[4] 必须是分隔符。与紧邻 cygdrive 臂的 is_separator(normalized[1 + k_cygdrive_name.size()]) 恢复对称,也与 rubash windows_mnt_drive_argument 的 starts_with("/mnt/") 语义对齐。

② 负例加测试(tests/unit/ls/ls_unit_test.cpp ls_mnt_non_drive_forms_stay_verbatim):按 CR 建议加机器无关负例,两种形态都加(分别锁 size == drive_pos + 1 臂与 [6] 分隔符臂):

  • /mnt<盘><盘>(CR 复现形,坏条件下折成 /c 列出盘根 → rc=0 会红)
  • /mnt<盘><盘>/<存在的 tmp 文件>(坏条件下折到真实盘路径 → rc=0 会红)

红→绿取证:先在未修构建物上加测试跑 → 恰好这 2 个新形态红(EXPECT_EQ(r.exit_code, 2) failed: lhs: [0],即 CR 的变异场景);一行条件修复后 ls_mnt 套件 3/3 绿。

直打复核(PowerShell 原生 argv,standalone):

  • ls -d /mntcc → cannot access '/mntcc' rc=2(修复前 rc=0 列 C:\ 根)
  • ls -d /mntcd → rc=2(修复前 rc=0 列 D:\)
  • 正例无回归:ls /mnt/c/... rc=0、ls -d /mnt/c rc=0、边界 /mnt/data 仍 verbatim rc=2

③ 文案核对:

  • native_path.cppm 注释:保留 "byte-for-byte" 句式并写明已修差异——现明确列出 "the literal separator after it",且补注 trap("without the separator check /mntcc would lexically fold to /c and name C:")。
  • CHANGELOG.md:形状句本来就是 "exactly /mnt/X or /mnt/X/..."(修复后该句为真),未改动。
  • 上一提交信息里的 byte-for-byte 自述已由本提交信息更正说明。

回归面:全量 ctest 2978 例复跑,失败集与修复前完全一致(仅 2 个机器状态 locale_hint——本机已装 zh-CN catalog),零新增零消失。clang-format:native_path.cppm 的 4 处 dry-run 报点全为预存上游行(clang-format-22 与已提交风格的历史分歧,不属本 PR 触碰面);测试文件除我的新数组重排外零变化。

请 CR 复核。

@caomengxuan666

Copy link
Copy Markdown
Member Author

复核轮:APPROVE(42d8841)

F1 三件套全部独立复核通过,无新增 finding。逐条取证:

① 条件修复:native_path.cppm:401-402 补上 is_separator(normalized[k_mnt_name.size() + 1])(= [4],外层 size >= k_mnt_name.size() + 3 保证下标安全)。与 cygdrive 臂 is_separator(normalized[1 + k_cygdrive_name.size()]) 语义对称(均为 名字起点 1 + 名字长度;两边写法 k+1 vs 1+k 仅 cosmetic),与 rubash windows_mnt_drive_argument 的 starts_with("/mnt/") 对齐。背书形 \mnt\c\Windows 实测仍可折(is_separator 接受 \\,与 cygdrive 臂的 backslash 惯例一致)。

② 新负例(自跑 + 变异):修复构建物(清四个 shell-root 变量直打)——/mntcc rc=2、/mntcd rc=2、/mntcc/Windows rc=2、/mntab/c rc=2(全部 verbatim,修复前前两个 rc=0 列盘根);shell-root 配置下 /mntcc 仍 rc=2。变异验证(仅删新条件 → 重建 → ctest):ls.ls_mnt_non_drive_forms_stay_verbatim 转红,恰为两个新形态(两处 EXPECT_EQ(r.exit_code, 2) failed),分别锁 size == drive_pos + 1 臂与 [6] 分隔符臂——与作者的 red→绿取证(lhs: [0])一致。还原重建后 ls.ls_mnt 3/3 绿。

③ 正例回归 + 全量:/mnt/c/Windows、/mnt/C/Windows rc=0;bare /mnt、/mnt/ standalone rc=2;/mnt/data|cfoo|123 rc=2;/MNT/c rc=2;/mnt/cygdrive/c/Windows rc=2 无双折;/cygdrive/c/Windows rc=0、/dev/null rc=0 既有类不受扰;shell-root 下 /mnt 仍列 <root>/mnt(marker.txt)、/mnt/c/... rc=0。全量 ctest 2978 例,2976 过,失败集与修复前逐项一致(仅 2786/2787 两个机器状态 locale_hint,零新增零消失)。

④ 改动面:0fb4d50..42d8841 仅 2 文件(native_path.cppm +12/-5、ls_unit_test.cpp +10/-2),对基线累计仍严格 3 文件 202 行纯新增,无夹带;CHANGELOG 未动且 "exactly /mnt/X or /mnt/X/..." 修复后为真;新增行 0 超 80 列、0 尾随空白。

#1172 缺口修复完整、边界与两层契约对齐、测试承重。LGTM。

@caomengxuan666
caomengxuan666 merged commit 69dd5eb into main Oct 18, 2026
5 checks passed
@caomengxuan666
caomengxuan666 deleted the feat/1172-mnt-drive-dialect branch October 18, 2026 13:35
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.

feature: native 层解析 /mnt/X 形态(WSL 互操作路径;rubash#568 裁决实证全系无支持)

1 participant