Repository navigation
fix(builtins,prompt): #759 builtin divergences (shift usage status, zsh-name builtins, sudo visibility) and #757 prompt expansion (bare specials, promptvars gate) - #810
Conversation
caomengxuan666
left a comment
There was a problem hiding this comment.
CR verdict: APPROVE-WITH-NITS
Independent review of b6452d3 (PR head == fix/759-757, base 9055c96). All GNU anchors below were re-verified against the vendored 5.3 tree in third_party/bash/; rubash behavior probes were rerun on this machine (Windows release build) and against WSL GNU bash 5.3.0(1)-release.
Verified (per review checklist)
-
#759 setopt/unsetopt removal — mechanism is a full teardown:
src/builtins/zsh_options.rsdeleted,pub modline gone (src/builtins/mod.rs), both dispatch arms removed (command_dispatch_primary.rs,command_no_alias.rs), theexecute_zsh_option_builtinhelper removed (option_builtins.rs), and classification tables cleaned (builtin_names.rs,command.rs/type.rsis_shell_builtin,command_text.rsenv-needs list).grep -r "zsh_options|execute_zsh_option_builtin" src/ tests/→ zero hits;enable setopt→ rc 1 "not a shell builtin";compgen -blists exactly 61 with no setopt/sudo leak (probed). Theenable -a== 61 invariant is pinned cross-platform intests/regression.rs:2527(zsh_option_builtins_are_gone) andALL_BUILTINSin src/builtins/enable.rs is exactly 61 entries.compgen -A setoptretention is correct: third_party/bash/builtins/complete.def:130{ "setopt", CA_SETOPT, 0 }is theset -ocompletion action (probed: it completesallexport/braceexpand/…, not builtin names). -
sudo hidden-builtin contract —
routes_as_builtin(src/executor/lookup_paths.rs:93-96) is the single execution-routing gate:cfg!(windows) && "sudo" && elevation_handler.is_some(). Windows-with-handler keeps the host builtin (pre-existingsudo_uses_host_elevation_handler, still green); Windows-without-handler and all unix builds take PATH, verified by code reading of the three gated dispatch arms plus thebuiltin sudofall-through towrite_builtin_not_foundrc 1 (src/executor/builtin_direct_command.rs:301-305). This IS a behavior change for Windows users without an embedding host:sudo cmdpreviously always answered "elevation handler is not configured" (rc 1); now it runs the PATH command (Win11 System32 sudo.exe where present) or 127 — intended, documented in docs/builtins.md, and strictly closer to GNU (which has no sudo builtin). Coverage gap in F4. -
shift statuses — new mapping 2/2/1/1 matches vendored shift.def + builtins/common.c:501-505 (
sh_neednumarg, return 0 → EX_USAGE) and common.c:511 (no_args→ EX_BADUSAGE). The erange boundary is preserved: negative count → 1 (src/builtins/shift.rs:66) andshift 99past$#→ 1 with the posix/shift_verbose-gated diagnostic (src/executor/shift_echo_builtins.rs:26-47). Grep found no caller depending on the old rc=1 for the two usage shapes — only the three chain tests updated (part_057/058/059), plus untouched erange suites (issue334, part_040) that still pass. Newshift_bad_operand_status_matches_gnupins all four shapes + both diagnostic wordings. -
#757 engine — the second pass is now
expand_embedded_parameters_inner(_, false, false, false, double_quoted=true): dq-escape set exactly\ $ "+ newline-join (matches the Q_DOUBLE_QUOTES contract), quotes are data, bare specials/${}/$((...))/backticks expand. Anchor audit: parse.y:6683 gate ✓, parse.y:6689expand_prompt_string(result, Q_DOUBLE_QUOTES, 0)✓, parse.y:6588\$euid!=0 backslash ✓ (rubash root branch via EUID==0 matches Windows), parse.y:6430/6434 (\D{}), 6533 (\u), 6545/6549 (\h\H), 6449/6452 (\w\W) quote gating ✓, syntax.h:26slashify_in_quotes "\\$"\n"✓ and shquote.c:328 newline exemption ✓ — rubash'sprompt_quote_for_expansionset (\$ ", newline untouched) is exactly this set. Gate priority verified against live GNU:set -o posix; shopt -u promptvars→ GNU still expands ([Axyz B]) and so does rubash (pinned in issue757 tests).\win a$-containing directory stays literal (pinned + probed)."as data ✓. Performance: 20k${PS1@P}renders of a typical PS1 in ~1s (~50µs/render) — no frame-budget concern; see F6 for the missing benchmark entry. -
Differential honesty spot-check — I reran
executor_testson both trees (base = 9055c96 worktree, branch): base 1543 passed/9 failed vs branch 1544 passed/8 failed; failure sets identical (cd/PWD, kill/jobspec,command -P, param+, unclosed-arith-subscript — all environment class), zero branch-only failures; the base-only disappearance (part_071::test_shellmath_decimal_divide_script_path) is favorable-side noise. Candidate new failure drill:regression::upstream_suite_slice_snapshotsfailed on the branch → rerun on a fresh base worktree → fails there too (pre-existing snapshot/environment class). Claim "no new failure attributable to the change" holds on my sample. Test quality: 3+6+3 new tests each cite GNU probes; issue757 suite is the strongest (gate round-trip, posix override, both channels,\wprotection). -
Red lines — no GPL text and zero verbatim-C lines in the diff (the only parse.y-adjacent content is prose comments with file:line anchors, all verified against the vendored tree, none mirrored);
cargo fmt --checkclean; the two fmt-only hunks (src/executor/arrays/mapfile.rs, tests/executor_command_chaining/part_041.rs) are pure rustfmt reflows, no semantic drift; no merge conflicts with current master (base is 10 commits behind,git merge-treeconflict count 0). Temporary review worktree removed; nothing merged.
Findings (nits — none blocking)
-
F1 (minor, new failure mode): prompt-pass expansion errors are not contained.
PS1='a${1x}b'; p=${PS1@P}; …now printsbad substitutionand aborts the rest of the command list (rc 1, subsequent commands never run) — probed:bash: line 1: a${1x}b: bad substitution, exit 1. GNU 5.3.0 prints the diagnostic but returns the literala${1x}bwith rc 0 and continues (probed on WSL). Pre-PR base was a silent[ab]. The new engine turns malformed prompt content into a command-level fatal expansion error; GNU contains it inside the prompt pass. Unterminated${bis swallowed ([a]) on both master and this branch while GNU returns the literal — pre-existing, but the same containment fix would cover both. Suggest: catch the diagnostic inside the prompt pass, emit it, and return the decoded text (parse.y behavior), plus a regression probe.src/executor/embedded_parameters.rs:489-492(the${}arm'sexpand_wordcall) is where the error currently propagates from. -
F2 (docs accuracy): the
${var?word}boundary is mischaracterized. Commit + PR body say the shape "keeps printing the message text"; observed rubash behavior silently substitutes the message text into the value (pre${MYVAR?msg}post→premsgpost, no stderr) while GNU printsMYVAR: msgand returns the literal. Pre-existing on master (probed base binary), but the declaration doesn't match observable behavior and nothing pins it. -
F3 (pre-existing, adjacent to touched code):
${PS1@P}leaks command-substitution status into$?.PS1='x$(false)y'; p=${PS1@P}; echo $?→ 1 (GNU 0 — parse.y:6684-6696 restoreslast_command_exit_valuearound the pass). Base behaves identically (pre-existing), but this PR rewires exactly this path (parameter_transforms.rs:416-430) and already snapshots/restores status inexpand_prompt_string_mutfor #604; the transform channel is the remaining hole. -
F4 (coverage): the no-handler execution route is unpinned.
sudo_is_not_reported_as_a_builtinasserts only the introspection invariant; nothing exercises (a)sudo cmdwith no handler actually executing a PATH command (fakesudoon PATH), or (b)builtin sudowithout handler → "not a shell builtin" rc 1. Both verified by code reading only. A#[cfg(windows)]twin of the handler test withclear_elevation_handler()+ fake PATH entry would pin the two-branch contract the PR is built on. -
F5 (contract consistency):
help sudostill serves the builtin help page (src/builtins/help.rs:272-279, windows-only) while the other hidden builtins have no topic (help uname→ "no help topics match"). Pre-existing, but inconsistent with the declared "introspection surfaces report external unconditionally" contract — either disclose it as part of the hidden-builtin docs or align it. -
F6 (info): no prompt-render benchmark. The second pass now runs the full engine per render; measured ~50µs/render (20k in ~1s), so no practical concern, but
benchmarks/has no prompt entry to guard the 60fps budget against future engine growth. -
F7 (nit):
command_execute.rs:1063—is_shell_builtin_name(&expanded) || self.routes_as_builtin(&expanded)— the first disjunct is subsumed byroutes_as_builtin; harmless redundancy.
Also worth noting for the changelog: the sudo no-handler behavior change on Windows (F-disclosed above) is user-visible and docs/builtins.md covers it, but CHANGELOG.md is not in this diff.
No temporary changes remain in the repo (review worktree removed; branch cr-810 checked out at b6452d3; nothing merged).
|
CR 快速轮完成( F1(must)— 已修。定位同 CR:遍历内的裁决需要围栏 + 两处裁决点补齐。
F2 — 择"修对齐 GNU"(同上第二裁决点 + 围栏): F5 — 已修:删除 windows-only 的 GNU 差分证据(WSL 5.3.0,probe-f1/f1b/f1c,五形态全部逐字节对齐):
新回归: 验证:issue393/421/431/433/604/757 + pb10k 共 35/35 绿;lib 690 全绿;executor_tests 全量失败集与裁决基线完全一致(仅那 8 个既有环境态 flake,master 同样复现)。F3/F4/F6/F7 未动,等 followup 票。 |
…rompt_string (CR F1/F2/F5 on #810) F1 (regression from the #757 prompt pass): a malformed `${...}` inside PS1 failed the enclosing command (`PS1='a${1x}b'; p=${PS1@P}` -> rc 1, variable unset). GNU subst.c:4392-4418 expand_prompt_string runs the expansion with `no_longjmp_on_fatal_error = 1` and RETURNS THE PASSED STRING on any verdict. The pass now snapshots the expansion-verdict latches (parameter_bad_substitution, arithmetic_expansion_error, arithmetic_fatal_error, arithmetic_nonfatal_error) and, when the walk raised one, restores them and falls back to the decoded prompt text — diagnostic stands, value literal, enclosing command still rc 0. expand_prompt_string_mut (the interactive render channel) gets the same containment around its double-quoted walk. Two verdict sites were needed inside the double-quoted walk, both gated on it so ordinary word paths are untouched: - an unterminated `${body` (GNU 5.3.0: `PS1='a${bad'` prints `a${bad: bad substitution`, value literal) — the body collector now reports termination (collect_braced_parameter_body); - the `?`/`:?` error operator REPORTS (subst.c:10403-10418: `{prefix} {name}: {message}`, message expanded) instead of substituting the message into the value. F2 resolved by the same change: `${var?word}` inside the prompt pass is now GNU-aligned (stderr diagnostic + literal value + rc 0) — probed against WSL GNU 5.3.0 on all five shapes (bad substitution, arithmetic verdict, unterminated brace, `?` operator, nonfatal division). F5: `help sudo` drops the windows-only hand-written help page and takes the GNU no-topics form (`help: no help topics match 'sudo'`), matching the new contract that introspection never presents sudo as a builtin. New differential regressions: tests/regression.rs prompt_expansion_failure_contained_like_gnu (rc + literal + stderr across the five shapes) and the in-process malformed_braced_parameter_contained_in_prompt_transform. Prompt boundary suites (issue393/421/431/433/604/757, pb10k) 35/35 green; lib 690 green; executor_tests failure set unchanged (the 8 adjudicated pre-existing environment flakes).
…sh-name builtins, sudo visibility) and #757 prompt expansion (bare specials, promptvars gate) #759 item 3 - `shift` with a bad operand is a usage error (2), not a plain failure. GNU builtins/shift.def routes a non-numeric operand through get_numeric_arg (builtins/common.c:501-505 sh_neednumarg, get_numeric_arg returns 0, shift_builtin answers `return (EX_USAGE)`) and a surplus operand through no_args (set_exit_status(EX_BADUSAGE)); only the shift-count-erange path stays EXECUTION_FAILURE. rubash returned 1 for both usage shapes; GNU 5.3.0 gives 2/2/1/1 for x / 1 2 / -1 / 99 and rubash now agrees (the 5.2.21-vs-5.3.0 question left open on the ticket thread is resolved for the 5.3.0 contract). #759 item 4 - GNU bash has no `setopt`/`unsetopt` builtins; a script probing them to detect zsh must miss. Removed the zsh-compat builtins (src/builtins/zsh_options.rs and every dispatch/classification arm): `setopt x` is command-not-found (127), `builtin setopt x` is not-a-shell-builtin (1), `enable -a` lists exactly GNU's 61 names, and shell option state is untouched by the unknown names. `compgen -A setopt` is deliberately UNTOUCHED - complete.def:130 defines it as a `set -o` completion action, not the zsh builtin. `sudo` moves to the hidden-builtin contract (docs/builtins.md, the uname/arch pattern): execution keeps the Windows host-capability builtin only while an embedding host registered an elevation handler; with no handler it routes and introspects as the PATH command GNU runs (`command -v sudo` finds /usr/bin/sudo, never a bare builtin name). Introspection surfaces (type, command -v, enable -a, compgen -b) report external unconditionally. #757 - the prompt second pass now runs the full double-quoted word expansion (parse.y:6689 expand_prompt_string with Q_DOUBLE_QUOTES) instead of a bare-name scanner: bare special parameters ($? $# $$ $- positional $1/$2), $((...)) arithmetic and backticks all expand in ${PS1@P} and the render channels. The pass is gated on `promptvars || posixly_correct` (parse.y:6683), so `shopt -u promptvars` leaves `$var`/backtick text literal while posix mode keeps expanding. decode_prompt_string gains the parse.y:6586-6592 `\$` contract (backslash-quoted for the pass when non-root, bare `#`/`$` otherwise) and the parse.y:6434/6452/6533/6549/6563 backslash-quote protection for the \w \u \h \H \W \D{} decode outputs (the slashify_in_quotes set, syntax.h:26), so their data cannot be misread as expansion syntax by the pass. #431 (\[ \] stripping) and #604 (status snapshot, render-path parity) behavior unchanged - their regression suites stay green. Known boundaries left as-is (pre-existing, out of ticket scope): PS4 does not decode PS1-style escapes, the `${var?word}` prompt-pass shape keeps printing the message text, and ticket section 3 (PS0 emission, \! / HISTCMD counters, compgen -A signal inventory). Differential evidence: WSL GNU bash 5.3.0 stdin probes 2026-10-18 (LF scripts, stdout/stderr split). New regression coverage: tests/regression.rs shift_bad_operand_status_matches_gnu / zsh_option_builtins_are_gone / sudo_is_not_reported_as_a_builtin and tests/issue757_prompt_expansion_regressions.rs (6 cases); the three shift chain tests move to the 5.3.0 status contract. Full `cargo test --release -- --test-threads=1` failure set compared bidirectionally against an origin/master worktree run on the same machine: 44 pre-existing environment failures on master, 34 on this branch, no new failure attributable to the change. Two files (arrays/mapfile.rs, executor_command_chaining/part_041.rs) carry fmt-only hunks the pre-commit rustfmt gate demands on any commit.
…rompt_string (CR F1/F2/F5 on #810) F1 (regression from the #757 prompt pass): a malformed `${...}` inside PS1 failed the enclosing command (`PS1='a${1x}b'; p=${PS1@P}` -> rc 1, variable unset). GNU subst.c:4392-4418 expand_prompt_string runs the expansion with `no_longjmp_on_fatal_error = 1` and RETURNS THE PASSED STRING on any verdict. The pass now snapshots the expansion-verdict latches (parameter_bad_substitution, arithmetic_expansion_error, arithmetic_fatal_error, arithmetic_nonfatal_error) and, when the walk raised one, restores them and falls back to the decoded prompt text — diagnostic stands, value literal, enclosing command still rc 0. expand_prompt_string_mut (the interactive render channel) gets the same containment around its double-quoted walk. Two verdict sites were needed inside the double-quoted walk, both gated on it so ordinary word paths are untouched: - an unterminated `${body` (GNU 5.3.0: `PS1='a${bad'` prints `a${bad: bad substitution`, value literal) — the body collector now reports termination (collect_braced_parameter_body); - the `?`/`:?` error operator REPORTS (subst.c:10403-10418: `{prefix} {name}: {message}`, message expanded) instead of substituting the message into the value. F2 resolved by the same change: `${var?word}` inside the prompt pass is now GNU-aligned (stderr diagnostic + literal value + rc 0) — probed against WSL GNU 5.3.0 on all five shapes (bad substitution, arithmetic verdict, unterminated brace, `?` operator, nonfatal division). F5: `help sudo` drops the windows-only hand-written help page and takes the GNU no-topics form (`help: no help topics match 'sudo'`), matching the new contract that introspection never presents sudo as a builtin. New differential regressions: tests/regression.rs prompt_expansion_failure_contained_like_gnu (rc + literal + stderr across the five shapes) and the in-process malformed_braced_parameter_contained_in_prompt_transform. Prompt boundary suites (issue393/421/431/433/604/757, pb10k) 35/35 green; lib 690 green; executor_tests failure set unchanged (the 8 adjudicated pre-existing environment flakes).
…cross-target E0609) routes_as_builtin referenced the #[cfg(windows)] elevation_handler field unconditionally, so every unix compile lane (linux/darwin/android cross check, unix Rust tests, shell functionality build) failed with E0609 at lookup_paths.rs:95. The field and its whole machinery are windows-only by the established pattern (executor/mod.rs:1039-1040, init.rs:424, command_substitution.rs:1573, sudo_builtin module gate), so the routing helper gets the same two-variant shape: on Windows the table plus the handler-gated sudo arm; elsewhere the pure table - which is also the GNU-correct answer, since off Windows there is no sudo builtin at all. The issue757 backslash-dollar decode regression test asserted the root render (hash); unix CI runs non-root, so it now derives the expectation from EUID and asserts the literal-name contract on either branch (root hash / non-root backslash-quoted dollar).
…item 3) The upstream-suite errors slice pinned the pre-#759 `shift` usage status: `after shift: 1` twice, recorded while rubash answered EX_USAGE-shaped failures with EXECUTION_FAILURE. The 5.3.0 contract this branch ships (builtins/common.c:501-505 get_numeric_arg -> shift.def `return (EX_USAGE)`, surplus operands through no_args EX_BADUSAGE) is 2, byte-verified against WSL GNU bash 5.3.0. Re-recorded per the documented protocol (RUBASH_REGRESSION_RECORD=1 cargo test --test regression upstream_suite_slice_snapshots); the diff is exactly the two shift lines, no other slice moved.
c4ea987 to
5892b6f
Compare
|
CI 两类已清(rebase + E0609 全量修), ① E0609(must)— 一次清完。CI 四 lane 日志的错误点只有一处(
修法按既有 windows-only 模式( 顺带:issue757 的 ② goldens — 已愈。rebase 到 本机 Windows:lib 690、issue757 7/7、executor_tests shift/setopt 切片 15/15 全绿。CI 判。 |
Closes #759 (items 2-4; item 1
unset+function already gone on master, item 2dirs -lfixed in 5da6421)Closes #757 (facets 1-2; section 3 items stay open)
What changed
#759 item 3 -
shiftbad-operand statusGNU builtins/shift.def routes a non-numeric operand through get_numeric_arg (builtins/common.c:501-505,
sh_neednumarg+ return 0 ->return (EX_USAGE)= 2) and a surplus operand throughno_args(set_exit_status(EX_BADUSAGE)= 2); only the shift-count-erange path returns EXECUTION_FAILURE (1). rubash returned 1 for both usage shapes. The 5.2.21-vs-5.3.0 question left open on the ticket thread is resolved for the 5.3.0 contract (verified on WSL GNU bash 5.3.0).#759 item 4 - the three non-bash builtins
setopt/unsetoptremoved entirely (module, dispatch, classification, completion action table entries):setopt x-> 127 command-not-found,builtin setopt x-> 1 not-a-shell-builtin,enable -alists exactly GNU's 61 names, option state untouched.compgen -A setoptdeliberately untouched - complete.def:130 defines it as aset -ocompletion action, not the zsh builtin.sudomoves to the hidden-builtin contract (the repo's documented uname/arch pattern): execution keeps the Windows host-capability builtin only while an embedding host registered an elevation handler; with no handler it routes and introspects as the PATH command GNU runs. Introspection (type,command -v,enable -a,compgen -b) reports external unconditionally.#757 - prompt expansion second pass
The pass now runs the full double-quoted word expansion (parse.y:6689
expand_prompt_string(result, Q_DOUBLE_QUOTES, 0)) instead of a bare-name scanner: bare special parameters ($?$#$$$-positionals),$((...)), backticks and${...}operators all expand in${PS1@P}and the render channels. Gated onpromptvars || posixly_correct(parse.y:6683):shopt -u promptvarsleaves$var/backtick text literal; posix mode keeps expanding.decode_prompt_stringgains the parse.y:6586-6592\$contract and the sh_backslash_quote_for_double_quotes protection (syntax.h:26 slashify_in_quotes set) for the\\w \\u \\h \\H \\W \\D{}decode outputs, so their data survives the pass literally.#431 (
\\[ \\]stripping) and #604 (status snapshot, render-path parity) behavior unchanged - issue431/issue604/pb10k/issue393/issue421/issue433 suites all green.GNU differential evidence (WSL GNU bash 5.3.0, stdin method, 2026-10-18)
( set -- 1 2; shift x )rc( set -- 1 2; shift 1 2 )rc( set -- 1 2; shift -1 )rcshift 99(3 positionals) rccommand -v setoptsetopt, rc 0command -v unsetoptunsetopt, rc 0command -v sudo/usr/bin/sudo(external)sudo(builtin)enable -a | wc -lbuiltin setopt x/builtin unsetopt xrcfalse; PS1='x\$?y'->\${PS1@P}[x0y][x\$?y][x0y]shopt -u promptvars;PS1='A\$MYVAR B'[A\$MYVAR B][Axyz B][A\$MYVAR B][Pxyz S](expanded)PS1='c\echo bt`d'`[cbtd][cbtd]set -- one two;PS1='n\$1 a\$2'[none atwo z][none atwo z]PS1='m\$((3+4))n'[m7n]3+4as command[m7n]PS1='q\"quote\$dollar'(unset)[q\"quote][q\"quote][q\"quote]mkdir 'd\$x'; PS1='\\w'.../d\$xliteral.../d\$xliteraldirs -l(already fixed on master, 5da6421)Test coverage added
shift_bad_operand_status_matches_gnu,zsh_option_builtins_are_gone,sudo_is_not_reported_as_a_builtin\$contract, data quotes,\\wprotection)Full-suite gate
cargo test --release --no-fail-fast -- --test-threads=1failure set compared bidirectionally against an origin/master worktree run on the same machine and moment: master 44 pre-existing environment failures, this branch 34; every candidate "new" failure was re-run in isolation on both trees and either reproduced identically on master (bashdb trio needs the untrackedtarget/bashdb-clean/bashdb-generatedlauncher to run at all - with it, master fails the same way) or was the shift-status contract update fixed here. No new failure attributable to the change. Note:arrays/mapfile.rsandpart_041.rscarry fmt-only hunks - the pre-commit rustfmt gate rejects any commit while they are unformatted on master.