Skip to content

fix(executor): route command <builtin> --help through the shared help gate - #3381

Merged
caomengxuan666 merged 1 commit into
unixwin:masterfrom
Uarz:fix/issue-3339
Nov 12, 2026
Merged

caomengxuan666 merged 1 commit into
unixwin:masterfrom
Uarz:fix/issue-3339

Conversation

@Uarz

@Uarz Uarz commented Nov 11, 2026 •

Copy link
Copy Markdown
Member

Fixes #3339

What was fixed

command <builtin> --help never reached the shared help gate: command cd --help printed cd: --: invalid option + short usage (status 2, no help), and command kill --help was worse — kill: -help: invalid signal specification, status 1.

The root cause is in execute_command_without_aliases (src/executor/command_no_alias.rs): it dispatches straight to each builtin handler and never re-enters the funnel's builtin_help_gate (command_dispatch.rs:829). The fix adds +29 lines (zero deletions, no per-builtin special cases) in that one function: after the disabled/PATH/loadable fallbacks and before slot matching, it reuses the same shared decision the builtin face uses — help_opt_requested on the builtin table row, line-for-line isomorphic with builtin_direct_command.rs:115-132 — and prints the target builtin's long help with status 2. command -p, nested command/builtin, and pipeline faces all go through the same function, so one change covers them. SPECIAL rows mark special_builtin_failed, cleared by the redispatch wrapper so it does not leak into the outer command's POSIX fatal check (consistent with the existing command return 16 behavior).

GNU (builtins/command.def:68-146): command_builtin parses only its own -p/-v/-V (internal_getopt(list, "pvV"), :81; its own --help goes through CASE_HELPOPT, :88), then rebuilds the remaining words as a bare simple command and calls execute_command (:141) — the redispatched builtin goes through normal dispatch, whose internal_getopt hits --help and returns EX_USAGE (2). builtins/common.h:29-41 CHECK_HELPOPT / CASE_HELPOPT.

What was deleted

Nothing. No files, features, or tests were removed.

Verification (all run, per-item counts)

  • Regression pin tests/issue3339_command_builtin_help_gate.rs: 34/34 pass. Expectations are all from GNU 5.3.20 oracle measurements (two probe rounds, 64 cases). Coverage: help face (cd/kill/trap/wait/declare/set/eval/umask/type/shift/exec/source/exit/printf/return/break, -p, nested command/builtin, shadowed functions, redirects, comsub, pipelines, command --help self-control) + non-help face (kill -l lists signals, echo/test/:/true as operands, read -p swallows --help as a prompt, cd -- --help as a directory, -v descriptions, enable -n falls to 127, let x=1 --help still evaluates). Fail-first on the unpatched tree (supervisor re-ran with the patch method): 24 passed / 10 failed — exactly the 10 help faces were red.
  • Adjacent: help family 57 items (issue2753_builtin_helpopt_gate 20/20, issue2753_p4_phase1_help_regressions 11/11, help_pages 12/12, issue2128_flow_builtin_help_regressions 7/7, issue2955_shopt_help_regressions 3/3, issue585_invocation_aware_help_regressions 4/4 — supervisor re-ran the first and third), command family 22 items (issue1047 4/4, issue2514 6/6, issue1369 1/1, issue1172 3/3, issue1648 4/4, case_command_head_bash_command_regressions 4/4).
  • GNU differential probe (64 cases, fixed tree): matches GNU throughout, except two expected differences: diagnostic prefixes are the binary path (invocation-aware prolog), and command bind --help (see Owed).
  • cargo build -j 2 --bin rubash clean, cargo fmt --check clean. src/lexer/continuation.rs untouched.

Owed

  1. command bind --help still lacks GNU's bind: warning: line editing not enabled stderr line — and set +h; command hash --help still prints the hash help where GNU refuses (hash: hashing disabled, status 1). Verified by the supervisor with both worktree binaries after [bug] bind --help 非交互下缺失 line editing 警告(help 门先行跳过了处理器前导诊断) #3340 landed: [bug] bind --help 非交互下缺失 line editing 警告(help 门先行跳过了处理器前导诊断) #3340's prologue hook lives only on the funnel gate and the builtin redispatch gate, while this PR's gate in execute_command_without_aliases calls print_builtin_help directly and never runs the prologue. The fix is to route the command-path gate through the same shared apply_builtin_help ([bug] bind --help 非交互下缺失 line editing 警告(help 门先行跳过了处理器前导诊断) #3340); that needs a follow-up issue, since each branch was based on f5f65d3 without the other.

… gate

