Repository navigation
Render conditional/for/select word lists from raw text in source serializer, Refs #2987 - #2990
Conversation
…Refs #2987 Background respawn serializes the function table through bash_command_source_text; its conditional arm joins cooked [[ ]] args, so [[ "$1" != '|' ]] re-serializes as [[ $1 != | ]] and [[ "$1" == "" ]] as [[ $1 == ]] - the respawned child dies at parse before its first command. In bats-core this kills the per-test timeout watchdog subshell (bats-exec-test's table carries such conditionals), so BATS_TEST_TIMEOUT never fires. Pins: quoted pipe/empty/space/glob operands, regex alternation + escaped space, inline subshell bodies, for/select word lists, and the watchdog countdown chain in miniature. Fail-first on master b3e4ff8: 9 of 10 pins red (only the unary/bang control passes both ways). GNU oracle: bash 5.3.20 script-file probes.
…alizer, Refs #2987 conditional_command_source_text joined the cooked ConditionalCommand args (quote markers stripped at cond-arg collection); for/select source text joined cooked map_list words the same way. GNU prints all three lists from the stored word text, quotes intact: print_cmd.c:881 print_cond_node (cond->op->word), print_cmd.c:586 command_print_word_list, :602 print_for_command_head, :656 print_select_command_head. GNU's async path never re-serializes (execute_cmd.c:701 single make_child fork inherits the parsed table); rubash's respawn must therefore round-trip losslessly. Route all three renderers through command_word_source_text (raw when metadata.value matches, single-quoted cooked fallback, comsub canonicalization) - the contract the case arm already keeps (rubash#1704).
Lane verification update (release-caliber acceptance)timeout.bats standalone, release binary built from this branch (
The remaining wall-time gap is a separate mechanism, out of this PR's scope, documented in the lane REPORT for captain adjudication: rubash's |
|
Captain review — rubash PR #2990 (Fixes #2987): verified, ready to merge.
Overlap note for the bats wave: Finding C of the bats lane edits the same |
…-depth The three issue2982 pins cover the prelude rendering regressions (quoted-empty [[ ]] word, for-word carrier leak) fixed by merged #2990 (fb96e74), not by this PR's C2 trap reset. Rewriting the file header so the attribution is accurate, and recording the honesty note: no independently fail-first probe shape for C2 alone was found (definitions skip DEBUG, the respawned child reads no startup file, the prelude is definitions-only), so C2 stays defense-in-depth, behavior-preserving, not pin-proven. Refs #2982
…) (#3012) Fixes #2982 Background wrapper trap re-arm (C2): the respawned wrapper child inherited live DEBUG/ERR traps while the prelude re-defined functions, so traps could fire against an incomplete function table. GNU's forked async child never has this window (execute_cmd.c:1576 execute_in_subshell). Fix resets DEBUG/ERR for the wrapper child and re-arms them after the prelude (src/builtins/trap.rs, src/executor/compound_exec.rs). Captain adjudication (decision (b), recorded in the captain review): C2 is accepted as defense-in-depth — its shape matches GNU trap handling and it is behavior-preserving on every probe. No distinguishing fail-first pin exists for C2 itself, and none is claimed. The two regression stems in this PR (issue2982_background_wrapper_trap_prelude_regressions, 3 tests; issue2983_background_wrapper_pgrp_kill_regressions, 1 test) pass unchanged on master without this PR (captain transplant onto 446d766: 3/0 and 1/0): they guard the render behavior delivered by merged #2990 (fb96e74), and the credit for what they verify belongs there. Refs #2983 — that issue stays open; its root is Finding E, blocked on #2995. 本 PR 删除了什么:无删除。净 diff 4 文件 +246/−0,纯新增(C4 重定向目标假设已在分支内调查证伪并回退,不在净 diff 中)。 Captain verification: pins on head 3/0 + 1/0; lib 1188/0/4 (baseline-identical); RUSTFLAGS="-D warnings" cargo check rc=0; hygiene clean; rustfmt clean over the branch diff; transplant no-fail-first result as documented above.
Refs #2987
根因
后台作业 respawn 时,子进程的
-c源码由bash_command_source_text序列化(函数表 prelude + 作业体)。其中conditional_command_source_text直接 join cooked 的[[ ]]参数(引号标记在 cond 参数收集时已被剥除),for/select 的词表同样 cooked-join:[[ "$1" != '|' ]]→[[ $1 != | ]]→unexpected argument '|' to conditional binary operator[[ "$1" == "" ]]→[[ $1 == ]]→unexpected argument ']]' ...[[ $x == "p q" ]]→[[ $x == p q ]]→ syntax error[[ "$1" == "a*" ]]→[[ $1 == a* ]]→ 能 parse,但引号字面量静默变成模式(语义损坏)for i in "a b" c→for i in a b c→ 迭代次数改变子进程在 parse 阶段整体死亡、一行不跑。bats-core 的每测试超时看门狗正是这样死的:bats-exec-test 的函数表里有这类条件式(如 test_functions.bash 的
[[ "$current_command_or_arg" != '|' ]]),倒计时子壳( ... ) &的-c源码 parse 失败 → 看门狗从未运行 → 没人发 TERM →BATS_TEST_TIMEOUT=1的测试睡满 10s 以 ok 退出(timeout.bats rubash 1 ok / 3 not-ok,GNU 4/0)。GNU 侧:print_cmd.c:881
print_cond_node打印cond->op->word(存词原文、引号犹在),print_cmd.c:586command_print_word_list、:602print_for_command_head、:656print_select_command_head同理;且 GNU 的异步路径根本不重序列化(execute_cmd.c:701 单次 make_child fork 继承整张已解析表)——rubash 的 respawn 序列化必须无损往返。修复
src/executor/command_text.rs三处渲染器统一改走已有的command_word_source_text(metadata.value 匹配时用 raw、否则 cooked 值单引号兜底、comsub 规范化)——与本文件 case 臂(#1704)已保持的 raw 契约一致:conditional_command_source_text([[ ]]参数)for_command_source_text(for 词表)select_command_source_text(select 词表)回归钉
tests/issue2987_respawn_conditional_word_quoting.rs(10 钉):引号|/空串/空格/glob 操作数、=~alternation + 转义空格、unary/bang、内联子壳体、for/select 词表、看门狗倒计时链微缩版(子壳内嵌后台 + TERM trap + wait + 函数调用)、TERM 送达主壳完整链。master 上 fail-first 9/10 红。本 PR 删除了什么
无删除。净行数以 diff 为准(渲染器三处改走既有 helper + 新钉文件)。
UNVERIFIED-BY-CAPTAIN(车道自报;队长复核为准)