Repository navigation
fix(executor): run leading prologues before the --help gate (bind warning, hash refusal) - #3385
Conversation
…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.
|
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 + |
… 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
|
队长复核:PASS(无作者侧前置;合入轮条件见卷宗 §11)。本轮全部验证腿走老服务器、判词只认复核自跑数字。 申报对账:文件集恰 5 个、与正文逐项相符;真实 merge-base 经 git 实算 = 自跑数字:
Owed 1(#3414)定界核对:本 PR 不触 合入走 update-branch(交集一文件,merge-tree 已证零冲突)+ 最终头双钉与全靶警告 rc=0 终验,条件全文见复核卷宗 |
Fixes #3340
What was fixed
In a non-interactive shell,
bind --helpprinted the help but lost GNU'sbind: warning: line editing not enabledstderr line, andset +h; hash --helpprinted the help instead of GNU's fatalhash: hashing disabled(status 1, no help).The leading code runs before
CASE_HELPOPTin the C sources —bind.def:122-123warns,:130-131runsinitialize_readline, both before:191;hash.def:86-90refuses 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) runsrun_pre_help_prologuefirst, 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 viawrite_buffered_builtin_output_stderr_first(#1134 rule).Bind→ extractedbind_pre_help_prologue(warning +initialize_readline, reused bybind_dispatch);Hash→ extractedcheck_hashing_enabled(sameDiagrendering, byte-for-byte with the handler); everything else →Proceed. The funnel gate and thebuiltinredispatch shareapply_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
.defleading section (required by the issue) found onlybind(non-fatal warning) andhash(fatal refusal) have observable code before the help check.getopts/times/eval/caller/fg_bg/builtinreach help viano_options(itself the help check), andtype's pre-scan only rewrites-type/-path/-allwithout touching--help. Thetrappipeline-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-41CHECK_HELPOPT / CASE_HELPOPT.What was deleted
Nothing. No files, features, or tests were removed.
Verification (all run, per-item counts)
tests/issue3340_help_gate_leading_diagnostics.rs: 10/10 pass (bind --help,bind -p --help, merged-stream warning-first,bind -lcontrol,hash --helpenabled,set +hhash --helprefusal without help,set +hhash -lcontrol,builtin bind --help,builtin bind --helpmerged-stream,set +hbuiltin 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).issue2753_builtin_helpopt_gate20/20,issue2753_p4_phase1_help_regressions11/11,help_pages12/12 (supervisor re-ran the first and third), hash family 13 files 61 items, bind family 7 files 57 items,executor_tests part_03714/14.cargo build -j 2clean,cargo fmt --checkclean.src/lexer/continuation.rsuntouched.Owed
commandface 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 --helpprints help with status 2 but no warning, andset +h; command hash --helpprints the hash help with status 2 where GNU refuses (hash: hashing disabled, status 1). [bug] command <builtin> --help 重派发面未过 help 门(GNU 出 help) #3339's gate inexecute_command_without_aliasescallsprint_builtin_helpdirectly and never runs the prologue hook this PR adds to the funnel andbuiltingates. The fix is to route the command-path gate through the same sharedapply_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 onf5f65d3without the other.