execute_command_without_aliases dispatched straight to each builtin handler and never re-entered the funnel's builtin_help_gate, so 'command cd --help' printed 'cd: --: invalid option' + short usage instead of the long help, and 'command kill --help' was worse ('kill: -help: invalid signal specification', status 1). The fix checks, after the disabled/PATH/loadable fallbacks and before slot matching, the same shared predicate the builtin face uses (help_opt_requested on the builtin table row, line-for-line isomorphic with builtin_direct_command.rs:115-132) and prints the target builtin's long help with status 2 (SPECIAL rows mark special_builtin_failed, cleared by the redispatch wrapper so it does not leak into the outer command's POSIX fatal check). GNU command_builtin (command.def:68-146) parses only its own -p/-v/-V, then rebuilds the remaining words as a bare simple command and runs execute_command — the redispatched builtin goes through normal dispatch, whose internal_getopt hits --help and returns EX_USAGE (2).

Refs unixwin#3339

Regression pin tests/issue3339_command_builtin_help_gate.rs (34 tests; fail-first 24 passed / 10 failed on the unpatched tree, 34/34 pass after; supervisor verified both rounds with the patch method). Adjacent: help family 57 items (issue2753 20/20, issue2753_p4 11/11, help_pages 12/12, issue2128 7/7, issue2955 3/3, issue585 4/4), command family 22 items, GNU differential probe 64 cases. cargo fmt clean.
@caomengxuan666 caomengxuan666 added bug Something isn't working gnu-baseline Tracked by the GNU Bash 5.3.0 true-baseline ledger labels Nov 11, 2026
@caomengxuan666 caomengxuan666 self-assigned this Nov 11, 2026
@caomengxuan666 caomengxuan666 added P3-low 低:优化、文档、远期规划,有机会再做 area:builtins builtin semantics (printf/declare/command/type/...) labels Nov 11, 2026
@caomengxuan666

Copy link
Copy Markdown
Member

Thanks for the PR. This is queued for captain review — collaborator PRs are reviewed by the captain before merge, and #3339 stays open until that review lands.

CI at intake: all 10 checks green (1 skipping). First pass: one function, +29 lines, no per-builtin special cases, pin 34/34 fail-first (24 passed / 10 failed on the unpatched tree, exactly the 10 help faces). One thing flagged for the captain's decision: your Owed note (and #3385's) says the command face still lacks the bind/hash prologues — whether that becomes a follow-up issue or is folded into this review is for the captain to decide. No action needed from you.

@caomengxuan666

Copy link
Copy Markdown
Member

队长复核:PASS(无作者侧前置)

复核证据(box 亲跑,flock 全程、python 启动器逐信号复位、SigIgn 亲核全零;GNU 锚点复核员亲读源码定位):

  • 申报全对账:产品 1 文件 +29/−0、总 diff 2 文件 +369/−0 逐项吻合;删除节在位且属实(零删);continuation.rs 未碰;diff 零 libc::;正文 closing 扫描唯一命中 = 意向 Fixes #3339。
  • GNU 锚点逐字亲读:builtins/command.def:81(internal_getopt (list, "pvV"))、:88 CASE_HELPOPT、:141 execute_command 重建裸命令;builtins/common.h:29-41 CHECK_HELPOPT / CASE_HELPOPT——引注全对位。修法是把同一共享决策 help_opt_requested 补到 command 直派面,与 builtin 面逐行同构、无逐内建特例,合 issue 修法方向。
  • 钉双边:head 34/34;真实分叉 f5f65d35 + top-up(钉 sha256 双边同值)24 过/10 红,红名恰为无自有 scan 的处理器面(cd 族七面 + kill + trap),与申报逐格一致。
  • 相邻茎:head 逐茎独立调用——help 族 57 全绿(20/11/12/7/3/4)、command 族 22 全绿(4/6/1/3/4 + case 4),与申报逐茎一致。
  • lib:双边 1245/0/4,失败名集 ∅=∅。
  • 卫生:fmt / 整树 UTF-8 / marker-lint 全 rc=0;作用域 -D warnings(lib+bins+钉)rc=0 且旗标加载得证(-v flagged 计数);cargo check --tests rc=0。全靶 -D warnings 以 --keep-going 枚举:16 个错误点全为测试文件 dead-field、base 与 head 集合逐字相同、钉文件不在其中——分叉基底既存测试卫生面,非本 PR 引入(其中数点已在 master 区间被修掉)。
  • 分叉/交集:真实 merge-base = f5f65d35(gh baseRefOid 的 f5d0aec7 是立案时点尖、非分叉点);区间 84 文件 ∩ 本 PR 2 文件 = ∅。
  • CI:复核头 15 个 check-runs 全 finished(10 success + 5 skipped)零红;但新钉不在 CI 点名名单(.github/ grep 零命中),钉证据以 box 双边为准。

过程注记:本轮 box 盘曾被构建群耗尽一次,head 的 lib/警告/checktests/marker 四腿首跑读数作废、已全部在修复后的干净树上重跑取得上列数字(作废与重跑的完整账在队长卷宗 §6);不影响判词的任何一条证据。

关于 Owed 1(与 #3385 的共享 prologue 缺口):已定界,队长裁 file-or-fold,你无需动作

我用四方探针(GNU 5.3.20 / base / 本头 / #3385 头,18 形,脚本与原始输出在队长卷宗)把缺口定界完毕,要点:

  • 分歧形共 9:bind 六形(command bind --help 及其 -p、操作数后、嵌套 command command、管道、合流变体)——help 已达但缺 bind: warning: line editing not enabled;hash 三形(set +h; command [-p] hash --help 及嵌套形)——本应以状态 1 拒绝却印了 help。特别注明:hash 三形在 base 上是偶然正确的(处理器直达、自有拒绝先行),分歧是本 PR 的新门抢先引入的,定界记录里已如实写明。
  • command builtin … 两形不在缺口内:它们走 builtin 面的门,fix(executor): run leading prologues before the --help gate (bind warning, hash refusal) #3385 的钩子已覆盖(实测 ✓)。
  • 修法形已明确:command 面门改调共享 apply_builtin_help 一处调用点;两支文件面不相交、任一合入次序都不冲突。立独立单还是并入某一支,由队长裁断后另行通知——这支 PR 本身判 PASS、按合入轮条件推进,不等这个裁断。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:builtins builtin semantics (printf/declare/command/type/...) bug Something isn't working gnu-baseline Tracked by the GNU Bash 5.3.0 true-baseline ledger P3-low 低:优化、文档、远期规划,有机会再做

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] command <builtin> --help 重派发面未过 help 门(GNU 出 help)

2 participants