Skip to content

fix(builtins): record as-found spelling for explicit hash NAME (Refs #3358) - #3476

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/3358-hash-builtin-relative-path
Nov 15, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/3358-hash-builtin-relative-path

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Refs #3358(#2696 的后续:run-once 记录路径已由 PR #3120 修,本单是显式 hash 内建余项)。

根因

显式 hash NAME 的裸名分支把 find_user_command 返回的 session-cwd 锚定路径直接存入 hash 表:PATH=.: 时 hash mycmd 存 <cwd>/./mycmd,于是 hash -t / hash -l / bare hash 全印锚定形。run-once 路径与 command -v / type 描述路径早已存 as-found 拼写,唯独显式 hash 分支取了锚定形。

GNU 锚点

  • builtins/hash.def:223-225:裸名分支 full_path = find_user_command (w); phash_insert (w, full_path, dot_found_in_search, 0)。
  • findcmd.c sh_makepath:walk 只造一个字符串——PATH 元素原样 + / + name;元素 . → ./mycmd。
  • 本地 GNU 5.3.20 探针确认:hash -t mycmd → ./mycmd;hash -l → builtin hash -p ./mycmd mycmd;type mycmd → mycmd is hashed (./mycmd)。

修复

src/builtins/hash.rs 裸名分支改存 recorded_resolution_spelling(name, &path, env_vars)(#2696 已有的 helper):as-written join 锚定回 program 时返回该 join,否则回落锚定显示形;绝对元素两形重合,行为不变。只动 hash.rs,未碰 path.rs(在飞 PR #3443 面)与 command_execute.rs(在飞 PR #3449 面)。

回归钉:tests/issue3358_hash_builtin_relative_path.rs(2 tests,复用 #2696 harness;seed 前 3 检查 + type + 3 个对照全量断言)。

本 PR 删除了什么

无删除:纯一行存值改动 + 新增回归钉文件;无公开面、无行为面删除。

UNVERIFIED-BY-CAPTAIN

队长复核前未验证:本轮无构建容量(本地写墙 EDQUOT、box 盘满、老服务器 ssh 未恢复、X299 直连未通),以下腿 OWED 到复核轮——RUSTFLAGS="-D warnings" cargo check --locked --lib --bins、新钉 stem issue3358_hash_builtin_relative_path(须先 --bin rubash)、全量 lib 与 base 逐数对齐。已实测:marker-lint OK、utf8-boundary clean、rustfmt --check OK、GNU 探针通过。另见工作区 REPORT.md §4:显式 hash 后的执行面(post-cd)仍走锚定路径,mirror 同步 + phash_search RELPATH consult 建议另案处理。

…3358)

GNU: builtins/hash.def:223-225 hash_builtin calls find_user_command(w)
then phash_insert(w, full_path, dot_found_in_search, 0); findcmd.c
sh_makepath builds the as-written <elem>/<name> join. The bare-name
branch stored find_user_command's session-cwd-anchored resolution
(<cwd>/./mycmd for PATH=.:...); store recorded_resolution_spelling
(#2696) instead. Regression pins:
tests/issue3358_hash_builtin_relative_path.rs.
@caomengxuan666
caomengxuan666 force-pushed the fix/3358-hash-builtin-relative-path branch from 6c927d2 to 0e80589 Compare November 13, 2026 00:15
@caomengxuan666

Copy link
Copy Markdown
Member Author

【WIN-AGENT-AUDIT】
PR #3476 第1轮 — 建议:PASS
head: 0e80589 base(merge-base): 3745712 文件: 2 个 +155/-1
关联 issue: #3358(状态:open,我核过的时间:2026-11-15 08:45 CST)

机制核查:

  • 一行存值修正:显式 hash NAME 记录 as-found 拼写 recorded_resolution_spelling(name,&path,env_vars)(复用 [A2-13] Hash table stores absolutized path; type prints it instead of the as-found relative spelling #2696 的拼写函数),不再存 anchored <cwd>/./mycmd。GNU 侧 builtins/hash.def:223-225 bare-name 循环 phash_insert(w, find_user_command(w) 结果),GNU 的 find_user_command 产出的是 as-written <PATH元素>/<name> 连接(findcmd.c sh_makepath 逐元素 verbatim)——存「拼写」而非「锚定路径」与 GNU 同源。WSL GNU 5.3.20 实测 PATH=.:... 下 hash mycmd; hash -t/-l/hash 均显示 ./mycmd。
  • diff 无无关改动;内部 lookup cache 保留 anchored 形(执行面不动,残差在 PR 正文 REPORT.md §4 已声明另案);无 trust 类机制。

腿(逐项给数字与名字):

  • 钉自跑:issue3358_hash_builtin_relative_path head @Linux(WSL):2 passed / 0 failed;head @Windows:0 tests(#![cfg(unix)],预期内)
  • fail-first:base(3745712)+钉 @Linux:1 passed / 1 failed — 红名={explicit_hash_records_relative_spelling},控制格 explicit_hash_controls_agree base 即绿;fail-first 有效且红集与 PR 声称一致
  • lib 双边 @Windows:head 失败集={issue2084}=base,差集 ∅(1349/1/4 同)
  • -D warnings:cargo check --locked --lib --bins exit 0
  • 卫生:rustfmt --check 两文件 rc=0;非 ASCII 仅注释;无 carrier 字节
  • CI:本 head 红名仅基线 issue2875
  • GNU 对照:wsl bash 5.3.20(1)-release,探针 target/review-w5/p3476.sh:PATH=.:$PATH 下 hash mycmd → -t/ -l/bare hash 三面全显示 ./mycmd,与钉逐字一致

F 点:无

未跑/VOID 的腿:

  • Windows 钉自跑 VOID(cfg unix);产品代码非 cfg-gated,Windows lib 差集 ∅ 已覆盖回归面
  • Linux 全量 lib 双边未跑(队长复核轮可选)

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.

1 participant