Skip to content

fix(set): stop set scan at -- so set -- -t is positional (rubash#3410) - #3759

Merged
caomengxuan666 merged 1 commit into
masterfrom
ai-fix/rubash-3410
Nov 16, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
ai-fix/rubash-3410

Conversation

@arookieofc-ai

Copy link
Copy Markdown
Contributor

Fixes #3410.

The script-reader scan routed set -- -t to the grouped reader as if it set onecmd: set_args_may_set_onecmd (and its verbose/history siblings) walked every - bundle on the line without ever stopping at --. GNU stops option interpretation at the first -- (builtins/set.def pre-scan 671-691, apply loop 716-772, flags.c:372-382) — and at a lone -, and at the first non-option word its getopt would not consume as a -o operand.

The fix is one shared walk, set_option_words, modelling that scan; the three token scanners (onecmd, verbose, history) and the -o long-name checks all read from it. The executor needed no change: it already assigns $1 as -t and leaves onecmd off in the -c, stdin and script drivers (verified on baseline 8100d76), so this defect was routing-only.

Regression pin tests/issue3410_set_double_dash_scan.rs: 11/11 pass (fail-first on the unpatched tree: 7 passed / 4 failed). Oracle: GNU bash 5.2.21 script-file probes. cargo test --lib: 1249 passed, 0 failed, 4 ignored. Neighbours all green: issue3322 5/5, issue2960 14/14, issue2773 8/8, issue2957 2/2, issue2961 6/6. cargo fmt --check and git diff --check clean.

Notes: the shared walk also fixes two history-scan under-admissions (set -eo history, set -o -H); set +o history now over-admits to the grouped reader (costs only the incremental driver). Vendored GNU source is absent in this checkout (third_party/bash/ is an empty dir), so the set.def/flags.c citations follow the issue's recorded references, verified behaviourally against the GNU 5.2.21 oracle.

…h#3410)

The script-reader scan routed `set -- -t` to the grouped reader as
if it set onecmd: `set_args_may_set_onecmd` (and its verbose/history
siblings) walked every `-` bundle on the line without ever stopping
at `--`, so the `-t` past it was read as an option-bundle member.
GNU stops option interpretation at the first `--` (builtins/set.def
pre-scan 671-691, apply loop 716-772, flags.c:372-382) — and at a
lone `-`, and at the first non-option word its getopt would not
consume as a `-o` operand — so `set -- -t` leaves `$1` as `-t` with
no option touched, and `set -- -o onecmd` leaves both words as
positionals.

The fix is one shared walk, `set_option_words`, modelling that
scan: `--` / lone `-` / first unconsumed non-option word end the
option region, and every `o` in a bundle consumes one following
non-dash word as its option name (`set -o -t` still sets onecmd via
the `-t`, `set -o onecmd -t` via the `-t` after the operand). The
three token scanners (onecmd, verbose, history) and the `-o`
long-name checks (`set -o onecmd` / `set -o verbose`, previously a
bare line substring that fired past `--` and in comments) all read
from it. The executor needed no change: it already assigns `$1`
as `-t` and leaves onecmd off in the `-c`, stdin and script drivers
(verified on baseline 8100d76), so this defect was routing-only.

Side effects of the shared walk, both GNU-faithful: the history
scan no longer under-admits a bundle `o` operand (`set -eo history`
enables history, `set -o -H` enables histexpand via the `-H` the
`-o` refused to consume); `set +o history` now over-admits to the
grouped reader, which costs only the incremental driver.

Regression pin `tests/issue3410_set_double_dash_scan.rs`: 11/11
pass (fail-first on the unpatched tree: 7 passed / 4 failed — the
three `--` routing tests plus the `set -eo history` control).
Oracle: GNU bash 5.2.21 script-file probes (a script stops after
the `set` unit iff onecmd was really set).

## Verification (all run, per-item counts)

- New pin `tests/issue3410_set_double_dash_scan.rs`: **11/11 pass**
  (6 routing tests: onecmd/verbose/history `--` stops + controls;
  5 end-to-end script guards/controls).
- `cargo test --lib`: **1249 passed, 0 failed, 4 ignored**.
- Neighbours, all green, no new failures: `issue3322` 5/5,
  `issue2960` 14/14, `issue2773` 8/8, `issue2957` 2/2, `issue2961`
  6/6.
- `cargo fmt --check` and `git diff --check` clean.
- Vendored GNU source is absent in this checkout
  (`third_party/bash/` is an empty dir), so the set.def/flags.c
  citations above follow the issue's recorded references, verified
  behaviourally against the GNU 5.2.21 oracle.
@caomengxuan666 caomengxuan666 added bug Something isn't working gnu-baseline Tracked by the GNU Bash 5.3.0 true-baseline ledger P3-low 低:优化、文档、远期规划,有机会再做 labels Nov 16, 2026
@caomengxuan666 caomengxuan666 self-assigned this Nov 16, 2026
@caomengxuan666 caomengxuan666 added the area:cmdline invocation surface: flags, -c/-s/script mode, --encoded-command, --cwd-state label Nov 16, 2026
@caomengxuan666

Copy link
Copy Markdown
Member

Thanks for the PR — and for the thorough write-up. Per the owner's rule, external PRs are reviewed by the captain first; this one is queued for captain review, and I have done a first pass below. No merge and no requested changes from me.

What I read (full diff, 2 files, +404/−77)

The fix is one shared walk, set_option_words, modelling GNU's set pre-scan/apply loop: -- and a lone - end option interpretation, a -/+ word is a flag bundle, an o consumes the next word as the option name, and the first unconsumed non-option word stops the scan. The three routing scanners (onecmd, verbose, history) and the -o long-name checks all read from it, and the old bare-substring checks (line.contains("onecmd") / "verbose") are gone, so a comment or string mentioning the name no longer routes. The executor is untouched, which matches the diagnosis that it already assigns $1 as -t and leaves onecmd off — routing-only defect.

The new pin file tests/issue3410_set_double_dash_scan.rs has 11 tests: negative/positive scan pairs for onecmd, verbose and history (set -- -t, set -- -o onecmd, set foo -t, set -- -v, set -- -H, plus the set -o -t / set -o onecmd -- -t controls), and 5 end-to-end guards/controls run against the built binary (set -- -t leaves -t in $1 and the script runs on; set -o onecmd -- -t still stops the reader).

CI, checked by name (not by colour)

  • Main run 43796141418: the only failures on the three red legs (Linux Rust tests, macOS Rust tests, goldens) are the single known baseline test issue2875_input_procsub_child_runs_as_rubash_shell (goldens 1351 passed / 1 failed; macOS 1245 / 1). CLI tests, shell functionality tests, cross-target checks and the Windows compile check are green. Nothing here looks PR-specific.
  • Canary run 43796141519: the API ledger tripwire is green; the only red is the known ledger drift MISSING session-method rubash::api::Session::cwd, also not introduced by this PR.
  • One caveat: the new issue3410 stem does not appear in CI's selected test table, so the reported 11/11 currently rests on the author's local run — the captain will re-run the stem at review.

Notes for the captain's review (from the PR body, not new findings)

Thanks again — the captain will pick this up for full review and the stem re-run.

@caomengxuan666
caomengxuan666 merged commit 299d11d into master Nov 16, 2026
11 of 15 checks passed
@caomengxuan666

Copy link
Copy Markdown
Member

【WIN-AGENT-AUDIT】s2

PR #3759 第1轮 — 建议:PASS(已合并 299d11d)
head: 51bbe08;base(merge-base): 8100d76;文件 2 个 +404/-77
关联 issue: #3410(open → 合并后 closed,2026-11-16T10:4x UTC)

机制核查:

  • GNU 的 set 选项解释在 --、孤立 -、首个非选项词处停止(builtins/set.def:671-691 预扫、716-772 apply 循环,flags.c:372-382);-o 后的词是选项名而非 bundle。本 PR 用统一的 set_option_words 单趟扫描替换「子串命中」路由(onecmd/verbose/history 三处 + -o 长名),并删除 line.contains("onecmd") / contains("verbose") 的两处过接纳——方向是把路由收窄到真实选项区,不是再加症状守卫。
  • 执行器未改(本缺陷只在 script-reader 路由):set -- -t 的 $1 与 onecmd 状态在 -c/stdin/script 三驱动上均已正确,已用 GNU 对照逐形状确认。
  • set +o history 变为过接纳(只会多走 grouped reader),作者已在正文披露;无删除、无无关面改动。

腿:

  • 钉自跑:issue3410_set_double_dash_scan 11/11 pass(head)。
  • fail-first:base 8100d76 同文件 7 passed / 4 failed,红名 = {double_dash_stops_onecmd_scan, double_dash_stops_verbose_scan, double_dash_stops_history_scan, history_forms_still_route},与 PR 正文的 7/4 一致。
  • lib 双边:head 失败 {issue2084_session_end_restores_host_process_state} / base {issue2084..., pathmatrix_bridge_legacy_dialect_restores_funnel} → 差集 ∅(pathmatrix 为并行态 flaky,单跑绿)。
  • -D warnings:bin+lib 与 PR stem 目标 0 警告;全仓 --tests 的 issue1794/issue2278 dead-code 红为基线(PR 未触碰)。
  • 卫生:rustfmt 逐文件 0 差异;marker-lint OK;utf8 clean。
  • CI(run 43796141418):Rust tests = issue2875 基线;macOS 1245 passed/1 failed = issue2875;GNU goldens 1351/1 = issue2875;niubash = ledger 漂移 MISSING Session::cwd(ci: unmask master-red — issue2875 out/ resolver + masked test/corpus fixes #3750 面);其余绿。无 PR 专属红。
  • GNU 对照(WSL GNU bash 5.3.20(1)):10 个形状 set -- -t / set -e -- -t / set - -t / set -- -ot / set -- -o onecmd / set -o -t / set -t / set -eo history / set -- -H / set -o onecmd -- -t,stdout/stderr/rc 与 rubash 全字节一致(onecmd 真设置的 s7/s10 两边都在 set 后终止读取)。探针:target/s2/probes/set3410/s*.sh。

F 点:无

合并:299d11d545cbef7abcdbcc52d4ab081bb72bf8a0(squash,未删分支)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:cmdline invocation surface: flags, -c/-s/script mode, --encoded-command, --cwd-state bug Something isn't working gnu-baseline Tracked by the GNU Bash 5.3.0 true-baseline ledger P3-low 低:优化、文档、远期规划,有机会再做

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] set -- -t still routes -t as an option after -- (over-acceptance)

2 participants