Skip to content

fix(lexer): close comsub extraction on case body/preamble ) and doomed ;; (Refs #3306) - #3878

Merged
caomengxuan666 merged 3 commits into
masterfrom
fix/3306-comsub-case-body-close-verdict
Nov 18, 2026
Merged

caomengxuan666 merged 3 commits into
masterfrom
fix/3306-comsub-case-body-close-verdict

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Summary

Fixes #3306 — command substitutions whose case body can never complete now report GNU's body-boundary diagnostic instead of the generic unclosed-) EOF route.

GNU parse_comsub (parse.y:4451) parses the body with shell_eof_token = ')' (parse.y:4519-4521): a ) arriving while the case pattern region is disarmed — clause body or case … in preamble — or inside a case already doomed by a pattern-position clause terminator (;;/;&/;;& is only legal after a clause body) IS the substitution's closer. The truncated body reaches the body parser, whose verdict the read-time screen reports (parse.y:4549-4555, 6858-6865).

Changes (all outside captain-exclusive src/lexer/continuation.rs):

  • src/lexer/skip.rs — skip_cmd_subst + skip_parenthesized_unit_corrected: new case_body_paren_depth (body/preamble parens own their ) first) and case_clause_terminator_in_pattern (;;-family in armed pattern region latches the doom); the close arm fires at body paren depth 0 with region disarmed or doomed.
  • src/parser/command_substitution.rs — dollar_command_substitution: same two trackers; empty-pattern () keeps the ) in the body source so the NEAR offender is )' itself.
  • src/script_driver.rs — command_paren_verdict_disproved_by_parser: !command_position clean-parse units whose only error lives in a comsub body now disprove the unclosed verdict (cond-marker and all other verdicts unchanged); interactive_pending_is_hard_syntax_error consults Executor::comsub_body_error_pending so stdin groups release at the same point GNU does.
  • src/executor/command_substitution.rs + public_accessors.rs — comsub_body_error_pending accessor; a literal )' offender renders without the while looking for matching suffix (parse.y:6858-6859).

Evidence

  • GNU bash 5.3.20 (/usr/local/bin/bash, WSL) script-file matrix, 33 shapes: 31/33 byte-identical (rc + diagnostic + offending-line echo). The 2 residuals are quoted-wrap variants (echo "pre $(case x in a) echo x) post") — a separate adjacent family where the dquote scanner never releases the inner ); pre-existing, unpinned here.
  • stdin mode (rubash < case.sh vs bash < case.sh): 6/6 match.
  • Pin tests/issue3306_comsub_unclosed_case_body_regressions.rs: 9/9 on head; on base a1f9718b the fail-first red set is {spaced/nospace pattern-body ), ;; terminator family, empty-pattern (), earlier-unit-voiding} — all reporting the old generic unexpected EOF line.
  • lib 双边: head failures {issue2084_session_end, respawn_state_spill×2} == base failures (environmental, state-file writes) — 差集空.
  • cli_tests: head 475 passed / 8 failed; of those, compat_issue78_multiline_arrays::unclosed_compound_assignment_at_eof_reports_gnu_eof_diagnostic was a real regression caught mid-work and fixed by narrowing the disproof (final state passes); remaining 7 fail identically on base (env: paths, timeouts, type -t, dirty build hash).
  • cargo test --lib lexer:: 111/111; comsub/case stems (issue2784/2789/3307/3756/3834/3605/305/2751/1641/1656/2309/2678/2740/3000/372/381/413/336/385) all green except issue381's 3 exact-prefix asserts which fail on base too (argv[0] path env).
  • RUSTFLAGS="-D warnings" cargo check clean; rustfmt clean on changed files; marker-lint OK; utf8-hygiene clean.
  • src/lexer/continuation.rs untouched.

Test plan

  • pin stem issue3306_comsub_unclosed_case_body_regressions 9/9 head / 5 red on base
  • GNU 5.3.20 script-file + stdin matrix
  • lib 双边差集空; warnings/fmt/marker-lint clean
  • cli_tests + focused comsub/case stems reported above

Generated with Devin

…med `;;` (Refs #3306)

GNU parse_comsub (parse.y:4451) parses the body with shell_eof_token
`)' (parse.y:4519-4521): a `)` arriving while the case pattern region
is disarmed — clause body or `case ... in` preamble — or inside a case
already doomed by a pattern-position clause terminator (`;;`/`;&`/`;;&`
is only legal after a clause body) IS the substitution's closer. The
truncated body then reaches the body parser whose verdict the read-time
screen reports (parse.y:4549-4555, 6858-6865).

The skip.rs oracle scanners (skip_cmd_subst,
skip_parenthesized_unit_corrected), the parser extractor
(dollar_command_substitution) and the unclosed-route disproof now share
that invariant via case_body_paren_depth +
case_clause_terminator_in_pattern; interactive_pending_is_hard_syntax_error
asks the comsub body walker so stdin groups release at the same point.
A literal `)' offender renders without the matching suffix
(parse.y:6858-6859).

Verified against GNU bash 5.3.20 script-file matrix: 31/33 shapes
byte-identical (rc + diagnostic + echo); the two quoted-wrap residuals
(`"...$(case...)..."`) are a separate adjacent family, unpinned.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@caomengxuan666

Copy link
Copy Markdown
Member Author

