Skip to content

fix(executor): run leading prologues before the --help gate (bind warning, hash refusal) - #3385

Merged
caomengxuan666 merged 2 commits into
unixwin:masterfrom
Uarz:fix/issue-3340
Nov 12, 2026
Merged

caomengxuan666 merged 2 commits into
unixwin:masterfrom
Uarz:fix/issue-3340

Conversation

@Uarz

@Uarz Uarz commented Nov 11, 2026

Copy link
Copy Markdown
Member

Fixes #3340

What was fixed

In a non-interactive shell, bind --help printed the help but lost GNU's bind: warning: line editing not enabled stderr line, and set +h; hash --help printed the help instead of GNU's fatal hash: hashing disabled (status 1, no help).

The leading code runs before CASE_HELPOPT in the C sources — bind.def:122-123 warns, :130-131 runs initialize_readline, both before :191; hash.def:86-90 refuses before the getopt loop — but rubash's shared help gate fired before any handler code ran, so the gate never saw the prologue.

The fix makes the prologue a hook on the gate instead of a per-builtin patch: new shared apply_builtin_help (command_dispatch.rs) runs run_pre_help_prologue first, then either aborts with the fatal diagnostic (status 1, no help) or prints the long help (status 2), with the prologue's stderr emitted before the help via write_buffered_builtin_output_stderr_first (#1134 rule). Bind → extracted bind_pre_help_prologue (warning + initialize_readline, reused by bind_dispatch); Hash → extracted check_hashing_enabled (same Diag rendering, byte-for-byte with the handler); everything else → Proceed. The funnel gate and the builtin redispatch share apply_builtin_help, so the prologue runs exactly once — the gate returns before the handler, so the handler's own prologue never double-runs.

A survey of every builtin's .def leading section (required by the issue) found only bind (non-fatal warning) and hash (fatal refusal) have observable code before the help check. getopts/times/eval/caller/fg_bg/builtin reach help via no_options (itself the help check), and type's pre-scan only rewrites -type/-path/-all without touching --help. The trap pipeline-stage gate needs no prologue (no leading code, survey-clean, left as-is).

GNU: builtins/bind.def:122-123, :130-131, :191; builtins/hash.def:86-90; 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/issue3340_help_gate_leading_diagnostics.rs: 10/10 pass (bind --help, bind -p --help, merged-stream warning-first, bind -l control, hash --help enabled, set +h hash --help refusal without help, set +h hash -l control, builtin bind --help, builtin bind --help merged-stream, set +h builtin hash --help). Fail-first on the unpatched tree (supervisor re-ran with the patch method): 3 passed / 7 failed. Post-fix 8-case GNU oracle probe is byte-identical on stdout/stderr, plus 5 extra cases (builtin redispatch, comsub, redirects).
  • Adjacent: help family issue2753_builtin_helpopt_gate 20/20, issue2753_p4_phase1_help_regressions 11/11, help_pages 12/12 (supervisor re-ran the first and third), hash family 13 files 61 items, bind family 7 files 57 items, executor_tests part_037 14/14.
  • cargo build -j 2 clean, cargo fmt --check clean. src/lexer/continuation.rs untouched.

Owed

  1. The command face still lacks both prologues after this PR and [bug] command <builtin> --help 重派发面未过 help 门(GNU 出 help) #3339 merge. Verified by the supervisor with both worktree binaries: on the [bug] command <builtin> --help 重派发面未过 help 门(GNU 出 help) #3339 tree, command bind --help prints help with status 2 but no warning, and set +h; command hash --help prints the hash help with status 2 where GNU refuses (hash: hashing disabled, status 1). [bug] command <builtin> --help 重派发面未过 help 门(GNU 出 help) #3339's gate in execute_command_without_aliases calls print_builtin_help directly and never runs the prologue hook this PR adds to the funnel and builtin gates. The fix is to route the command-path gate through the same shared apply_builtin_help; that needs a follow-up issue (or a captain decision to fold it into [bug] command <builtin> --help 重派发面未过 help 门(GNU 出 help) #3339's review), since each branch was based on f5f65d3 without the other.

…ning, hash refusal)

In a non-interactive shell, 'bind --help' printed the help but lost GNU's 'bind: warning: line editing not enabled' stderr line, and 'set +h; hash --help' printed the help instead of GNU's fatal 'hash: hashing disabled' (status 1). The leading code runs before CASE_HELPOPT in the C sources (bind.def:122-123 warning, :130-131 initialize_readline, both before :191; hash.def:86-90 refuses before the getopt loop), but rubash's shared help gate fired before any handler code ran. The fix makes the prologue a hook on the gate: new shared apply_builtin_help (command_dispatch.rs) runs run_pre_help_prologue first, then either aborts with the fatal diagnostic (status 1, no help) or prints the long help (status 2), with the prologue's stderr emitted before the help via write_buffered_builtin_output_stderr_first (unixwin#1134 rule). Bind -> bind_pre_help_prologue (warning + initialize_readline, extracted from bind_dispatch which reuses it); Hash -> check_hashing_enabled (extracted from the handler, same Diag rendering byte-for-byte); everything else -> Proceed. The funnel gate and the builtin redispatch share apply_builtin_help, so the prologue runs exactly once — the gate returns before the handler, so the handler's own prologue never double-runs. A survey of every builtin's .def leading section found only bind (non-fatal warning) and hash (fatal refusal) have observable code before the help check; getopts/times/eval/caller/fg_bg/builtin reach help via no_options (itself the help check), and type's pre-scan only rewrites -type/-path/-all.

Refs unixwin#3340

Regression pin tests/issue3340_help_gate_leading_diagnostics.rs (10 tests; fail-first 3 passed / 7 failed on the unpatched tree, 10/10 pass after; supervisor verified both rounds with the patch method). Post-fix 8-case GNU oracle probe byte-identical on stdout/stderr, plus 5 extra cases (builtin redispatch, comsub, redirects). Adjacent: issue2753 20/20, issue2753_p4 11/11, help_pages 12/12 (supervisor re-ran the first and third), hash family 13 files 61 items, bind family 7 files 57 items, executor_tests part_037 14/14. cargo fmt clean.
@caomengxuan666 caomengxuan666 added the bug Something isn't working label Nov 11, 2026
@caomengxuan666 caomengxuan666 self-assigned this Nov 11, 2026
@caomengxuan666 caomengxuan666 added gnu-baseline Tracked by the GNU Bash 5.3.0 true-baseline ledger 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 #3340 stays open until that review lands.

CI at intake: all 10 checks green (1 skipping). First pass: the prologue-as-hook design keeps the fix shared (funnel gate + builtin redispatch run it exactly once), pin 10/10 fail-first (3 passed / 7 failed on the unpatched tree), and the survey finding that only bind and hash have observable leading code is recorded. One thing flagged for the captain's decision: your Owed note (and #3381's) says the command face still lacks both 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 pushed a commit that referenced this pull request Nov 12, 2026
… gate (#3381)

Fixes #3339

## What changed

`command <builtin> --help` now goes through the shared help gate on the `command` re-dispatch face: `execute_command_without_aliases` (`src/executor/command_no_alias.rs`, +29 lines, no deletions) applies the shared `help_opt_requested` decision on the builtin table row and prints the target builtin's long help with status 2, mirroring the `builtin` face (`builtin_direct_command.rs`). SPECIAL rows mark `special_builtin_failed`, cleared by the redispatch wrapper, matching the existing `command return 16` behaviour. `command -p`, nested `command`/`builtin`, shadowed functions, redirects, command substitution and pipelines all pass through the same function, so one change covers them; there are no per-builtin special cases.

GNU anchor: `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 meets `--help` in normal dispatch 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 (captain review, box bilateral)

- Pin `tests/issue3339_command_builtin_help_gate.rs`: head 34/34. Base (true merge-base `f5f65d35` + top-up, pin sha256 identical on both sides) 24 passed / 10 failed — the 10 red names are exactly the no-scan handler faces (the cd family faces, kill, trap).
- Adjacent stems on head: help family 57 (`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); command family 22 (`issue1047_command_p_path_regressions` 4/4, `issue2514_command_v_reporting_regressions` 6/6, `issue1369_command_builtin_time_regressions` 1/1, `issue1172_command_p_regressions` 3/3, `issue1648_command_p_hash_regressions` 4/4, `case_command_head_bash_command_regressions` 4/4).
- lib: head 1245 passed / 0 failed / 4 ignored; the failure name set is empty on head and base alike.
- Hygiene: `cargo fmt --check` rc=0; whole-tree UTF-8 hygiene rc=0; marker-lint OK (117 registry consts, 268 allowlisted sites); scoped `RUSTFLAGS="-D warnings"` check (lib + bins + the pin target) rc=0 with flag loading proven in the verbose log; `cargo check --tests` rc=0. A full-target `-D warnings` enumeration (`--keep-going`) on this fork-era tree surfaces 16 pre-existing dead-field points in test files this change does not touch — the set is byte-identical on base and head, and the pin file is not among them; the operative scoped leg is green.
- The real merge-base is `f5f65d35` (the gh baseRefOid `f5d0aec7` is the filing-time tip, not the fork point); the interval intersection with master `3db080a1` is empty (0 files).
- CI on the reviewed head: 15 check-runs finished — 10 success, 5 skipped, zero red. The new pin is not in CI's named-stem list (`.github/` grep: 0 hits), so the pin evidence is the box bilateral run above.

## Known remaining face (not part of this change)

The `command`-face gate added here prints the long help directly and does not replay a builtin's pre-help prologue. Measured on this head against GNU 5.3.20 (captain probe, 18 shapes, scripts in the review dossier): `command bind --help` and its `-p`, nested and pipeline variants print the help without the `bind: warning: line editing not enabled` line, and `set +h` followed by `command hash --help` prints the hash help with status 2 where GNU refuses with status 1 and no help. The prologue hook itself is the subject of PR #3385; routing this gate through the shared `apply_builtin_help` is the follow-up, delimited in the captain review dossier for a file-or-fold decision.

Refs #3340
@caomengxuan666

Copy link
Copy Markdown
Member

队长复核:PASS(无作者侧前置;合入轮条件见卷宗 §11)。本轮全部验证腿走老服务器、判词只认复核自跑数字。

申报对账:文件集恰 5 个、与正文逐项相符;真实 merge-base 经 git 实算 = f5f65d35;与 master 区间交集恰 {src/executor/command_dispatch.rs} 一文件;与 #3384 / #3386 文件集交集均 ∅。

自跑数字:

  • 钉 issue3340:head 10/10;base(真分叉点 top-up)3 过 / 7 红——红集恰为 7 个 prologue 形、过集恰为 3 个对照形,与申报逐名一致,fail-first 成立。
  • 三方探针 19 形(GNU bash 5.3.20 oracle,脚本落盘):head 在本职面(funnel + builtin 两门)全部 17 形与 GNU 逐字节同——含合流序 bind --help 2>&1 警告在前、重定向分流字节数、comsub 首行;base 的 11 处分歧恰为 [bug] bind --help 非交互下缺失 line editing 警告(help 门先行跳过了处理器前导诊断) #3340 立案形状全集。
  • 合并形实测(master + 本 PR 的 comb 树):双钉同跑 issue3340 10/10 + issue3339 34/34,两守恒形(command hash --help、command bind -l)与 GNU 全同——与 fix(executor): route command <builtin> --help through the shared help gate #3381 不互相回退。
  • 相邻:issue2753 门 20/20、p4 11/11、help_pages 12/12、executor_tests part_037 14 过;hash 族 13 茎 65 过、bind 族 18 茎 115 过(全集口径,申报的 7 文件子集含于其中),全零红;lib 1245 过 / 0 红 / 4 ignored,失败名集与 base 恒等 ∅。
  • 卫生:fmt / marker-lint / UTF-8 边界腿 rc=0;作用域 -D warnings(lib+bins+新钉,旗标加载以 -v 点名得证)rc=0;全靶枚举 head 点集 = base 点集逐字相同 16 点,全为分叉基底既存钉文件点、零点落 src/、零点在本 PR 文件内。另注:现尖 master 全靶同口径实测 rc=0 全清,合入轮最终头按此期望验收。

Owed 1(#3414)定界核对:本 PR 不触 command_no_alias.rs(master 现行该文件仍直调 print_builtin_help),与 #3414 不重叠;comb 树上 #3414 的 9 个分歧形已逐一复现立案形状(bind 六形有 help 无警告、hash 三形印 help 状态 2),两排除形 command builtin … 在 head 与 comb 上均已与 GNU 全同、确归本单验收面。本 PR 合入后,#3414 的 fail-first 基线即为届时 master,解闸条件齐备——其修法按 #3341 规矩另行派工,不 fold 进本 PR。

合入走 update-branch(交集一文件,merge-tree 已证零冲突)+ 最终头双钉与全靶警告 rc=0 终验,条件全文见复核卷宗 ~/workspace/review-3385/CAPTAIN-VERIFY.md §11。作者不需要再动这支 PR。

@caomengxuan666
caomengxuan666 marked this pull request as ready for review November 12, 2026 03:32
@caomengxuan666
caomengxuan666 merged commit f6e8c67 into unixwin:master Nov 12, 2026
11 checks passed
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] bind --help 非交互下缺失 line editing 警告(help 门先行跳过了处理器前导诊断)

2 participants