Skip to content

fix(executor,cd): bare drive designator D:/cd D: converge on the engine dispatch - #953

Merged
caomengxuan666 merged 2 commits into
masterfrom
fix/481-483
Oct 21, 2026
Merged

caomengxuan666 merged 2 commits into
masterfrom
fix/481-483

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Summary

Fixes unixwin/niubash#481 · Refs unixwin/niubash#483

The niubash product REPL applies its four Windows normalizers
(normalize_bare_windows_drive_commands, normalize_cd_windows_drive_args,
normalize_winuxcmd_slash_drive_args, rewrite_winuxcmd_command_shims) only
on the interactive host fast path — below the batch gate's early return in
shell.rs. Every other read route reaches the executor with the raw text:

  • the grouped reader behind the batch gate (D:; pwd, cd D: && pwd,
    alias heads, keywords) — niubash#481;
  • the engine's piped -i stdin driver (run_interactive_stdin), where
    niu -i with a non-terminal stdin lands — niubash#483;
  • nested contexts the host AST pass never descends into (function bodies,
    eval, $(...), sourced files).

Bare-drive forms have no engine-side handling, so they diverged by route:
D: → D:: command not found, cd D: → cd: D:: No such file or directory
on every route except the normalized fast path.

Fix

The bare-drive semantics now live at the two engine funnels all routes share,
so the outcome is identical whether or not a host normalized first:

  • src/executor/windows_drive.rs (new) — bare_windows_drive_command_root
    ports the host pass's shape predicate verbatim (lone unquoted X: word; no
    assignments, redirects, pipe/background/!/time markers, no compound
    structure) and execute_bare_windows_drive_command rewrites the node to
    the same cd X:/ triple the host emits (words + kinds + literal metadata),
    then re-dispatches through execute_command — $_, xtrace, errexit, and
    diagnostics all follow ordinary cd semantics. Hooked at the top of
    execute_command_with_procsub_scope.
  • src/builtins/cd.rs — windows_bare_drive_operand folds a bare X:
    operand to the /x/ slash-drive root the in-shell funnel already resolves;
    D:rel drive-relative spellings stay untouched.
  • src/executor/path.rs — shell_pwd_display_path renders the bare D:
    root display as /d/ (rubash#537 persona contract). This also repairs a
    residual on the operand path: cd D:/ previously stranded D: in $PWD.

GNU has no drive designators, so there is no upstream C anchor to cite — the
contract is the Windows persona the host normalizer already defines; this
moves it to a single semantic owner instead of per-route normalization.

Convergent scope notes: D: stays command-not-found inside pipelines
(D: | cat, true | D:), quoted ("D:"), with args/assignments/redirects —
matching the host pass's exclusions. D: &, ! D:, time D: now resolve to
the drive switch inside their wrapper (the exclusion cannot survive the
engine respawn/re-entry boundary), which keeps all routes identical. The
slash-drive arg normalizer and winuxcmd shim rewrite remain host-side and are
out of scope (niubash#483 stays open).

Test plan

  • New tests/issue481_bare_drive_command_regressions.rs (4 tests):
    D:/cd D: under ; and &&, $PWD/OLDPWD persona form, function
    body + eval contexts, piped -i stdin driver, and the
    command-not-found exclusion matrix.
  • cargo test --lib — 745 passed.
  • cargo test --test path_contract_boundary_posix_forms --test path_contract_boundary_native_core --test issue566_bare_drive_root_enoent_regressions --test issue359_colon_redirect_regressions — all pass.
  • cargo test --test executor_tests — 1552 passed; the 6 failures are
    pre-existing on clean master at this worktree base (missing
    third_party submodule content + host PATH/env dependent cases),
    verified by stashing and re-running.
  • Manual probes: D:; pwd → /d/; cd D: && pwd → /d/;
    printf 'cd D:\npwd\n' | rubash -i → /d/.

Generated with Devin

…ne dispatch (unixwin/niubash#481, refs unixwin/niubash#483)

The product REPL's Windows normalizers (niubash-runtime shell.rs
normalize_bare_windows_drive_commands / normalize_cd_windows_drive_args)
run only on the interactive host fast path — below the batch gate's early
return. The grouped reader (D:; pwd / cd D: && pwd), the engine's piped
-i stdin driver, and every nested context the AST pass does not descend
into (function bodies, eval) handed the bare word to the executor, which
reported `D:: command not found` / `cd: D:: No such file or directory` —
one keystroke of intent, two outcomes per reader route.

Move the semantics to the two engine funnels every route shares:

- execute_command rewrites a bare `X:` node into the same `cd X:/` the
  host pass emits (executor/windows_drive.rs ports the host predicate
  verbatim — lone unquoted word, no assignments/redirects/pipes/
  background/!/time/compound structure — so admission cannot drift).
- cd's operand resolution folds a bare `X:` designator to the `/x/`
  drive-root spelling the in-shell path funnel already maps
  (builtins/cd.rs windows_bare_drive_operand); `D:rel` drive-relative
  forms stay filename data.
- shell_pwd_display_path renders the bare `D:` root display as `/d/`
  (rubash#537 contract) — `cd D:/` previously stranded the designator
  in $PWD.

GNU has no drive designators — no upstream anchor exists; the contract
is the product persona the host normalizer already defines, now held at
one semantic owner instead of per-route.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@caomengxuan666

Copy link
Copy Markdown
Member Author

CR(本轮不合并)

方案本身验证通过,但 CI 在 PR 自己新增的代码上红了:Rust tests → Check UTF-8 boundary hygiene 两处违规,合并会把 master 的这个门直接搞红(master 当前绿),所以先留票。

src/builtins/cd.rs:439:          return format!("/{}/", (bytes[0] as char).to_ascii_lowercase());
src/executor/windows_drive.rs:82: Some(format!("{}:/", (bytes[0] as char).to_ascii_uppercase()))

门脚本的头注释写明了流程:新 as char 位点必须先进 scripts/check-utf8-boundary-hygiene.sh 的 ALLOWLIST(评审本身就是门的意义)。顺带说明:src/executor/path.rs 里新加的 bare-root 分支没有被标记,是因为该文件已有 (as_bytes()|bytes)\[[0-9]+\] as char 条目覆盖;src/builtins/cd.rs 本体没有条目(现有条目只盖了 src/builtins/cd/paths.rs)。

两处位点实际上都是可证安全的——is_ascii_alphabetic() 先行把 bytes[0] 钉在 ASCII 字母上,不可能是 UTF-8 continuation byte,符合 ALLOWLIST 的收录标准。二选一修掉即可:

  1. 按门要求给两处加 ALLOWLIST 条目(附上面这条安全性论证);
  2. 或者改成字节侧写法绕开模式,如 (bytes[0].to_ascii_lowercase() as char) / char::from(bytes[0].to_ascii_uppercase())。

语义与测试面(本地复验,全绿,附证据)

  • cargo test --test issue481_bare_drive_command_regressions — 4/4 过(Windows 本机):D:/cd D: 在 ;/&& grouped 路由与 fast path 收敛到同一 /d/ persona;piped -i stdin driver(niubash#483 三路径)同收敛;"D:"/D: arg/V=1 D:/D: | cat/true | D: 排除矩阵保住 command-not-found 形;function body/eval 嵌套上下文覆盖。
  • 守卫套件 path_contract_boundary_posix_forms + path_contract_boundary_native_core + issue566_bare_drive_root_enoent_regressions + issue359_colon_redirect_regressions 全过(&& 链,非零即断)。
  • cargo test --lib — 745 passed / 0 failed。
  • 对 master git merge-tree 干净可并;票面互链两票(Fixes niubash#481 · Refs niubash#483)齐。
  • 引擎侧收敛路线(不动 niubash 的 batch gate 早退位置)确认:四个 host 归一化器与 gate 守卫形零接触,无回退向量。

补两行 ALLOWLIST 或改写后 push,CI 转绿即可合并,无需重跑本轮已验面。

… and windows_drive.rs

The two `bytes[0] as char` drive-letter folds added for niubash#481/#483
each sit behind a `bytes[0].is_ascii_alphabetic()` condition, pinning the
widened byte to ASCII — never a UTF-8 continuation byte. Same reviewed-safe
class as the existing path.rs/cd/paths.rs/pwd.rs entries.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@caomengxuan666

Copy link
Copy Markdown
Member Author

已按方案 1 修复 BLOCKER(8f161cdc):两处 as char 位点均有 is_ascii_alphabetic() 前置护栏,bytes[0] 被钉在 ASCII 字母上、不可能是 UTF-8 continuation byte,符合 ALLOWLIST 收录标准 —— 按门脚本头部既定的 reviewed-safe 流程给 src/builtins/cd.rs 与 src/executor/windows_drive.rs 各加一条 (as_bytes\(\)|bytes)\[[0-9]+\] as char 条目(与 path.rs / cd/paths.rs / pwd.rs 现有条目同形),并附安全性论证注释。

本地复验:

  • bash scripts/check-utf8-boundary-hygiene.sh → clean(两处位点确认被条目覆盖,收紧度不变:仅匹配 bytes[N] as char 形)。
  • cargo test --test issue481_bare_drive_command_regressions → 4/4 过,与上轮验证一致;本次仅改 .sh 门脚本,无语义面变动。

@caomengxuan666
caomengxuan666 merged commit 12fab0e into master Oct 21, 2026
6 checks passed
@caomengxuan666

Copy link
Copy Markdown
Member Author

终审:通过,合并

返工验收四项全过(head 8f161cdc):

  1. 门绿(本地等价) — bash scripts/check-utf8-boundary-hygiene.sh @ 本 head:clean,exit 0(与 CI Check UTF-8 boundary hygiene 同一调用形)。反证覆盖精确性:用 master 版门脚本跑同一棵 PR 源树,恰好只报上轮点名的两处——src/builtins/cd.rs:439 与 src/executor/windows_drive.rs:82,即两条新 ALLOWLIST 条目精确覆盖、无多盖。
  2. ALLOWLIST 依据可证 — 两条目均注明 bytes[0].is_ascii_alphabetic() 前置护栏把被加宽字节钉在 ASCII 字母上、不可能是 UTF-8 continuation byte;代码复核护栏在位(cd.rs:438、windows_drive.rs:81 的同一条件分支),符合门注释的收录标准。
  3. 语义面不回退 — issue481_bare_drive_command_regressions 4/4;四守卫套件 path_contract_boundary_posix_forms 7/7、path_contract_boundary_native_core 5/5、issue566_bare_drive_root_enoent_regressions 7/7、issue359_colon_redirect_regressions 3/3(Windows 本机实跑)。
  4. 无夹带 — 返工 commit 8f161cdc 仅动门脚本(+8 行、两条目按字母序插入);全 PR diff 面与上轮已验一致。CI 本轮实跑全绿(Rust tests 内含本门)。

Fixes unixwin/niubash#481 · Refs unixwin/niubash#483

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.

[P2][interactive] bare-drive "D:" / "cd D:" work on the host fast path but fail on the grouped-reader route

1 participant