Skip to content

fix(cd): announce the verbatim CDPATH join under -P (Refs #3395) - #3531

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/3395-cd-p-relative-cdpath-echo
Nov 15, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/3395-cd-p-relative-cdpath-echo

Conversation

@caomengxuan666

@caomengxuan666 caomengxuan666 commented Nov 14, 2026 •

Copy link
Copy Markdown
Member

Fixes #3395

修了什么

cd -P 经 CDPATH 条目命中时的回显:GNU 回显 sh_makepath(条目, 参数) 的原样拼接(相对条目即相对回显,./、.. 原样保留,绝对条目里的 ./ 也保留);rubash 把它经逻辑目的地绝对化/规范化了。$PWD 两壳本就一致,分歧仅在回显串。

  • src/builtins/cd.rs resolve_cdpath:命中路径按 sh_makepath 语义文本拼接(条目 + /(条目已以 / 结尾则不加)+ 参数原样),不再用 Path::join(Windows 上分隔符是 \)。该串同时是 chdir 目标与 -P 回显,与 GNU 的 temp 一致。
  • PrintPath::CdPath 回显:Mode::Physical 打印该拼接串原样;Mode::Logical 维持打印新逻辑 cwd(绝对、规范化)。

删了什么

附带:tests/d11_pipeline_squote_carrier_regressions.rs 在 master(#3511)以未格式化形态合入,pre-commit 的 rustfmt 检查因此失败;本 PR 对该文件跑了 rustfmt(纯格式,无语义变化)。

GNU 依据

  • builtins/cd.def:360 temp = sh_makepath (path, dirname, MP_DOTILDE);
  • builtins/cd.def:370 if (opt && (path = no_symlinks ? temp : the_current_working_directory)) printf ("%s\n", path); —— -P 打印 temp,-L 打印新 cwd。
  • lib/sh/makepath.c:66 sh_makepath():path + /(s[-1] != '/' 时)+ dir,原样拼接;空条目为 .。

验证

GNU 5.3.20(WSL /usr/local/bin/bash)脚本文件探针逐形实测,期望写入回归钉 tests/issue3395_cd_physical_relative_cdpath_echo.rs(5 个测试;符号链接一例 #[cfg(unix)]):

腿 修前 修后
Windows cargo test --test issue3395_cd_physical_relative_cdpath_echo 1/4 4/4
Linux (WSL, 同一树) 同上 1/5 5/5

同族 stem(Linux/WSL 全绿;这些多为 #[cfg(unix)]):issue2211 14/14、issue2219 9/9、issue2391 6/6、issue2796 12/12、issue3076 24/24、issue3196 6/6、issue3268 19/19、issue3335 15/15。Windows 上 issue392 6/6;issue2211 3/13、issue2219 7/9、issue2391 0/6 在 Windows 上修前修后同值(预先存在的环境失败,与本改动无关)。cargo test --lib builtins::cd 5/5。

Owed

  • CDPATH 条目以 ~ 开头时的 MP_DOTILDE 波浪号展开未探、未动。
  • 未跑全量 83 套件账本。

GNU builtins/cd.def:370 prints `no_symlinks ? temp :
the_current_working_directory`, where temp is cd.def:360's
sh_makepath(unit, dirname) join (lib/sh/makepath.c:66). Under -P the
announcement is that join verbatim, so a relative CDPATH unit echoes a
relative path and `./`/`..` components stay; rubash routed it through
the logical destination and absolutized it. The join is now built
textually (unit + `/` unless the unit ends in one + operand) instead of
Path::join, whose separator is the host's.

Also rustfmt tests/d11_pipeline_squote_carrier_regressions.rs, which
landed unformatted on master (#3511) and fails the pre-commit check.

Generated with [Devin](https://devin.ai)
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@caomengxuan666
caomengxuan666 marked this pull request as ready for review November 14, 2026 04:52
@caomengxuan666
caomengxuan666 marked this pull request as draft November 14, 2026 05:09
caomengxuan666 added a commit that referenced this pull request Nov 14, 2026
…2847) (#3556)

Fixes #2847

## 修了什么

`scripts/check-api-ledger.py` 的 §6 校验从「子树里有同名声明」改为「记录的路径就是真实导出路径」:

- `item rubash::a::b::Name`:从 `src/lib.rs` 起逐段解析,每一段必须是 `pub mod`(内联或文件,含 `#[path]`)或把模块 `pub use` 出来的再导出;末段 `Name` 必须在该模块**顶层**以 `pub` 声明(fn/struct/enum/trait/type/const/static/union/mod),或被该模块 `pub use` 再导出(具名、`as` 改名、glob;glob 目标可以是私有模块,如 `parser` 的 `pub use nodes::*`)。只认裸 `pub`,`pub(crate)` 不算对外面。
- `variant` / `method`:其所属类型路径按同一解析器校验(此前 method 完全不看类型路径)。
- 诊断区分两种失败:`declared in the tree but not exported under rubash::…`(路径错)与 `not found in tree`(符号没了)。
- 源码级近似:先抹掉注释与字符串/字符字面量,再按花括号深度判定「顶层」;不追宏生成的条目(真遇到会大声失败、需人工处理)。
- 自检(`--self-test`)新增一组:真实导出路径(具名/改名/私有模块 glob/`#[path]`/根再导出/子模块路径)必须过;未再导出、穿私有模块、类型路径错的 item/variant/method 必须各自失败。

## 删了什么

`item_exists` 原先的「模块子树 rglob + 声明模式」判定(即 issue 所说的盲区)。`PUB_DECL_PATTERNS` 只保留用于失败诊断(区分「路径错」与「不存在」)。

## 依据

工程面,无 GNU 锚。

## 验证

- issue 复现:取 #2850 之前的树(`4f0d493c~1`,`CandidateKind` 尚未在 `src/api/mod.rs` 再导出):
  - 旧脚本:`all 279 ledger symbols present`,rc=0(假绿)
  - 新脚本:5 条失败(`item rubash::api::CandidateKind` + 4 个 variant,均为 `declared in the tree but not exported under rubash::api::CandidateKind`),rc=1
- 当前 master:`all 287 ledger symbols present`,rc=0;`--niu D:/repo/niubash`:287 present、97 consumed paths recorded,rc=0。
- `--self-test` rc=0(四段自检全部通过)。
- 运行时间与旧脚本持平(约 13.5s,瓶颈仍是原有的 method 全树扫描)。
- 另带一个仅格式化提交:`tests/d11_pipeline_squote_carrier_regressions.rs`(#3511 在 master 留下的 fmt 漂移,pre-commit hook 必红;与 #3531/#3547 中的同一 hunk 相同,合并无冲突)。

## Owed

- `docs/api-ledger.md` §5 第 1 条仍写「proves presence by declaration patterns only」,现已不准确;但该文件要求与 niubash 副本逐字节相同(canary `cmp`),需 rubash/niubash 成对改,本 PR 未动。
- 未在 CI(`niu-canary.yml` 的 `ledger` / `pairing` job)上实跑,仅本地 Windows Python 3 运行。


## 队长复核(合入时)

- 判词 PASS:L1–L8 一手跑过全绿(287/287、--self-test、复现树双向对照旧假绿 279 / 新 5 缺失、--niu 97 consumed、两份账本 sha256 identical)。
- CI run 43560449915:3 fail 逐名 = issue2875 ×2(goldens、macOS)+ issue2859 Linux-only;issue2859 按 #3292 类确认为 VOID(同头 macOS/goldens 该 cell 绿、零 Rust 产品代码、不碰 jobs/sleep 面)。
- 交集 ∅(merge-base 8b48c16 = live tip),无需 update-branch。
- 合入体:接受正文 Fixes #2847,#2847 随合入自动关闭。
@caomengxuan666

Copy link
Copy Markdown
Member Author

【WIN-AGENT-AUDIT】

PR #3531 第1轮 — 建议:PASS
head: ef99826 base(merge-base): 8b48c16 文件: 3 个 +202/-21
关联 issue: #3395(状态:open,我核过的时间:2026-11-15 本地)

机制核查:

  • PrintPath::CdPath 在 Mode::Physical 下打印 target.display(resolve_cdpath 的拼接串)原样,Mode::Logical 打印新逻辑 cwd——对应 GNU builtins/cd.def:370 path = no_symlinks ? temp : the_current_working_directory。
  • resolve_cdpath 改为文本拼接 base + '/'(base 已以 / 结尾则不加)+ operand,对应 cd.def:360 temp = sh_makepath(path, dirname, MP_DOTILDE) 与 lib/sh/makepath.c:66(不再用 Path::join,Windows 分隔符问题同时消除)。
  • 可疑/无关改动:tests/d11_pipeline_squote_carrier_regressions.rs 仅 rustfmt 重排(无语义变化,正文已声明);无半成品/桥接式修法。MP_DOTILDE 的 ~ 单元展开正文自列为 Owed,未声称修复。

腿:

  • 钉自跑:issue3395_cd_physical_relative_cdpath_echo head 上 4/4(第 5 个符号链接测试 #[cfg(unix)],Windows 不编译)。
  • fail-first:base 8b48c16 上同 stem 1 passed / 3 failed,红名 = {issue3395_dot_components_stay_verbatim_under_physical, issue3395_oldpwd_after_physical_cdpath_hit, issue3395_relative_unit_announces_relative_join},logical_controls 为对照绿——与 PR 声称的修前 1/4 一致。
  • lib 双边:head 失败名集 {api::consumer_tests::issue2084_session_end_restores_host_process_state} / base 失败名集 {同}(此前 base 全量实测同名单红)/ 差集 ∅。
  • -D warnings:RUSTFLAGS="-D warnings" cargo check --all-targets 报 1 个 error:tests/issue566_bare_drive_root_enoent_regressions.rs:28 unused import Path——该文件本 PR 未改(diff 为空),属基线存量噪音,不计本 PR 账。
  • 卫生:rustfmt --check 三个改动文件全过;marker-lint OK (117 consts/268 sites);utf8-boundary clean。
  • CI:3 个红 job(GNU regression goldens、Rust tests、Rust tests macOS)逐个核过——红名单全部只有 issue2875_input_procsub_child_runs_as_rubash_shell 一个,均为已知基线,无本 PR 引入红。
  • GNU 对照:WSL /usr/local/bin/bash 5.3.20(1)-release,脚本文件探针 target/audit-w2/probe3395.lf.sh + probe3395b.sh。各形状 GNU / 本 PR 输出逐字节一致:CDPATH=. + cd -P d1 → ./d1;CDPATH=./sub → ./sub/inner;绝对条目 P/./sub → P/./sub/inner(/./ 保留);cd -L → 绝对逻辑 cwd;CDPATH=sub/(尾斜杠)→ sub/inner;空 CDPATH → 命中不公告。$PWD/OLDPWD 两侧一致。

F 点:无

未跑/VOID 的腿:

  • issue3359 等无关 stem 不在本 PR;本 PR 钉的第 5 个 unix-only 测试在 Windows 上不编译(已注明);cargo test --lib 的 base 集复用此前同 base 实跑结果,差集判断不受影响。
  • 83 套件账本未跑(正文已列为 Owed)。

@caomengxuan666
caomengxuan666 marked this pull request as ready for review November 15, 2026 02:03
@caomengxuan666
caomengxuan666 merged commit 3e80335 into master Nov 15, 2026
8 of 11 checks passed
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.

cd -P 经相对 CDPATH 条目命中的回显被绝对化(GNU 回显条目+参数原样相对路径;#1329 follow-up)

1 participant