Skip to content

test(interactive): pin (A;B);) stray-close family to GNU 5.3.0 across all modes (#845) - #852

Merged
caomengxuan666 merged 2 commits into
masterfrom
fix/845
Oct 19, 2026
Merged

caomengxuan666 merged 2 commits into
masterfrom
fix/845

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

结论先行

#845 的前提不成立:rubash 与真 GNU bash 5.3.0 在该形上无任何分歧。本 PR 不改引擎,只落实测一致性回归(6 条,覆盖 -c / stdin 脚本 / 交互 -i 三路),把该族行为钉死。

Oracle 证伪(根因证据)

#426 CR NIT-3 引用的「GNU bash 5.3 (msys) oracle」二进制 winuxcmd/usr/bin/bash.exe(版本串 GNU bash, version 5.3.0(1)-release (x86_64-pc-msys))不是 bash,是一个 243 KB 的启动器 shim。二进制内嵌字符串:

bash shim: failed to start
bash shim: cannot locate niu.exe; set NIU_SHELL to its path
src\bin\bash.rs

它实际拉起的是 niubash(niu.exe)。所谓「GNU 容忍 );) 尾部(跑子壳体、exit 0)」的裁决是 niu 自己的行为被 shim 原样回显。

以唯一基线 WSL GNU Bash 5.3.0(/usr/local/bin/bash) 实测,GNU 在全部四种形态(-c / 脚本 / 管道 -i / 真 PTY -i,后者经 script -qec bash -i)都拒绝该形:syntax error near unexpected token ')',子壳体不执行。

GNU C source 裁定

  • simple_list: simple_list1 ';'(parse.y:1377-1394)仅在 lookahead ∈ simple_list_terminator = '\n' | yacc_EOF(parse.y:1310-1314)时归约;) 不能开 simple_list1(parse.y:1389)→ ; 后遇 ) 是 yyerror,子壳体不跑。
  • ;+NEWLINE 完成列表(list0,parse.y:1274-1286)→ 拆行在 ); 之后的形态会执行子壳体,游离 ) 单独报错。
  • 交互存活:eval.c:203-207(EOF_Reached 仅 if (interactive == 0));PS2:read_secondary_line(parse.y:2327)。

实测矩阵(GNU=WSL 5.3.0;rubash ConPTY 走 pywinpty 键级驱动)

形态 GNU rubash master
-c '(echo a; echo b);)' -c: line 1: syntax error near unexpected token ')',rc 2,不执行 一致
-c '(echo a;\necho b);)' -c: line 2: ...,rc 2 一致
脚本单行 (a; b);) line 1: ...,rc 2,后续命令不达 一致
脚本 (a;\nb);\n) ;+换行完成列表→跑 a,b;游离 ) 行 line 3: ...,rc 2 一致
PTY -i (a;\nb);) 报错近 ),不执行,会话存活 一致(ConPTY 键级)
PTY -i (a;\nb);\n) PS2 边界执行子壳体,游离 ) 报错,存活 一致(ConPTY 键级)
PTY -i echo a; ) 报错,存活 一致(管道 -i)

诊断文本、行号归属、退出码逐字节一致(-c 行归属 line 1/line 2、脚本 $0: line N: 等)。

变更内容

  • 新增 tests/issue845_subshell_stray_close_regressions.rs:6 条回归,逐条在 doc comment 引用 parse.y/eval.c 依据与 oracle 实跑记录。

验证三行

  1. 新测试 6/6:cargo test --test issue845_subshell_stray_close_regressions;全量 cargo test --no-fail-fast -- --test-threads=1 中同样 6/6。
  2. 全量单线程:37 failed(基线区间 37-44 下沿;cli_tests 23 / executor_tests fd_redirects 6 / issue526 2 / regression snapshot 1 / 其余环境性单条),与既有基线族完全重合,无新增。
  3. cargo fmt --check 干净;RUSTFLAGS="-D warnings" cargo check --all-targets 仅既有 master 文件报错(issue592:249 / issue528:40 / issue282_stty / issue566),新文件零告警。

niubash 侧跟进(另行安排,不在本仓)

  • 该族真实分歧在 niubash:niu -c 与 niu stdin 脚本对 (A;B);) 接受(跑子壳体、exit 0),GNU 拒绝;niu 交互路径已与 GNU 一致。
  • niubash tests/interactive.rs::continuation_subshell_paren_completes(master:121,未被 ignore,已钉干净 ) 收口):保留该腿;其注释(master:114-119)的「GNU 5.3 msys 容忍尾部」表述即本次证伪的 mis-oracle,需按上文更正;并建议补两条按 GNU 期望的腿——交互 (printf a; PS2 printf b);) 应报语法错且不产出子壳体输出、随后提示符恢复;-c/stdin 腿应 rc 2。

Closes #845(not-a-bug,前提被基线证伪;一致性由本 PR 回归钉住)。

… all modes (#845)

#845 claimed GNU accepts the (A;B);) tail in an interactive PS2
continuation while rubash errors, interactive-only, with rubash -c and
stdin script accepting the same shape. Measured against the sole
baseline (WSL GNU Bash 5.3.0, /usr/local/bin/bash), the premise is
false on every leg, so this lands the measured conformance as
regressions instead of an engine change.

Oracle falsification: the '#426 GNU 5.3 msys oracle' binary
(winuxcmd/usr/bin/bash.exe, version string x86_64-pc-msys) is a 243 KB
launcher whose embedded strings read 'bash shim: cannot locate
niu.exe; set NIU_SHELL to its path' - it runs NIUBASH, so its
'accepts' verdict was niubash's own -c/stdin behavior echoed back.

GNU truth (all live-verified, plus the grammar): simple_list:
simple_list1 ';' (parse.y:1377-1394) reduces only when the lookahead
is a terminator (simple_list_terminator parse.y:1310-1314); ')' cannot
start simple_list1 (parse.y:1389), so ';' + ')' is a syntax error and
the subshell never runs.

- bash -c '(echo one; echo two);)' -> 'bash: -c: line 1: syntax error
  near unexpected token ')'', rc 2, nothing runs; multiline -c payload
  attributes the error to line 2.
- stdin script one-liner -> 'line 1: syntax error ...', rc 2, shell
  exits before the next command (script mode dies on first parse
  error; verified 'echo a\n)\necho b' runs only 'echo a').
- stdin script '(echo one;\necho two);\n)' -> the ';'+NEWLINE
  completes the list, the subshell RUNS, then the stray ')' line is
  'line 3: syntax error ...', rc 2, AFTER-OK never reached.
- interactive -i -> diagnostic reported, nothing executes, session
  survives (eval.c:203-207 reader_loop: EOF_Reached only if
  interactive == 0); split after ');' the subshell runs at the PS2
  boundary (read_secondary_line parse.y:2327) and the stray ')' errors
  separately. Verified for GNU on a real PTY (script -qec bash -i) and
  for rubash on a real ConPTY (pywinpty keystroke driver).

The genuine divergence in this family lives in niubash (niu -c and
stdin script accept the form, exit 0, where GNU rejects); niubash's
tests/interactive.rs continuation_subshell_paren_completes comment
needs the same oracle correction.
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.

交互 PS2 续行:(A;B);) GNU 接受而 rubash 报错(交互路径特有;-c 与 stdin 脚本同形均接受)

1 participant