Skip to content

test: add fail-first regression pins for empty hash -p path (Refs #3824) - #3829

Merged
caomengxuan666 merged 3 commits into
masterfrom
fix/3824-hash-empty-p-path
Nov 17, 2026
Merged

caomengxuan666 merged 3 commits into
masterfrom
fix/3824-hash-empty-p-path

Conversation

@caomengxuan666

@caomengxuan666 caomengxuan666 commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

摘要

hash -p '' ghost 之后 hash -t ghost 应印空路径、运行该条目应报 : No such file or directory(rc 127);当前 rubash 印 ./、运行报 ./: Is a directory(rc 126)。

修法已落盘:53acd684(src/executor/path.rs 1 处)。回归钉 7c16f5b4(8 cells)+ 格式修复 eeae7b85。

根因

hash -p 的插入本身正确(存 "")。分歧在读路径 phash_search_spelling(src/builtins/hash.rs:488-530):它对相对路径条目加 "./" 前缀再测 is_executable_file("./")。unix 侧 is_executable_file(src/executor/path.rs:3944)是裸 access(X_OK),目录因搜索权限而通过,于是返回 Some("./")。

GNU 的同名原语不接受目录。

GNU 锚点

  • hashcmd.c phash_search:RELPATH 条目加 "./" 后以 executable_file 判定。
  • findcmd.c:214-223 executable_file:(s & FS_EXECABLE) && ((s & FS_DIRECTORY) == 0)。
  • hash.def:163-180 add_hashed_command:-p 插入只拒目录(.//),存原值。

修法

unix 侧 is_executable_file 改为 !path.is_dir() && file_is_executable(path),与 GNU executable_file 对齐;其 src 内唯一调用点即 hash.rs:501。Windows 侧已是 is_file(),不受影响。私有 file_is_executable(裸 access)未动:它同时是 PATH 查找的执行臂,目录在 PATH 中的处理是另一未立案的执行面(见 REPORT §8),不在本单范围。

本 PR 删除了什么

无删除(新增回归钉 tests/issue3824_hash_empty_p_path.rs,8 个 cells)。

验证(车道腿,UNVERIFIED-BY-CAPTAIN)

  • Linux fail-first(新服务器,base 969230b + 钉):stem 3824 rc=101,5 pass / 3 fail——恰为 3 个缺陷 cells(空 hash -t、运行 rc127、双空 -p),5 个对照全过。
  • Linux 修绿:CI census(run 43998648571,job 133756897574,Linux 全 stem)8/8 PASS。服务器修绿腿因新服务器严重过载(load ~30、swap 满,rustc 70 分钟仅 70 秒 CPU)无法在合理时间内完成,车道已停掉该腿;Linux 修绿证据以 CI census 为准。
  • CI(head eeae7b8):除 goldens + census 外全绿(CLI、cross-target darwin/linux、Rust tests、macOS、Shell functionality、Windows compile、ledger)。goldens = 恰 2 个基线 cells(issue_753::case_9、upstream_suite_slice_snapshots)。census 80 cells,与 test: add fail-first regression pins for hash/type accepting non-executable PATH files (Refs #3825) #3830 的 87 cells 之差仅为已知的 assoc/at/$@ 不稳定族 + 2 个 churn cells;两单共有的唯一 hash/type 相邻红 cell(type_a_empty_path_element_visit_counts,[bug] type -a reports the cwd match once per empty PATH element; GNU collapses adjacent empty elements #2943)在本 PR(diff 到不了它)上同样红,属基线/抖动。
  • X299:fmt 0(5 文件)、-D warnings check 0、lib 双边 1368/1/4 两侧完全一致(唯一红 cell 为已知 Windows 基线 issue2084)、hygiene 三项全 0;钉 stems 为 unix-gated,Windows 上 0 tests。
  • GNU oracle:种子 R133-A 在 GNU bash 5.3.20 上 12/12;钉 cells 即种子断言的测试化。

GNU anchors: hashcmd.c phash_search (RELPATH arm) + findcmd.c:214-223
executable_file (FS_EXECABLE and not a directory). The stored empty
path must read back as "", and running it must fail ": No such file
or directory" (rc 127), not "./: Is a directory" (rc 126).

UNVERIFIED-BY-CAPTAIN
…efs #3824)

GNU findcmd.c:214-223 executable_file requires FS_EXECABLE and not a
directory; the unix is_executable_file was a bare access(X_OK), which
admits directories (search permission). That made phash_search_spelling
return "./" for a stored empty hash -p path: hash -t printed "./"
and running the entry failed "./: Is a directory" (rc 126) instead
of GNU's ": No such file or directory" (rc 127).

Shared fix commit for #3825 (same commit cherry-picked onto the
#3825 branch): the #3825 hash/type post-checks call this predicate.

UNVERIFIED-BY-CAPTAIN
Formatting only (server rustfmt --edition 2021); no semantic change.
@caomengxuan666

Copy link
Copy Markdown
Member Author

PR #3829 第1轮 — 建议:PASS(附一处正文表述偏差与爆炸半径说明,均不阻塞)
head: eeae7b8 base(merge-base): 969230b 文件: 2 个 +169/-1
关联 issue: #3824(状态:open,我核过的时间:2026-11-17 12:26 +0800)

机制核查:

  • GNU 锚点属实:hashcmd.c:126-160 phash_search 对 HASH_RELPATH 条目取 tail=path,无 ./ 前缀则拼 "./"+tail,以 executable_file(dotted) 判定;空存储路径 tail="" → dotted="./" → 目录 → executable_file 否 → 落到返回 path(空串)——hash -t 印空行、执行走空拼接报 : No such file or directory rc 127。findcmd.c:214-223 executable_file 的目录排除是关键:旧 is_executable_file 裸 access(X_OK) 对目录恒真(搜索权限),于是返回 Some("./")。
  • 修法为共享原语:unix is_executable_file → !path.is_dir() && file_is_executable(path)(path.rs:3944 一带),is_dir 随 stat 穿透符号链接,与 file_status 的 stat 语义一致;phash_search_spelling(hash.rs:503-530)无需改动即由否决 "./" 探针而保住空拼写。Windows 臂 is_file() 本就拒目录,cfg(unix) 钉合理。
  • diff 无顺手改动、无桥接/翻译层。
  • 爆炸半径说明(不阻塞,供队长知悉):正文称「src 内唯一调用点即 hash.rs:501」不确——is_executable_file 在本树另有调用点 src/bin/bash.rs:199/209/218/258(bash 自身路径解析)、external_inner.rs:4949/6509(ENOEXEC 壳脚本回退门)、completion_executable_qualifies(path.rs:3983,已自带 is_dir)。这些点同步获得目录排除,方向均与 GNU executable_file 一致(目录 execve 必 EACCES→126;completion 面本就排目录),无回归;但正文的「唯一调用点」表述建议更正。

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

  • 钉自跑:issue3824_hash_empty_p_path 8 passed / 0 failed(WSL Linux cargo +1.99.0,head eeae7b8;cfg(unix),Windows 0 tests)
  • fail-first:base 969230b + 原样钉文件 → 5 passed / 3 failed;红名 = {issue3824_hash_t_prints_empty_path_for_empty_p_entry, issue3824_hash_t_prints_empty_path_after_double_empty_p, issue3824_running_empty_p_entry_is_no_such_file_rc127},绿名 = {hash -l 空路径、hash 表空行、-p . 与 -p / 目录拒绝、被拒 dot 条目运行 127}——与 PR 声称「3 缺陷格 + 5 对照」完全一致
  • lib 双边(WSL cargo +1.99.0):head 失败名集 {}(1267 passed / 0 failed / 4 ignored)/ base 失败名集 {}(1267 passed / 0 failed / 4 ignored)/ 差集 ∅
  • -D warnings:RUSTFLAGS="-D warnings" cargo check --locked --lib --bins --tests → Finished,0 警告
  • 卫生:rustfmt --check(path.rs / 钉文件)rc=0;marker-lint OK(118 consts / 268 allowlisted);utf8-boundary clean
  • CI(head eeae7b8 run 43998648571):红任务 2 个——「GNU regression goldens and canaries」红格 = {issue_753::case_9_declare_indexed_operand_binds_nothing, upstream_suite_slice_snapshots} = 基线;「Regression pin stem census」红为基线红族,新钉 issue3824_hash_empty_p_path 在 census 8/8 全过。其余任务全绿。
  • GNU 对照:WSL /usr/local/bin/bash = GNU bash 5.3.20(1)-release (x86_64-pc-linux-gnu);探针脚本 D:/repo/rubash-devin-y1/target/probes/case3824.sh:hash -p '' ghost3824 → rc=0、hash -t 印空行 rc=0、hash -l → builtin hash -p ghost3824、hash 表行空命令列;运行 → : No such file or directory rc=127;双空 -p 仍空;hash -p ./hash -p / → Is a directory rc=1、不入表、运行 → command not found rc=127。rubash head 逐格一致。

F 点:无

续作记录:无(只审未改)

未跑/VOID 的腿:无

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