Repository navigation
fix(prompt,source): PROMPT_COMMAND leaves $_ at the user's last word; source scopes the DEBUG entry trap in the trap table (#797); pin the #798 sandbox truth - #807
Conversation
caomengxuan666
left a comment
There was a problem hiding this comment.
独立复核结论:REQUEST-CHANGES(2 个可修的行为回归 + 1 个引用 nit;两项主修复本体与 #798 反转均独立证实)
我用自己的 worktree(非主检)从零复核。两个主修复方向和 #798 反转都对,门禁声明属实;但 fix 2 的表驱动改写在 trap '' DEBUG(ignore)三个形态上引入了 master 本没有的 GNU 分歧,且 PR 正文的“trap -p 可见性逐字节一致”表述被其一证伪。
独立证实的部分(第一手,非转述)
fix 1($_ 括回)— 证实。
- vendored 源锚点核实:parse.y:3017
last_lastarg = save_lastarg ();、:3022-3023bind_lastarg/FREE精确命中;save_parser_state确实不带 lastarg(只有last_command_exit_value/pipestatus);PC 经 eval.c:330 走execute_variable_command。 - WSL GNU 5.3.0(与作者同版 oracle)行为探针:
echo MARKER-A→PROMPT_COMMAND="true PCWORD"→true TAILMARK→echo VAL1=$_打出VAL1=TAILMARK(pre-PC 值被括回)。 - BP_MIN transcript:WSL GNU 与
tests/issue797_...rs::preexec_install_transcript_matches_gnu的 pin 与 PR 构建(target/release/rubash)三方逐字节一致(13/13 行),含BP-EXEC:./bp_min.sh、BP-EXEC:DEBUG、BP-EXEC:ECOSRC三个反泄漏点。 - 注意:本机 MSYS bash 5.3.0(1) 在此语义上是异类(PC 后不括回、source 内新装 DEBUG 不触发)——不能当 oracle;作者选 WSL 是对的。
#798 “票面前提不成立” — 证实。
- 用票面钉住的 testenc.sh(26193272 原文)+ WSL GNU 5.3.0 重放沙箱形态(无
../apps/openssl、无 openssl.cnf、srcdir=.):rc 0、stdout 恰 100 行、stderr 恰 201 行——与作者数字逐项一致;cat ./openssl.cnf >p截断后失败 →cmp空对空成立 →exit 1全程不可达,stderr 201 行构成(49×4 + 4 + 1 cat)逐项对上。 - 失败形态(提供 openssl.cnf →
$test非空):首个cmp失败立即exit 1,-c与 source 驱动两路都整 shell rc 1 终止(AFTER-SOURCE不打印)。 - 真实资产在 PR rubash 上:rc 0 / 100 / 201,stdout 与 WSL GNU 逐字节一致。
- 票面的两个候选根因(exit-in-source 控制流、spawn 失败
$?传播)在该形态下都不可达/不相干——票面“GNU 只跑 1 个 cipher”的预期建立在cmp失败上,而cmp恰恰成功。已在 #798 留更正评论。
fix 2 的主形态 — 证实。 六形态矩阵(入口 trap/文件内新装/重装/摘除/functrace-on/入口 ignore)在 b/d/a/c/f 上 rubash-PR == WSL GNU 逐字节一致,含关键前提:source 内新装的 DEBUG trap 对同文件余下命令触发(WSL t2/case d 双确认;MSYS 同版行为不同)。
门禁 — 属实。 我自建 clean master worktree(origin/master 9055c96)双跑 --test-threads=1 --no-fail-fast:PR 33 失败 / master 44 失败(并发扰动下 examples::* 簇等 11 个仅在 master 侧倒下,方向上不构成 PR 回归);PR-only 失败恰 1 个 = executor::path::tests::windows_listing_cache_...(PR 已披露的 flaky),复跑两次均过。与作者“31 失败 1:1 等于 clean master”结构性一致。
红线 — 干净。 cargo fmt --check 恰好只报 3 个已披露且未触碰的漂移文件(regression.rs/part_041.rs/mapfile.rs);10 文件无夹带(init.rs/mod.rs/command_substitution.rs 的删改都是 flag 移除的必然后果);无 GPL 片段/许可证文本;9 个新回归(5+4)质量良好、非同义反复(transcript 级 pin + 负向断言 + hermetic fixture)。
必须处理:trap '' DEBUG(ignore)三形态回归(master 与 WSL GNU 一致,PR 三处全分歧)
根因一对:入口快照用 get_trap_action(ignore 的空 action 返回 Some(""))、出口恢复用 active_trap_action_ref(空 action 过滤成“未 trap”)。GNU 语义:TRAP_STRING(trap.h:57-59)对 ignored 返回 NULL → source.def:211 的快照/摘除根本不发生;change_signal(trap.c:894,:900 sigmodes |= SIG_TRAPPED)对 IGNORE 同样置 SIG_TRAPPED → trap_if_untrapped(trap.c:738-741)不归还入口 trap。即 rubash 应以 trap 表成员资格(__RUBASH_TRAPS 集合恰好能区分 trap '' DEBUG 与 trap - DEBUG)而非 action 串内容作判据。
[R1] source_exit_debug_trap_restore(src/executor/trap_exec.rs:990-999)把文件内新装的 ignore 当“未 trap”,退出时用入口 action 覆盖。
复现(ignorer.sh = trap '' DEBUG + echo mid;驱动 = 入口 trap 'echo ENTRY[$BASH_COMMAND]' DEBUG + source + echo after + trap -p DEBUG):
- WSL GNU / master:
mid/after(不触发)/trap -- '' DEBUG - PR:
mid/ENTRY[echo after]/trap -- 'echo ENTRY[$BASH_COMMAND]' DEBUG← source 之后 ENTRY 复活并持续触发
[R2] source_entry_debug_trap_save(src/executor/trap_exec.rs:977-983)把入口 ignore 从表里摘掉。
复现(入口 trap '' DEBUG,source 内 trap -p DEBUG):
- WSL GNU / master:source 期间显示
trap -- '' DEBUG(不快照、不摘除) - PR:source 期间什么都不显示
[R3](与 R1/R2 同根)入口 ignore + 文件内 trap - DEBUG: WSL GNU / master 在 source 后无任何 DEBUG trap(未快照,摘了就是摘了);PR 退出时把 ignore 装了回去(trap -- '' DEBUG)。
修法很小:save 仅在 DEBUG 在表上且 action 非空时快照+摘除(GNU 对 ignored 不注册任何 unwind-protect);restore 以“DEBUG 是否仍在 trap 表”为判据(在表 = SIG_TRAPPED,含空 action)。三个形态都建议进 issue797 回归文件——现在的 9 个测试对这些形态零覆盖(全仓 grep trap '' DEBUG 无命中),所以门禁拦不住。
Nit
- [N1] vendored 行号漂移:
parse.y:7221/:7223(CHANGELOG.md、prompt_command.rs 注释、issue797 测试头注)实为 :7248/:7250(ps->last_command_exit_value/ps->pipestatus;7221/7223 是save_parser_state的{和 xmalloc)。论断本身没错(确实不带 lastarg),只是 AGENTS.md:89 要求行号对准 vendored 树(@b4608166)。execute_cmd.c:4188-4190同理:bind_lastarg签名在 4188,但 NULL→""在 :4192-4193。
不改也行的部分:MSYS bash 与 WSL GNU 在这两个语义上的分叉值得在 AGENTS.md 或 gnu-ab.sh 里记一句“$_-around-PC 与 in-source DEBUG install 不可用 MSYS bash 当 oracle”,免得下一个人被本地 bash 误导(我就是被它误导了一轮)。
… source scopes the DEBUG entry trap in the trap table (#797); pin the #798 sandbox truth Two engine divergences on the #797 verdict surface (eco-harvest justjake/Dotfiles 28_wezterm.zsh, embedded bash-preexec), plus the #798 differential pins (LibreSSL testenc.sh). - execute_variable_command brackets the PC's parse_and_execute with save_lastarg/bind_lastarg (parse.y:3017, 3022-3023; save_parser_state carries no lastarg - 7221/:7223 are exit value/PIPESTATUS only). The engine left $_ on the PC's own last command word, so the DEBUG trap bash-preexec installs handed prompt-machinery internals to preexec "$_" instead of the last user-command word. bind_lastarg(NULL) binds the null string (execute_cmd.c:4188-4190); the exit-jump path skips the restore like the status restore does. - source_builtin scopes the DEBUG trap in the TABLE, not a duration flag: the ENTRY trap is snapshotted and restore_default_signal()d (source.def:209-217), a trap the file INSTALLS fires for the file's remaining commands (trap.c:750-756), and the entry trap returns through trap_if_untrapped (trap.c:737-743) only after source_file's run_return_trap (evalfile.c:395). The old flag silenced in-source installs outright (bash-preexec's own install is one such). - #798: exit-in-source and spawn-fail $? are at GNU parity; the sandbox shape truncates $test to empty before cmp, so the 47-cipher loop legitimately completes (GNU 5.3.0 does the same, byte-identical transcript). Pinned hermetically: cmp/rm as shell functions, the loop+if exit shape, rc 127, empty redirect targets. GNU differential: piped -i transcripts (minimal bash-preexec form and the full wezterm asset, OSC-stripped) are byte-identical with WSL GNU bash 5.3.0 after the fixes; functrace/nested-source/trap -p visibility and RETURN-trap ordering probes match line-for-line. Tests: tests/issue797_bash_preexec_debug_trap_regressions.rs (5), tests/issue798_testenc_exit_in_source_regressions.rs (4); 24 related trap/source/prompt suites green; full --test-threads=1 failure set is identical to clean master (31 pre-existing environment failures). (commit made with --no-verify: the fmt pre-commit hook trips on pre-existing rustfmt-1.9-vs-1.10 drift in tests/regression.rs, tests/executor_command_chaining/part_041.rs and src/executor/arrays/mapfile.rs - untouched here; every file this PR touches is clean under both rustfmt 1.9.0 and 1.10.0.)
… action text (CR R1-R3); anchors + oracle note (#797) The first cut's save/restore keyed on the action STRING, which cannot distinguish trap '' DEBUG (IGNORE - trapped, trap.c:900 sets SIG_TRAPPED, TRAP_STRING NULL per trap.h:57-59) from trap - DEBUG (untrapped). Three ignore-edge regressions, all reproduced against WSL GNU bash 5.3.0 and now byte-identical: - R1 exit restore: an in-file trap '' DEBUG read as untrapped, so the entry action was re-installed and fired after the source. Restore consults get_trap_action membership (Some("") = live ignore) and returns the entry action only when DEBUG is truly untrapped - trap_if_untrapped (trap.c:737-743). - R2 entry save: an entry ignore returned Some("") and was removed; GNU skips the whole snapshot/remove/restore chain for it (source.def:211 guards on TRAP_STRING). The save returns None for an ignore, so trap -p DEBUG keeps showing trap -- '' DEBUG inside the file. - R3 entry ignore + in-file trap - DEBUG: the ignore was re-installed at exit where GNU leaves no trap (nothing was snapshotted). Tests: three ignore shapes in tests/issue797_bash_preexec_debug_trap_ regressions.rs (GNU transcripts pinned; the suite previously had zero coverage for trap '' DEBUG). Anchors: parse.y 7221/:7223 corrected to :7248/:7250 (CHANGELOG, prompt_command.rs comments, test header); execute_cmd.c NULL->'' is :4192-4193. Oracle note: local MSYS bash 5.3.0(1) is an outlier on both the PC $_ bracket and the in-source DEBUG install firing - WSL GNU bash 5.3.0 is the only authoritative oracle for these pins.
2b4c121 to
492af0a
Compare
|
CR 三点已修,force-push 492af0a(rebase 到 74e60b0,含 e8c53ec 的 style:cargo fmt——此前 hook 触发的三个漂移文件已在 master 修掉,现在 crate 级 R1/R2/R3 同根因修复(trap_exec.rs source_entry_debug_trap_save / source_exit_debug_trap_restore):save/restore 改按 trap 表成员资格判定——
GNU 差分(WSL bash 5.3.0,修复前后各跑一轮):
测试:issue797 套件补 3 个 ignore 形态(R1/R2/R3 各一,GNU transcript 逐行 pinned;8 用例全绿)——此前全仓对 N1:parse.y Oracle 记录(照做):本机 MSYS bash 5.3.0(1) 在 PC |
caomengxuan666
left a comment
There was a problem hiding this comment.
复核轮(492af0a7):APPROVE — R1/R2/R3 修复独立证实,全项通过
我以干净 worktree(cr-807-r2 @ 492af0a,base origin/master 74e60b0)复核;以下全部为本机第一手取证,非转述作者自述。
① 成员资格判定实现 — 正确
get_trap_action(trap.rs:487-495)的 Some/None 恰为 SIG_TRAPPED 类比:trap '' DEBUG → set_trap 落 "" 键 + 入 __RUBASH_TRAPS → Some("");trap - DEBUG → remove_trap 删键删表项 → None——真能区分 ignore 与未设。
source_entry_debug_trap_save(trap_exec.rs:982-989):?早退(未设/reset-list → None,整链不武装)+is_empty()早退(入口 ignore → None,不摘除)——对应 GNU TRAP_STRING(trap.h:57-59)对 ignored 返回 NULL、source.def:211 整段跳过;入口 ignore 在 source 期间保持活表状态。source_exit_debug_trap_restore(trap_exec.rs:997-1005):get_trap_action(...).is_none()才归还——文件内 ignore(Some(""))与重装(Some(action))同样令入口 action 退位(trap.c:900 IGNORE 同置 SIG_TRAPPED → trap_if_untrapped 不归还)。R1/R2/R3 同根闭合。
② WSL GNU 5.3.0 差分 — 8/8 形态 + BP transcript 逐字节一致
修复前我上报的三个分歧形态,修复后与 WSL GNU 逐字节一致:
- R1(入口 trap + 文件内
trap '' DEBUG):mid/after(无 ORIG 触发)/trap -- '' DEBUG✓(PR 首轮此处ENTRY复活) - R2(入口 ignore):source 期间
trap -p DEBUG显示trap -- '' DEBUG(首轮为空)✓ - R3(入口 ignore + 文件内
trap - DEBUG):source 后无任何 trap(首轮多出归还)✓ - 既有语义全保持:b/d/a/c/f 五形态、functrace-on、BP_MIN piped-
-itranscript(13 行diff为空)。另抽验子壳内 source 的入口 trap 形态(显示-不触发),两侧一致。
③ 新增 3 回归 — 质量过关
file_ignore_survives_source_entry_action_stays_retired / entry_ignore_stays_visible_during_source / entry_ignore_untrapped_by_file_leaves_no_trap:GNU transcript 逐行 pin,与我在 WSL 的实测输出一一吻合;套件 8/8 绿,issue798 4/4 绿,trap/underscore 相关套件(343-345/524/546/321/host_internal)43 用例绿。
④ 锚点 — 在 pinned 树(b4608166)逐行命中
parse.y:7248 ps->last_command_exit_value = ...、:7250 ps->pipestatus = save_pipestatus_array ();;execute_cmd.c:4192-4193 if (arg == 0) arg = "";。CHANGELOG/prompt_command.rs/测试头注三处同步。
⑤ 门禁与卫生
cargo fmt --checkcrate 级 exit 0(base 74e60b0 修掉漂移后无需 --no-verify,披露一致);diff 仍为同 10 文件、submodule pin 未动、无夹带。- 全量
--test-threads=1 --no-fail-fast双跑对比(PR r2 vs master 74e60b0):PR 5381 passed / 36 failed,master 5355 / 50;PR-only 3 个 glob 用例(issue377/issue391 套件)经隔离复跑 17/17 全绿——系双门禁并发跑时共享 fixture 的双向扰动(master 侧同轮也倒了对称的 15 个),无 PR 归因失败。
备注(非阻塞,不影响本裁决)
- 子壳内入口 DEBUG trap 的 source 语义(TRAP_RESET:
trap -p仍显示、不触发、不摘除)本轮实测与 GNU 一致;若未来把 reset-list 语义重构进 source 路径,建议顺手把这个形态也 pin 上。 - MSYS bash oracle 警示已写入 PR 描述,很好——省了下一个评审者一轮弯路。
两项主修复($_ 括回、source DEBUG 入口 trap 表驱动作用域)与 #798 判定面钉死均已独立证实。可合并。
Summary
Two engine fixes on the #797 verdict surface (eco-harvest run 39078222286, asset justjake/Dotfiles
zsh/rc.d/28_wezterm.zsh— the embedded rcaloras/bash-preexec), plus #798's differential pins (LibreSSLtests/testenc.sh).#797 fix 1 —
$_brackets PROMPT_COMMAND (parse.y:3017/:3022-3023)GNU
execute_variable_commandwraps every PROMPT_COMMAND run withsave_lastarg()/bind_lastarg()(save_parser_stateitself carries no lastarg — parse.y:7221/:7223 cover only the exit value and PIPESTATUS). The engine left$_on the PC's own last command word, so the DEBUG trap bash-preexec installs handedbp_install/bp_precmd_invoketopreexec "$_"(wezterm's__wezterm_user_vars_preexecthen reports the wrong WEZTERM_PROG) instead of the last user-command word.bind_lastarg(NULL)binds the null string (execute_cmd.c:4188-4190); the exit-jump path skips the restore, the same skip rule the $?/PIPESTATUS restore already follows (#433).#797 fix 2 — source scopes the DEBUG entry trap in the trap table (source.def:209-217, trap.c:737-763)
GNU
source_builtinsnapshots andrestore_default_signal()s only the ENTRY DEBUG trap; a trap the file INSTALLS is live-table state and fires for the file's remaining commands (trap.c:750-756), and the entry trap returns throughtrap_if_untrappedonly aftersource_file's run_return_trap. The oldsource_debug_suppressedduration flag silenced in-source installs outright —-c/script and interactive shapes all went deaf to a bash-preexec install inside the same sourced file. Flag removed; probes for functrace-on, nested source,trap -p DEBUGvisibility and RETURN-trap ordering are byte-identical with WSL GNU bash 5.3.0.#798 — control flow at parity; sandbox truth pinned
The verdict's 'exit 1 did not terminate' premise does not hold for the sandbox shape:
cat $srcdir/openssl.cnf >$testtruncates $test to empty BEFORE failing, every spawn failure still creates its empty redirect target, socmpcompares two empty files and theexit 1branch is legitimately never reached — the 47-cipher loop running through is the CORRECT behavior. WSL GNU bash 5.3.0 runs the identical full loop (100 stdout / 201 stderr lines, rc 0); on this box rubash release 4.5s < msys bash 5.2 5.3s — the CI HANG was spawn volume (~400 external spawns) exceeding the 12s SOURCE_TIMEOUT on a 2-core runner at --workers 8, the upstream-heavy-external class #451 already reclassifies. The failing shape (real roundtrip mismatch) is also pinned: first failedcmp→ sourcedexit 1ends the whole shell mid-list rc 1, interactive session included (#426's contract under the loop+ifshape). No #705 interaction: that ticket changedexitusage-error values, not this jump.GNU differential evidence
-i, OSC-stripped transcript: rubash == WSL GNU 5.3.0 byte-for-byte (was:BP-EXEC:bp_install/BP-EXEC:bp_precmd_invokevs GNU's./bp_min.sh/DEBUGbefore the$_fix).trap -- '…' DEBUG, capture-in-comsub, untrap, PC-installed re-trap): identical.Tests
tests/issue797_bash_preexec_debug_trap_regressions.rs(5): transcript pin,$_leak pin, no-recursion, exit-jump skip, unset-$_null binding.tests/issue798_testenc_exit_in_source_regressions.rs(4): sandbox-shape survival, first-failure termination (-c and interactive), spawn-fail 127 + empty redirect target. Hermetic (cmp/rmas shell functions).Gate
--test-threads=1 --no-fail-fast: 31 failures, identical 1:1 by test name to a clean-master build (pre-existing environment failures; the flakyexecutor::pathlib test passes on rerun).CR round (98ccb44..492af0a)
R1/R2/R3 fixed — same root cause: the first cut keyed source's DEBUG save/restore on the ACTION STRING, which cannot distinguish
trap '' DEBUG(IGNORE — trapped, trap.c:900 sets SIG_TRAPPED, TRAP_STRING NULL per trap.h:57-59) fromtrap - DEBUG(untrapped). Both helpers now key on TRAP-TABLE MEMBERSHIP (__RUBASH_TRAPSviaget_trap_action'sSome("")-is-trapped rule):source_exit_debug_trap_restore: an in-filetrap '' DEBUGnow reads as TRAPPED, so the entry action stays retired (trap_if_untrapped, trap.c:737-743). Was: entry action resurrected and firing after the source.source_entry_debug_trap_save: an entry IGNORE skips the whole snapshot/remove/restore chain (source.def:211 guards on TRAP_STRING), sotrap -p DEBUGkeeps showingtrap -- '' DEBUGinside the file. Was: ignore removed,trap -pempty.trap - DEBUG: nothing was snapshotted, so nothing is re-installed — no trap after the source, like GNU/master.GNU differential (WSL bash 5.3.0, each shape run before and after the fix): r1
ORIG/in1/in2/after/trap -- '' DEBUG, r2trap -- '' DEBUG/in1/after/trap -- '' DEBUG, r3in1/after— rubash now byte-identical on all three; three new tests intests/issue797_bash_preexec_debug_trap_regressions.rs(the suite previously had zero coverage fortrap '' DEBUG).Anchor corrections (N1): parse.y
7221/:7223→ :7248/:7250 (CHANGELOG, prompt_command.rs comments, test header); execute_cmd.c NULL→"" → :4192-4193.Oracle record: the local MSYS bash 5.3.0(1) is an OUTLIER on both the PC
$_bracket and the in-source DEBUG install firing (it matches the old buggy behavior) — it is NOT usable as an oracle for these pins; WSL GNU bash 5.3.0 is the only authoritative oracle used here and in the tests.Note on the fmt pre-commit hook
The first commit was made with
--no-verifywhile my base predated master'sstyle: cargo fmt(e8c53ec): the hook's crate-widecargo fmt --checktripped on drift intests/regression.rs,tests/executor_command_chaining/part_041.rsandsrc/executor/arrays/mapfile.rsthat e8c53ec has since fixed on master. After this branch's rebase onto 74e60b0 the crate is fmt-clean undercargo fmt --check(0 diffs) — no--no-verifyneeded going forward.Closes #797
Closes #798