Skip to content

parser/executor: quoted compound markers are plain command names (#3557) - #3612

Merged
caomengxuan666 merged 3 commits into
masterfrom
fix/3557-quoted-compound-markers
Nov 16, 2026
Merged

caomengxuan666 merged 3 commits into
masterfrom
fix/3557-quoted-compound-markers

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Closes #3557.

Problem

'(' echo hi ')' ran a subshell and '{' echo hi '}' died on syntax error: unexpected end of file. GNU treats the quoted markers as plain words: (: command not found / {: command not found, status 127, script continues.

GNU basis

  • parse.y:3667 read_token: ( is an operator and {/}/reserved words (!, function, case, for, select, coproc, [[, (() exist only unquoted in the token stream; a quoted marker is a word.
  • parse.y:3249 alias_expand_token → push_string: only an alias value is pushed back through the lexer, which is why the execute_alias_introduced_* probes exist at all.

Fix (two layers over-read the marker)

parser/parse_loop.rs — gate value-only matches on the unquoted spelling (is_unquoted_operator / raw == value):

  • {-EOF arm, [[ dispatch, both [[/((-starts arms, and the time-prefixed compound probe.

executor — the alias re-lex probes fired whenever the expanded head word equaled the marker, including a literal (/{/!/function/case/coproc/for/select that was never alias-introduced. Each probe now declines when command.words.first() already is the marker — only an alias-emitted head may take the re-lex path.

command_dispatch_late.rs — LateSlot::Arithmetic claimed any ((-headed words list; a quoted '((' produces no arithmetic_command node, so it now falls through to command-not-found like [[ already did.

Verified vs GNU bash

Byte-for-byte on the whole class: '(', '{', '!', 'coproc', '[[', '((', 'function', 'case', 'for', 'select' all print <w>: command not found + 127 and continue; x=5; '((' x++ '))' prints x=5 unchanged. Unquoted (, {, [[, ((, !, time, case still form compounds; alias lp='(' still reparses to a real subshell.

Regression pins in tests/issue3557_quoted_compound_marker_regressions.rs (6 tests).

Written by Devin

caomengxuan666 and others added 2 commits November 14, 2026 14:23
…s (Refs unixwin/niubash#955)

The pin-stem census (rubash#3430) enumerated tests/issue*.rs only, so the
~83 non-issue stems (oils spec corpus, executor_tests, lexer/parser
matrices, deep audits, enable_dynamic_loading, multi_session_isolation)
never executed anywhere -- niubash#955's visibility gap.

- scripts/ci-run-pin-stems.sh now enumerates tests/*.rs; any new target
  is covered by default.
- scripts/ci-pin-exclusions.txt gains an ELSEWHERE class for stems that
  already run in a dedicated lane (cli_tests, regression,
  marker_leak_golden) plus first-census entries for the stems red on
  master (2026-11-14 Linux census: 2721 tests, 2567 pass / 154 fail /
  36 skip). executor_tests was re-run serially (52 red of 1561) to
  separate parallel-load flake from product red.
- .config/nextest.toml: the intended hard-kill never existed --
  timeout-source/termination-timeout are unknown keys nextest silently
  ignores, so a hung test would still eat the job. Real config:
  slow-timeout period=30s terminate-after=3 grace-period=10s, i.e.
  log at 30s, kill by name at 90s -- exactly what the comment promised.
- New profile.ci override pins enable_dynamic_loading to
  threads-required=num-test-threads: its tests share the
  target/enable-dynamic-fixture .so and race under the parallel
  schedule (serial run: 10/10 pass).

Box verification: stub-cargo run enumerates 1381 stems with all 104
exclusions applied and no stale entries; full nextest census of the 83
new stems ran on this Linux box (raw logs under
target/issue-suites/results/niubash955-*).

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…ash#3557)

GNU read_token (parse.y:3667) recognizes '(' / '{' / '[[' / '((' and the
reserved words !, function, case, for, select, coproc only when they
arrive unquoted; a quoted '(' word is data, so '(' echo hi ')' reports
'(: command not found' (127) and continues instead of running a subshell
or dying on an EOF parse error.

Two layers over-read the marker:

- parse_loop.rs: the '{' EOF-error arm, the '[[' dispatch, the '(('
  starts_with arms, and the time-prefixed compound probe matched
  token.value only. Gate them on the unquoted spelling
  (is_unquoted_operator / raw == value), the codebase's own
  quoted-vs-operator discriminant.
- executor alias re-lex probes (execute_alias_introduced_*): they
  emulate parse.y:3249 alias_expand_token + push_string, which re-lexes
  only the alias VALUE. They fired whenever the expanded head word
  equaled the marker — including a literal '(' / '{' / '!' / 'function' /
  'case' / 'coproc' / 'for' / 'select' that was never alias-introduced.
  Decline when the command's own head word is already the marker.
- command_dispatch_late.rs LateSlot::Arithmetic: a words-only '((' head
  (no arithmetic_command node — only reachable when quoted) ran as
  arithmetic; route it to command-not-found like '[[' already does.

Verified byte-for-byte vs GNU bash: '(' echo hi ')', '{' echo hi '}',
'!' echo bang, 'coproc' x, '[[' x = x ']]', '((' 1 '))', 'function' f,
'case' x, 'for' x, 'select' x all print '<w>: command not found' (127)
and continue; unquoted (/{/[[/((/!/time compounds and an
alias-introduced 'lp='('' subshell reparse are unchanged.

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

Copy link
Copy Markdown
Member Author

【WIN-AGENT-AUDIT】
PR #3612 第1轮 — 建议:PENDING(内容 PASS,合入阻塞:CONFLICTING)
head: 0c37214 base(merge-base): 96802ca 文件: 11 个 +281/-40(其中 4 个 CI 文件)
关联 issue: #3557(状态:open,我核过的时间:2026-11-16 20:5x 本地)

合入阻塞(不合、不关):

  • gh pr view 3612:mergeable=CONFLICTING、mergeStateStatus=DIRTY。git merge-tree --write-tree origin/master 0c372141 → CONFLICT (content): Merge conflict in .github/workflows/ci.yml(其余文件可自动合并)。
  • 冲突来源:分支基于 96802ca,master 已把 pin-stem census 拆成独立 job(rubash#3656:pin-stem-census job),本 PR 携带的是旧结构(census 作为 rust job 末尾步骤 + 改 for f in tests/*.rs)。其中 .config/nextest.toml、scripts/ci-pin-exclusions.txt、scripts/ci-run-pin-stems.sh 三文件与 master 逐字节相同(master 已合过同一批 niubash#955 CI 改动),只有 .github/workflows/ci.yml 与 master 结构冲突。
  • 处置建议:rebase 到当前 master,丢弃 ci.yml 里的 census 改名/搬迁 hunk(master 已有),仅保留 5 个 src 文件 + 1 个测试文件;重新算 diff 后即可合。按调度补充第 3 条,本轮跳过合入。

机制核查:

  • 解析层:parse.y:3667 read_token —— (/) 只在未引号时以 operator 出词,保留字/[[/(( 同理;引号内是 WORD。PR 在 parse_loop.rs 的 {-EOF、[[ 两处起笔、((' 起笔、time前缀复合探测上统一要求token.raw == token.value(is_unquoted_operator`),与该语义一致,且是按类别一次收口,不是逐症状加 guard。
  • 执行层 alias 探测:parse.y:3249 alias_expand_token 只把 alias 值 push 回 lexer 重扫;字面 head 词不应触发重扫。PR 在 alias_reparse.rs(!/(/{/function/time/case/coproc)、alias_loops.rs(for)、alias_select.rs(select)、alias_arithmetic_for.rs(算数 for)上统一加「head 已是字面 marker 则 decline」,与原 alias_introduced_* 语义互补,机制正确。
  • command_dispatch_late.rs 的 ((':cmd.arithmetic_command.is_none() 时回落 external(command not found),与 GNU ((: command not found 一致。
  • 无关改动:4 个 CI 文件相对 merge-base 是本 PR 的账,但其中 3 个 master 已同内容、1 个引起冲突(见上);不是语义越界,但 rebase 时应丢弃。

腿:

  • 钉自跑(head):issue3557_quoted_compound_marker_regressions → test result: ok. 6 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out。
  • fail-first(base 96802ca,钉文件原样放入):test result: FAILED. 2 passed; 4 failed; 0 ignored;红名 = {quoted_brace_marker_is_command_name, quoted_conditional_and_arithmetic_markers_are_command_names, quoted_reserved_word_heads_are_command_names, quoted_subshell_marker_is_command_name},绿名 = {alias_introduced_paren_still_relexes, unquoted_markers_still_form_compounds}(守卫格正确地在 base 就绿)。钉有效。
  • lib 双边(两边都先 cargo build --locked --bin rubash):head 1350 passed; 1 failed; 4 ignored / base 1350 passed; 1 failed; 4 ignored;失败名集合两边都 = {api::consumer_tests::issue2875_input_procsub_child_runs_as_rubash_shell}(基线),差集 ∅。
  • -D warnings:cargo check --lib 0 警告;cargo check --test issue3557_quoted_compound_marker_regressions 0 警告。cargo check --tests 全量在未改动的 tests/issue1331_1334_signal_and_startup.rs 报 dead_code(run_script)→ 基线问题(本 PR 不碰该文件),不计本 PR。
  • 卫生:fmt 逐文件 rustfmt --check 7 个改动 .rs 全 ok;marker-lint OK (117 registry consts, 268 allowlisted sites);utf8 scanned src / clean。
  • CI(head 0c37214):红 = GNU regression goldens and canaries、Rust tests、Rust tests (macOS);三者红名均为 api::consumer_tests::issue2875_input_procsub_child_runs_as_rubash_shell → 基线。其余全绿。
  • GNU 对照:WSL /usr/local/bin/bash 5.3.20(1)-release(脚本文件 target/devin-s9/probes/p3557.sh),与 head 二进制逐字节一致:
    • '(' echo hi ')' → (: command not found rc 127 / 同
    • '{' echo hi '}' → {: command not found rc 127 / 同
    • '!' echo hi → !: command not found rc 127 / 同
    • '[[' x -eq 1 ']]' → [[: command not found rc 127 / 同
    • '((' 1 + 1 '))' → ((: command not found rc 127 / 同
    • 'coproc' echo hi → coproc: command not found rc 127 / 同
    • x=5; '((' x++ '))' → x=5(不执行算术)/ 同

F 点:无(内容面未见问题)。

未跑/VOID 的腿:

  • 无(合并腿因 DIRTY 未执行,按规程跳过)。

处置:本轮不合入、不关 #3557;rebase 丢 ci.yml 旧 hunk 后可直接复审合入。

# Conflicts:
#	.github/workflows/ci.yml
@caomengxuan666

Copy link
Copy Markdown
Member Author

【WIN-AGENT-AUDIT】
PR #3612 第2轮(T1 收尾·解冲突)— 建议:PASS
head: c3475c4(merge origin/master c3bf91e,ci.yml 冲突取 master 版)base(merge-base): c3bf91e 文件: 7 个 +219/-20(CI 4 文件全部消出)
关联 issue: #3557(状态:open,我核过的时间:2026-11-16 22:1x 本地)

冲突消解:

机制核查(沿用第1轮结论,本轮合并未改语义面):

  • 解析层 token.raw == token.value(is_unquoted_operator)按类别收口,引号内 (/)/{/!/[[/((/保留字是 WORD(parse.y:3667 read_token 语义);alias 探测各入口统一「head 已是字面 marker 则 decline」。与 GNU 一致,无关改动:无。

腿(全在 c3475c4 上重跑):

  • 钉自跑:cargo test --test issue3557_quoted_compound_marker_regressions --locked → test result: ok. 6 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out。
  • fail-first:钉文件原样放入新 base c3bf91e → test result: FAILED. 2 passed; 4 failed;红名 = {quoted_brace_marker_is_command_name, quoted_conditional_and_arithmetic_markers_are_command_names, quoted_reserved_word_heads_are_command_names, quoted_subshell_marker_is_command_name},绿名 = {alias_introduced_paren_still_relexes, unquoted_markers_still_form_compounds}——与第1轮在 96802ca 上的结果逐名一致,钉在新 base 仍有效。
  • lib 双边(两边先 cargo build --locked --bin rubash):head 1356 passed; 1 failed; 4 ignored / base(c3bf91e) 1356 passed; 1 failed; 4 ignored;两边失败名都 = {api::consumer_tests::issue2084_session_end_restores_host_process_state}(Windows 本地基线红),差集 ∅。
  • -D warnings:cargo check --lib 与 --test issue3557_quoted_compound_marker_regressions 均 0 警告。
  • 卫生:rustfmt --edition 2021 --check 7 个改动文件全 OK;marker-lint OK (117 registry consts);utf8 scanned src / clean。
  • GNU 对照:WSL /usr/local/bin/bash GNU bash 5.3.20(1)-release vs 合并后 target/debug/rubash.exe 同跑 target/devin-t1/probe-3557.sh(8 例:引号 paren/brace/bang/[[/((/coproc/算术 incr + 未引号对照)→ 逐字节一致。
  • CI:旧 head 0c37214 的三红均为 issue2875 基线签名(第1轮已核日志);新 head 含 ci: unmask master-red — issue2875 out/ resolver + masked test/corpus fixes #3750 修复,预期消除,合并前以新 CI run 复核。

F 点:无。

续作记录(本轮):

  • c3475c4 Merge remote-tracking branch 'origin/master' into t1-3612(ci.yml 冲突取 master 版)。新 head: c3475c4。

未跑/VOID 的腿:无。

@caomengxuan666
caomengxuan666 merged commit 8a83879 into master Nov 16, 2026
10 of 12 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/3557-quoted-compound-markers branch November 16, 2026 14:46
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
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.

[bug] 命令位加引号的 '(' / '{' 被当作子 shell / 组命令(GNU 为普通 WORD,command not found)

1 participant