Repository navigation
fix(pwd): PWD family unconditionally POSIX /<drive>/ form — retire the native-PWD style hatch (#537) - #556
Merged
Conversation
…e native-PWD style hatch (#537) Root cause (precise): the engine has NOT rendered PWD in constant drive form since cf322dd — that commit made PWD/pwd/cd one canonical form gated by shell_path_style_enabled (POSIX /<drive>/ by default, native D:/ when a host exports WINUXSH_SHELL_PATH_STYLE / __RUBASH_PATH_STYLE). But the flagship hosts pin the gate native for the whole shell lifetime (niubash-runtime/src/shell.rs:222-225 sets NIU_SHELL_PATH_STYLE=native plus the deprecated bridge var), so every real niu/winuxsh session runs with a drive-form $PWD — and nvm.sh v0.40.8's nvm_find_up (corpus:606) terminates its ${path_%/*} walk only on "/./a found .nvmrc: 'D:' never shortens, death loop (probe 24: 60s timeout, zero output). GNU bash 5.3.0 force-fed the same PWD form hangs identically; real MSYS bash 5.2.37 (D:/Git/usr/bin/bash.exe) NEVER produces that form: $PWD/$(pwd)/post-cd are always /d/.... Design (per the #329 approved Option A policy and the msys persona --version claims): PWD form is shell semantics, not decoration — scripts consume it (nvm walk, bashdb _Dbg_is_file's leading-'/' classification). A host that wants native spelling in its prompt must render it host-side; the engine must not bend PWD. The hatch also directly contradicted #331's own locked tests (bash_variable_is_posix_ form asserts BASH has no colon — it fails under niu today) and undercut cf322dd's own bashdb goal. Changes: - shell_pwd_display_path: unconditional POSIX /<drive>/ rendering; shell_path_style_enabled deleted (no remaining readers). - init.rs shell_pwd_display: startup PWD and injected TMPDIR default always POSIX (ee6bea9's stated intent, now unconditional). - pwd builtin: logical echo drops the native branch; dead windows_slash_drive_display_to_native removed. - command-substitution fast paths ($(pwd -P), $(cd X && pwd[-P])) routed through the same canonical renderer — the raw process cwd leaked D:/ form through them even on pre-cf322dda default settings. - docs/host-contract.md: NIU_SHELL_PATH_STYLE retired engine-side (kept as a host prompt-render hint); README nvm row qualified. - tests/issue537_pwd_posix_persona.rs: probe 24 upgraded to a regression (nvm auto-load completes < 60s from a drive-letter cwd, run twice: host-style var set and unset), plus the PWD-form family contract. Host-side cleanup of niubash's set_var bridge can follow separately (the vars are inert to the engine now). Verification (Windows 10 19045 x64, 60s guards, stdin=/dev/null): - fix build, style=SET (the pre-fix hang trigger), probe 24: rc=0 in 2.6s (pre-fix 41de831: rc=124 at 60084ms); style=UNSET: rc=0 529ms (pre-fix also passes — the var, not the build date, is the trigger; the issue's 'clean env' cells carried the var). - Linux native (WSL2, same source built in WSL): 4/4 cells rc=0. - Full cargo test --no-fail-fast vs fresh master, same session env: zero new failures; 14 master-only failures fixed (issue331 family, cd/pushd/cdable-vars, comsub-cwd isolation, prompt \w, script-file drive path — all style-var dependent); the 11 branch-only names are load flakes that pass in isolation on both sides (examples family documented flaky since cf322dd). cargo fmt --check clean. Fixes #537
This was referenced Oct 12, 2026
caomengxuan666
added a commit
that referenced
this pull request
Oct 12, 2026
…forms, verbatim fidelity (#570) * tests+docs: boundary contract audit - pin the three invariants (native 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. * fix(ci): gate the boundary contract suites to the windows target 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 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.
[P0] fix #537: PWD family unconditionally POSIX
/<drive>/form — retire the native-PWD style hatchFixes #537. Blocks niubash 1.4.0.
1. cf322dd 考古(根因修正)
Issue 把根因记为"cf322dda 把 $PWD 改为恒盘符形态"——考证后需修正:
WINUXSH_SHELL_PATH_STYLE存在时shell_pwd_display_path/startup PWD 保留原生D:/拼写(宿主产品想要原生显示)。(cd dir; pwd)canonical 化、_Dbg_is_file以行首/分类绝对路径,frame 文件名D:/会掉进_Dbg_dirjoin。该提交把 PWD/pwd/cd 收敛为单一 canonical 形态,形态由shell_path_style_enabled门控——默认 POSIX/<drive>/,宿主 export 变量时保原生。它没有"改恒盘符",反而把盘符形态收进了开关。niubash-runtime/src/shell.rs:222-225在整个 shell 生命周期set_var("NIU_SHELL_PATH_STYLE","native")+ 遗留桥WINUXSH_SHELL_PATH_STYLE="native"。于是每个真实 niu/winuxsh 会话里 $PWD 恒为盘符形态(issue 的"恒"在旗舰资产上成立,机制是宿主常设变量,不是引擎无条件)。nvm.sh v0.40.8nvm_find_up(corpus:606)的${path_%/*}上溯只认""/"."/找到.nvmrc,D:永不缩短 → 死循环;probe 24 60s 零输出。bash_variable_is_posix_form断言BASH无冒号——在 niu 会话里今天就是红的;② cf322dd 自己的 bashdb 目标要求 POSIX canonical PWD,hatch 使 bashdb 在 niu 下永远达不到 byte-parity;③ GNU bash on MSYS 没有任何模式让$PWD报D:/。2. 设计权衡(判断标准:MSYS 真实行为最高参照)
Oracle 实测(
D:/Git/usr/bin/bash.exe= 真 msys bash 5.2.37 x86_64-pc-msys):$PWD/$(pwd)/cd 后恒/d/...;盘符形态路径喂给同一 find_up 循环任何 bash 都死循环(D:剥不动)——分歧只在引擎给出的 PWD 形态。/分类),不是装饰;要原生拼写应该在宿主 prompt 渲染层做。[family] Env-inherited POSIX paths re-rendered to D:/ drive form break scripts that splice $HOME/$DIR into sed s:...:...: (nvm install.sh writes 'export NVM_DIR=""', webi bootstrap dies) #329 已裁决 self-produced 值 POSIX-first,hatch 是最后一道反例。\w读$PWD),做双通道等于再造一个不变量;且只要任何路径让$PWD可为盘符形态,nvm 挂起就在那个形态下活着。改动面:
shell_pwd_display_path无条件 POSIX(path.rs)、shell_path_style_enabled删除(无残余读者)、startup PWD/自注入 TMPDIR 恒 POSIX(init.rs)、pwd 逻辑回显去原生分支(pwd.rs)、命令替换快路径$(pwd -P)/$(cd X && pwd[-P])接入同一 canonical 渲染(此前裸 current_dir 在任何设置下都漏D:/,这是本 PR 测试在验证中抓出的额外漏点)、docs 合约行退役标注、probe 24 升级为回归测试(style 变量 set/unset 双格,60s 守卫)。3. 矩阵对比(Windows 10 19045 x64,60s 守卫,stdin=/dev/null;探针=benchmarks/24-nvm-load.sh)
-u三个污染变量,留着WINUXSH_SHELL_PATH_STYLE=native——所以 8/8 格全挂;env -i全净或仅-ustyle 变量即过。挂起的唯一开关就是这个变量(与 perf(executor): hot-path residue — test marks gate, word materialization once, assignment scan admission (rubash#242) #501、三污染变量、cwd 均无关,与 issue 的排除结论一致,只是把"恒盘符"落到真机制上)。PWD=/d/repo/rubash-wt-537、cd /后/d/;旧构建同格报D:/repo/...;旧构建继承PWD=/d/foo(不存在)时按 GNU 语义重导出但仍渲染盘符形态,新构建渲染/d/...。$PWD/$(pwd)恒/d/...(复现命令:D:/Git/usr/bin/bash.exe -c 'echo $PWD')。4. 回归与套件对比
tests/issue537_pwd_posix_persona.rs(probe 24 升级):nvm.sh v0.40.8 空 NVM_DIR 规范形态 auto-load 必须在 60s 内完成,style 变量 set/unset 双格全平台跑 + PWD 形态家族契约(含看门狗:超时杀进程并点名 [P0] Windows 原生 source nvm.sh v0.40.8 自动载入挂起:PWD 盘符形态使 nvm_find_up 死循环(GNU 同 PWD 亦挂;Linux 原生不受影响;1.4.0 阻塞) #537,把静默挂起变成命名失败)。修复前二进制在 SET 格挂死。cargo test --no-fail-fast双向对比(同会话环境、同 fixture,本机 niu 会话携带 native 变量——真实宿主形态):\wdirtrim、script-file 盘符路径。$(cd x && pwd)分号格——两侧隔离均绿,属并行负载 flake,非回归。cargo fmt --check干净。5. 宿主侧 follow-up(不阻塞本 PR)
crates/niubash-runtime/src/shell.rs:222-225的两个set_var桥可删(AGENTS.md 本就要求 rubash 改读后移除);变量对引擎已惰性。D:/拼写:宿主自渲染(进程 CWD 宿主自知),或后续给引擎加显式 prompt 层接口——不回 PWD。修复后 README 生态表 nvm.sh 行的 byte-clean 声明在空 NVM_DIR 规范形态(probe 24/ perf 套件形态)下重新为真,并已限定标注。