l2b 续作验证 — #3306 修复腿复核(head a02349f)

机制核查(GNU bash 5.3.20 源码锚点):

  • parse.y:4451 parse_comsub + parse.y:4519-4521:comsub body 以 ) 为 shell_eof_token 解析;case pattern region disarmed(clause body / case … in preamble)或已被 pattern-position ;;/;&/;;& 判死的 ) 即替换符收尾符——截断 body 交 body parser 判定(parse.y:4549-4555, 6858-6865)。
  • 实现与该不变量一致:skip.rs 双扫描器(skip_cmd_subst / skip_parenthesized_unit_corrected)与 parser 提取器(dollar_command_substitution)共享 case_body_paren_depth + case_clause_terminator_in_pattern;script_driver 的 !command_position 干净解析 + comsub body error 判 disproved,让 read-time screen 出 GNU 诊断而非 generic EOF route;literal )' offender 不带 matching 后缀(parse.y:6858-6859)。
  • 未触碰 src/lexer/continuation.rs(diff 名单已核)。

腿(实测数字):

  • 钉自跑:issue3306_comsub_unclosed_case_body_regressions 9/9 passed。
  • fail-first:同钉放 base a1f9718 上 4/9 passed / 5 failed,红名 = {earlier_unit_command_does_not_run, empty_pattern_paren_names_close_paren, nospace_pattern_body_paren_is_eof_token, pattern_terminator_in_pattern_position_keeps_suffix, spaced_pattern_body_paren_is_eof_token},失败输出均为旧 unexpected EOF while looking for matching )'' —— 有效。
  • lib:head 1374 passed / 3 failed {api::consumer_tests::issue2084_session_end_restores_host_process_state, respawn_state_spill_tests::aggregate_budget_spills_largest_first, respawn_state_spill_tests::oversized_entry_rides_the_state_file};后两者已实证 C: 盘 100% 满导致 200KB state-file 写入 ENOSPC(与本 diff 无关的子系统),issue2084 为 child-scenario 环境腿——建议队长 Linux oracle 复核归因。
  • -D warnings:cargo check 0 警告。
  • 卫生:rustfmt 逐文件 changed-files 全过(mod.rs 的 external_inner.rs diff 为基线既有);marker-lint OK(118 consts / 269 allowlist);utf8-boundary clean。
  • cli_tests:477 passed / 6 failed / 3 ignored,6 红均为环境腿(type -t 解析、外部命令缺失、路径前缀、startup 噪音),与 lexer 面无关。
  • regression goldens:165 passed / 69 failed / 1 ignored——抽查失败均为 cat/mkdir/rm: command not found(Windows PATH 无 Unix 工具)、fd/winuxcmd 面、ENOSPC;comsub 相邻的 golden_catfile_comsub 红因 fixture 首行 mkdir -p 缺失,非本 diff。建议队长在带 Unix 工具链的环境复核全量 ledger。
  • GNU 对照:WSL /usr/local/bin/bash = GNU Bash 5.3.20(1)-release;33 形状脚本文件矩阵 31/33 逐字节一致(rc + 诊断行 + offending-line echo)。stdin 路径(rubash < case.sh vs bash < case.sh)6/6 一致。
  • 相邻残差(未钉、已在 PR 正文声明):双引号包裹 "…$(case…)…" 两形(quoted/dbl)仍报 EOF-"——dquote 扫描器不释放内部 ),属另一机制族。

建议判词:PASS(机制与 GNU 一致,钉有效,环境红已逐条归因)。

caomengxuan666 and others added 2 commits November 18, 2026 11:45
All nine tests in this stem shared target/rubash-issue371-output.txt.
cargo nextest runs each test in its own process, so concurrent probes
truncated/read each other's redirect target — the PR #3878 census went
red on three cells whose "actual" output was a byte-mix of two other
probes' results. pid + counter keeps the path unique under both
nextest (process per test) and plain cargo test (threads, one process).

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@caomengxuan666
caomengxuan666 merged commit 9f128fb into master Nov 18, 2026
10 of 12 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/3306-comsub-case-body-close-verdict branch November 18, 2026 08:28
caomengxuan666 added a commit that referenced this pull request Nov 18, 2026
test: land rubash#3550 stale-hash pipeline-member pins (Refs #3550)

Pin-only PR: 11 regression pins for #3550 (stale hashed path in a
pipeline member: wrong ENOENT name, status 0, PIPESTATUS collapse).
No product code changed (single file tests/issue3550_pipeline_spawn_failure.rs,
+338/-0).

Evidence: the three symptoms no longer reproduce on base 58c4cab;
they were fixed by merged PR #3720. The pins pass 11/11 on this
head's census (job 134702174402); fail-first was established by the
lane on the pre-#3720 base (10 red), see ~/workspace/fix-3550/REPORT.md.

Census note: this head's census total is 123, far above the era band
(79-88). The +47 delta vs the pre-burst heads is in parser/quote/
comsub/EOF faces and belongs to the tip base (12-PRs merge burst
08:28-08:36Z), not to this pin-only diff: the pins themselves are
11/11 green and the diff touches no product code. The tip regression
is tracked separately; #3878 was exonerated by its own head census
(79 cells, issue3306 pins 9/9).

本 PR 删除了什么:无(纯新增测试文件)。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant