Repository navigation
fix(print_comsub): never emit ';' after '&' in canonical comsub text (Refs #3662) - #3699
Merged
Merged
Conversation
…(Refs #3662) A background job inside $(...) in a defined function never ran: the background child is a respawned rubash -c whose program is the defined functions serialized ';'-joined plus the job's own command, and the canonical comsub printer emitted '& ;' for the background operator. '&' followed by ';' is a syntax error on both shells (parse.y:1275/1290: only newline_list may follow '&'), so the child died at parse and the job silently never executed. GNU anchor: print_cmd.c:257-272 '&' connector case prints ' &', plus one space only when a second command follows; semicolon() (print_cmd.c:1520) suppresses after ' &'. The background arm printed ' & ' with a trailing space, which both fed '& ;' through the list connector and defeated semicolon()'s ends_with(" &") guard, so a body ending in a background command printed '& ;' at its closer too. The fix mirrors ast_print.rs (whose background branch is why declare -f was already correct): arm prints ' &', list connector after a background command prints just a space, boundary still consumed. Regression nails: unit tests on print_comsub_text (issue #3662 shape, ';'-joined follower, plain ';' control, loop body ending in '&') plus integration stem tests/issue3662_bg_job_in_comsub_serializer_regressions.rs (issue minimal repro + regression seed functional half + control). UNVERIFIED-BY-CAPTAIN 本 PR 删除了什么:无(纯修复 + 回归钉;未删除任何功能、文件或公开面)。
Member
Author
|
【WIN-AGENT-AUDIT】PR #3699 第1轮 — 建议:FAIL head: b31ed3b base(merge-base): e81a1af 文件: 2 个 +207/-4 机制核查:
腿(逐项):
F 点:
续作记录:无(未改代码;FAIL 不合不关;#3662 保持 open)。 |
Member
Author
|
【WIN-AGENT-AUDIT】 机制核查:
腿(head d1c0e81):
F 点:无(F1 已修 d1c0e81;F2 由同一修复覆盖)。 |
caomengxuan666
marked this pull request as ready for review
November 16, 2026 15:29
caomengxuan666
added a commit
that referenced
this pull request
Nov 16, 2026
…eters (Refs #3783) ## 根因 `test -v` / `[[ -v ]]` 的全数字操作数恒返 false:`builtins::test::variable_is_set` 只查变量表(+ 动态参数),而位置参数从不进变量表,所以 `test -v 0`、`test -v 1` 等一律判未设置。 ## GNU 锚点 - `test.c:650-685`(unary `-v`):先 `valid_array_reference`,再 `valid_number(arg, &r)`,答 `r >= 0 && r <= number_of_args()`。 - `general.c:248-281` `valid_number`:strtoimax base 10,可选符号、前后空白、溢出判非法。 - `builtins/common.c:429-446` `number_of_args()`:即 posparam_count($1..$N 的个数,不含 $0)。 结论:`0` 恒 set;`N` 存在即 set;前导零按数值解析(`00` 即 $0、`01` 即 $1);`[[ -v N ]]` 与函数帧内同理。 ## 修法 - `src/builtins/test/variable.rs`:`variable_is_set` 增加 `positional_count` 参数;nameref 判定后用既有的 `super::valid_number` 做位置参数探针:`n >= 0 && n <= positional_count`(空串位置参数仍计入)。 - 线程化 `positional_count`(均为 live window 长度 `ShellState::positional_len`,帧感知):`test.rs`、`command_dispatch_late.rs`、`conditional.rs`、`simple_if.rs`、`test_tests.rs`。 - 回归钉 `tests/issue3783_test_v_positional_regressions.rs`:6 组,覆盖 seed 12 项 + 边界矩阵(`+1`、前后空白、`-1`、溢出、`0x1`/`1e1`/`1abc`、空串位置参数、`[ -v 0 ]`)。 ## 本 PR 删除了什么 无删除。仅新增:`variable_is_set` 等函数的 `positional_count` 参数与一处位置参数探针分支、回归钉文件 1 个。无行为删除,无公开面变动(未碰 `docs/api-ledger.md`、`src/lexer/continuation.rs`)。 ## 验证(队长已核) - X299 腿:fail-first 钉 1/6(仅 controls 组过,PIN_RC=101);修后钉 6/6;邻钉 #2710 2/2、#2073 3/3、#1707 4/4;`builtins::test` 单测 38/1;全量 lib 双边 1356/1 = 1356/1(唯一败 `issue2084_session_end_restores_host_process_state` 双边同格);`RUSTFLAGS="-D warnings" cargo check --locked --lib --bins` rc=0;seed 脚本对 built rubash.exe 12/12;GNU oracle seed 12/12;rustfmt 直核 7 文件 rc=0。 - CI run 43897420929(头 e23cc71,update-branch 到 master b5b0003 即 #3699 合入点):goldens 仅 `issue_753::case_9` + `upstream_suite_slice_snapshots`(与 master 逐格一致);census 86 败格 = 85 基线 + 1 主干继承格 `at_sign_at_a_quoted_with_colon_ifs_does_not_split`(master 跑 43895963546 同格 FAIL,旧头同格 PASS);CLI tests 单格 coproc 时序抖动 `c_command_keeps_named_coproc_output_fds_distinct`(left "first:\n" vs right "first:second\n"),重跑后绿;其余全 pass(darwin、linux/android、rust tests、macOS、shell、windows 编译、niubash 构建、ledger)。 - 队长复核:调用面 rg 已核(variable_is_set 外部 2 处、test::execute 6 处,无遗漏);`positional_len` 语义由钉边界格实测覆盖;漂移 hunk(#3612 的 command_dispatch_late.rs `((` 面)与本 PR hunk 相距约 260 行,update-branch 干净合入。 Refs #3783
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
根因
定义函数内命令替换里的后台作业永不执行:后台作业子进程是 respawned
rubash -c,其程序为全部已定义函数序列化;-join 后加作业本体;executor 的 canonical comsub printer(src/executor/print_comsub.rs,GNU print_cmd.c port)对命令替换内的后台算符&吐出& ;——&后跟;在两 shell 都是语法错,子进程死于解析,作业静默不执行(wait仍返回 0)。declare -f输出本身正确:parse-time printer(src/parser/ast_print.rs)早有 background 分支;错只在 executor 的 ComsubPrinter。GNU 锚点
&connector case:只打印&,其后空格仅当有第二个命令时才有(c != '&' || second);GNU 树里a & b是 connector 本身就是&的单个 connection,不存在&之后的;connector 节点。&之后只允许 newline_list。&结尾时不打印;。修复
src/executor/print_comsub.rs(仅此一文件 + 回归钉):&(尾空格)改为&,与 print_cmd.c 及 ast_print.rs 一致;print_command_list在前一命令为 background 时不走print_connector(不打印;/换行),只补一个分隔空格并skip_this_indent += 1,与 ast_print.rs 分支同形;boundary 仍按 consume-once 消费;ends_with(" &")守卫也恢复生效——以&结尾的循环/if/函数体不再于 closer 处印出& ;(同族)。影响面(codegraph 核):
print_comsub_text唯一调用方是canonicalize_comsub_spans,其调用方为command_text.rs(background 序列化两处)、parameter_errors.rs及 ComsubPrinter 自身(嵌套 comsub 递归);修法收敛于 comsub canonicalization,未动其他 list printer(bash_command_sequence_text与 ast_print.rs 的 background 分支此前已正确)。回归钉
src/executor/print_comsub.rs单元测试 4 个:issue 原形": & put \"\\""、a & b; c、纯;对照、循环体以&结尾;tests/issue3662_bg_job_in_comsub_serializer_regressions.rs3 个:issue 最小复现(仅定义函数 +: &)、回归种子功能半(bg-job-done 落盘)、无 comsub 函数对照。验证状态(UNVERIFIED-BY-CAPTAIN)
rustfmt --check(两改动文件)通过;git diff --check通过。RUSTFLAGS="-D warnings" cargo check --locked --lib --bins、GNU oracle 对照。原因:Simular box 钱包为空处于 hibernated,box_ensure明确返回钱包为空无法唤醒;老服务器与 X299-2607 均须经 box 中转,故全部远程构建路线均不可用;本 VM 按纪律不本地构建。待钱包充值后由队长/Win-agent 在 X299(Windows 面)+ Linux 侧(GNU 对照)补跑。&+;连接逐字吻合)与 GNU 锚点上,须以实测腿确认。本 PR 删除了什么
无(纯修复 + 回归钉;未删除任何功能、文件或公开面)。
Refs #3662