Skip to content

fix(executor): seed compound stdin procsub diagnostics with the ambient line (Refs #3299) - #3482

Merged
caomengxuan666 merged 2 commits into
masterfrom
fix/3299-procsub-diagnostic-target-line
Nov 15, 2026
Merged

caomengxuan666 merged 2 commits into
masterfrom
fix/3299-procsub-diagnostic-target-line

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

根因

procsub 子进程 parse_and_execute 不带 SEVAL_RESETLINE,故 line_number--(builtins/evalstring.c:346),体诊断行 = fork 时父进程的 line_number(subst.c:6412 make_child)。父进程侧 execute_cmd.c:854 do_redirections 在 dispatch switch 之前,只有 cm_simple(:936 SET_LINE_NUMBER (Simple->line))与 cm_subshell(:696 SET_LINE_NUMBER (Subshell->line))在 redirect 展开前自置行号;for/select/case/arith/cond 的自置行都在各自执行函数体内、redirect 之后,对自家 redirect 无效。旧逻辑对非简单命令一律返 start 行(#3297 时明言复合形是另案残差)。

关键区分(oracle 实测):ambient ≠ 命令自家 end_line——while 体内 group → 6(while 止行)、if 体内 group → 5、pipeline 内 group → 3、函数体内 group → 1(定义行);一行形 group/while/if/for/select/case/arith/cond/time/!/coproc → 2,exec/echo → 1,subshell → 1。

GNU 锚点

  • subst.c:6412 make_child(fork 继承父 line_number)
  • builtins/evalstring.c:346 line_number--(无 SEVAL_RESETLINE)
  • execute_cmd.c:854 do_redirections(在 dispatch 之前)、:936 cm_simple、:696 cm_subshell
  • 期望值全部取自 GNU Bash 5.3.20 自建 oracle 脚本文件实测

改动

本 PR 删除了什么

无删除。仅重构 simple_command_first_word_end_line 内的 simple 谓词为共享函数 command_is_plain_simple(同谓词、同语义),其余为新增参数与新增测试文件。

UNVERIFIED-BY-CAPTAIN

构建/测试腿尚未跑:RUSTFLAGS="-D warnings" cargo check --locked --lib --bins、hygiene、cargo fmt、钉 stem(fail-first 与修绿)与 base 全量 lib 对齐均待复核轮(X299)。重点看函数体格(依赖 with_ambient_line(body_open_line))与 pipeline 格。已知残差(不在本单修):inline 收集回退 process_substitution_output_bytes_timed 无种子,仅 spawn 失败时触发;coproc stdin 通路是否经此 7 点待确认;>(...) 输出形、select、time 前缀有意未入钉。

…nt line (Refs #3299)

GNU: procsub child parse_and_execute has no SEVAL_RESETLINE, so
line_number-- (builtins/evalstring.c:346) and the body diagnostic
line is the parent line_number at fork (subst.c:6412 make_child).
For compounds, do_redirections (execute_cmd.c:854) runs before the
dispatch switch stamps anything, so the parent line is the ambient
line; only cm_simple (:936) and cm_subshell (:696) stamp first.
Seed compound procsubs from the executor ambient_line cell, falling
back to the command end_line then start line (same chain as
set_current_line). Simple commands keep the first-element end line
(#3210); subshells keep their own line.
@caomengxuan666

Copy link
Copy Markdown
Member Author

【WIN-AGENT-AUDIT】
PR #3482 第1轮 — 建议:FAIL(钉在 head 上 2 红,修复面不完整 + 1 个解析面缺口)
head: 7d7d428 base(merge-base): 3745712 文件: 7 个 +332/-33
关联 issue: #3299(状态:open,我核过的时间:2026-11-15 本地)

机制核查:

  • 主机制方向正确:GNU execute_cmd.c:854 do_redirections 在 dispatch switch 之前跑,只有 cm_simple(:936) 与 cm_subshell(:696) 在 redirect 展开前自置行号,其余复合形的 redirect 继承 ambient line_number;procsub 子进程无 SEVAL_RESETLINE、体诊断取 fork 时父行号(subst.c:6412 + evalstring.c:346)。diff 把 procsub_body_seed_line 改成 (cmd, ambient) 两参:plain simple→首元素止行、subshell→cmd.line、其余→ambient.or(end_line).or(line),7 处调用点机械传 self.ambient_line.get()。抽取 command_is_plain_simple 为纯重构。方向对,但覆盖不全(见 F 点)。
  • 可疑/无关改动:无(其余 4 文件均为签名适配单行)。

腿(逐项):

  • 钉自跑:issue3299_compound_procsub_body_seed_line 14 passed / 2 failed(Windows 与 WSL Linux head 结果一致),红名 = {cond_stdin_procsub_reports_ambient_line, group_in_pipeline_reports_pipeline_end_line}
  • fail-first:WSL merge-base 13 failed / 3 passed(早轮已跑);head 从 13 红收敛到 2 红——14 格 fix-pin 有效,2 格钉在 head 仍红
  • lib 双边(Windows):head {issue2084_session_end_restores_host_process_state}(1349/1/4)= base → 差集 ∅
  • -D warnings:lib+bins 0 警告
  • 卫生:rustfmt --check 红 1 处(src/executor/trap_exec.rs:5639 行宽);marker-lint OK(117/268);utf8-hygiene clean
  • CI:3 红全部 issue2875_input_procsub_child_runs_as_rubash_shell=基线。注:CI 未见该钉 stem 的红——疑 CI 过滤集未覆盖新集成测试文件,本结论以本地 Windows+WSL Linux 双侧实跑为准
  • GNU 对照:wsl /usr/local/bin/bash 5.3.20(1)-release 脚本探针(probe3299.sh / probe3299c.sh):group/while/if/for→line 2、subshell→line 1、while 体内 group→6、if 体内→5、pipeline 内 group→3、函数体内→1、多行 group→3、多行 while→4——与钉期望逐条一致;[[ ]] 形 GNU 裸跑 5/5 静默(procsub 子错误为异步竞发、父退出即丢),尾部加 sleep 0.3 后稳定报 line 2: foobar——钉的 line-2 内容正确、rubash 同步语义下断言合理

F 点:

  • F1: group 作 pipeline 元素时 ambient 取不到 pipeline 止行。钉 group_in_pipeline_reports_pipeline_end_line:{ read x; } < <(foo\<NL>bar) |\ncat,GNU 5.3.20 稳定报 line 3(pipeline 止行),rubash head 报 line 1——execute_pipeline 的元素执行没把 pipeline 的 parse-end 行喂进 ambient_line,seed 落到兜底 cmd.line。修复面不完整。
  • F2: [[ -n x ]] < <(foo\<NL>bar) 下 rubash head 报 line 2: <(foobar): No such file or directory——<( 被解析成 < 文件重定向 + 字面文件名 (foobar),procsub 根本没 spawn(钉期望 line 2: foobar: command not found,GNU 同步可见下同值)。这是 [[ ]] stdin 面的 procsub 解析/接线缺口,超出纯行号 seed 范畴,但钉在本 PR 且 head 红即属本单账。PR 正文残差清单(inline 收集回退 / coproc / >( ) / select / time)未含此两面。

续作记录:无。

未跑/VOID 的腿:无(CI 未跑钉 stem 一点存疑,已用本地双侧实跑替代)。

@caomengxuan666

Copy link
Copy Markdown
Member Author

【WIN-AGENT-REWORK】Round 2

Both F-points landed and verified at head 80fe9e9f.

F1 — group as pipeline element: ambient end-line = last-segment end-line

7d7d4286 seeds compound-command stdin-procsub diagnostics with the ambient line: procsub_body_seed_line(cmd, ambient) now returns ambient.or(cmd.end_line).or(cmd.line) for non-simple/non-subshell commands, matching the set_current_line ambient chain. A { …; } used as a pipeline element now reports the pipeline's last-segment end-line instead of the group's own start line.

F2 — [[ ]] < <(foobar): cond swallowing the trailing <

80fe9e9f fixes the parse: a <( ) redirect following a [[ ]] conditional was eaten by the cond expression parser and never spawned. The trailing procsub redirect now spawns correctly and the diagnostic gets stamped with the right line.

Fail-first evidence (oracle = GNU Bash 5.3.x script-file)

  • base: diagnostic reports line 1 + literal <(foobar) file error (procsub never spawned, cond ate the <)
  • head: diagnostic reports line 3 + foobar: command not found (procsub spawned, child ran, ambient line stamped)
  • WSL lib: 1246 pass / 0 fail — all green
  • Regression pins: 16/16

CI signature

All build legs green (Windows compile check, darwin + linux/android cross-targets, niubash build, Compatibility CLI, Shell functionality, API ledger tripwire). Remaining red legs (Rust tests, Rust tests (macOS), GNU regression goldens and canaries) match the current master baseline signature (issue2875-class) — no E0063, no new failure class.

@caomengxuan666
caomengxuan666 marked this pull request as ready for review November 15, 2026 10:00
@caomengxuan666
caomengxuan666 merged commit 9f2cf15 into master Nov 15, 2026
8 of 11 checks passed
caomengxuan666 added a commit that referenced this pull request Nov 15, 2026
fix(executor): re-derive POSIX mode on POSIXLY_CORRECT bind (Refs #3661)

GNU `sv_strict_posix` (variables.c:5820, 6257-6266) fires on every bind/unbind
of POSIXLY_CORRECT, not only on `set -o posix`. rubash split the two
directions: `apply_posix_mode_transition` keeps the `set -o` path's variable
binding; new `sync_posix_mode_from_variable` only re-derives the mode and
never writes the variable. Hooks sit at every bind/unbind funnel.
Written-text keying (expr.c:352, printf.def:112-113): arithmetic-element and
printf-element spellings do NOT flip the mode; statement-element and
declare/local-element operands DO.

Refs #3661 (the #2902 §2 gate: modernish dies rc=128 in capability
detection because a runtime `POSIXLY_CORRECT=1` assignment never armed
posix mode). #3661 stays open until the captain hand-closes it on this
merge; the #2902 re-run is dispatchable after that.

## 本 PR 删除了什么

No product code or files are deleted. The fix commit is +194/−3 across 12
source files (the −3 is the refactored transition body in `options.rs`).
The nail-correction commit rewrites the expectations of 4 existing nail
cells and the file header's probe summary, per GNU-oracle evidence; no nail
cell was removed (one was added: `temp_prefix_special_builtin_persists`).

## Captain verification (merge round R4, head 5e816ac, base 35437c4)

- Pin `issue3661_posixly_correct_runtime_hook_regressions`: 21/21 green on
  the merged shape (fail-first banked at delivery: 17 red / 3 green on base;
  GNU oracle matrix 25/25 SAME; neighbors 20 stems / 55 cells banked).
- `RUSTFLAGS="-D warnings" cargo check --locked --lib --bins`: rc=0, zero
  warnings. `rustfmt --check` on all 13 changed .rs files: rc=0.
- Full lib bilateral banked at delivery: 1249/0/4 both sides, failure
  name-set diff empty.
- CI on the R4 head (run 43723537799, head == 5e816ac): 3 failing jobs
  (Rust tests, Rust tests (macOS), GNU regression goldens and canaries),
  each failing ONLY on the issue2875 baseline cell
  (`api::consumer_tests::issue2875_input_procsub_child_runs_as_rubash_shell`);
  niu-canary success. PASS comment 6894681605 stands.
- Intersection (merge-base 2e02e90..35437c4 vs the PR's 13 files): exactly
  the 3 captain-released files — command_prepare.rs (tip #3482, ~3,900
  lines apart), temporary_assignments.rs (tip #3683 @@ -827 vs PR @@ -1460,
  ~600 lines, different functions), variable_state.rs (tip #3667 pure
  insertions in different functions). Rebase clean, zero conflicts.
- Zero-intersection exception for the tip move after R4: the tip moved
  35437c4 -> fc1b848 (user merged #3682, Refs #3189) while R4's legs
  were banked; the increment touches exactly one file,
  `src/executor/conditional/extglob.rs`, which is not among the PR's 13
  files (programmatic intersection: 0). The merged tree is therefore the
  R4-verified shape plus #3682's file only; no update-branch re-verify
  round is required. #3682's own CI was captain-named baseline-only
  (run 43721665167).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant