Skip to content

fix(diagnostic): route histexpand failure + Invocation -c seed through argv[0] chain (Refs #3255) - #3611

Merged
caomengxuan666 merged 3 commits into
masterfrom
fix/3255-histexpand-prefix-invocation-name
Nov 16, 2026
Merged

caomengxuan666 merged 3 commits into
masterfrom
fix/3255-histexpand-prefix-invocation-name

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Refs #3255

根因(两点,同属 #3193 诊断名派生漏斗残留)

  1. src/script_driver.rs run_history_group:历史展开失败前缀是手写的 (script, line) match,任一缺失即落字面 "bash: "。交互读线期 line 已由 set_current_line_value 盖戳,script 名从不在该路上播种,所以可达形恰是字面臂:改名二进制 + rubash -i 管道输入 !nosuch 即印 bash: !nosuch: event not found。
  2. src/invocation.rs ShellInvocation::apply_to_executor:宿主经 Invocation API 驱动 -c 且未给显式 $0 时,往 __RUBASH_SCRIPT_NAME 种字面 "bash";main.rs 孪生位点已按 [B1-11] Diagnostic prolog hardcodes bash instead of the argv[0]-derived name (owner decision: impersonation vs fidelity) #2714 改为 BASH_ARGV0 派生,此为 API 孪生残留。宿主(niu 类)以改名 argv0 经 Invocation 驱动 -c 时诊断名被种成 "bash"。

GNU 锚

  • 失败展开的报告链:bashhist.c:594 pre_process_line 经 internal_error ("%s", history_value) → error_prolog(error.c:75-86)→ get_name_for_error(error.c:90-120)。交互壳只印壳名、无行号段;eval/-c 段只属于 parser_error(error.c:300-316),internal_error 没有。
  • -c 无显式 $0 时诊断名即 dollar_vars[0]:error.c:90-120;操作数成 $0:shell.c:523-528。
  • Oracle(GNU bash 5.3.20,setsid,管道 stdin,本车道实测):exec -a myname bash -i + !nosuch → myname: !nosuch: event not found;平 argv0 → bash: !nosuch: event not found。

修法

本 PR 删除了什么

  • run_history_group 里的手写 (script, line) 前缀 match 整段(含 {script}: eval 臂与字面 "bash: " 回退臂);该诊断现由执行器 error_prefix() 单一派生链提供。
  • invocation.rs 里 -c 无显式 $0 时种字面 "bash" 的旧分支与注释(行为由 BASH_ARGV0 派生取代;全无 carrier 时的 PROGRAM "bash" 回退保留)。
  • 未删除任何文件、公开 API、测试或功能。

验证(待队长复核,腿在 REPORT)

  • 回归钉:tests/issue3255_histexpand_prefix_invocation_name.rs(6 格:Invocation 派生/空 $0/无 carrier/显式操作数守卫 + 交互改名/平 argv0 前缀)。
  • 基底 fail-first 与头绿腿、lib 双边计数、RUSTFLAGS="-D warnings" check、fmt:见 ~/workspace/fix-3255/REPORT.md。构建槽位当时状况亦记于 REPORT(box 内存/磁盘门未过、老服务器 ssh banner 超时)。

UNVERIFIED-BY-CAPTAIN

@caomengxuan666

Copy link
Copy Markdown
Member Author

【WIN-AGENT-AUDIT】
PR #3611 审计第1轮 — 开工说明:审计腿已跑(钉 head 4/4、base fail-first 2 红、改名 argv0 交互探针 head=zimsh.exe: / base=bash:、GNU 5.3.20 oracle=myname: 一致、lib 双边差集 ∅、marker/utf8 干净)。唯一卫生缺陷:tests/issue3255_histexpand_prefix_invocation_name.rs:101 与 rustfmt 不一致(会导致仓库 pre-commit 的 cargo fmt --check 在合入后全树失败)。本轮只推一个 rustfmt 整理 commit(不改语义),随后发完整报告。

@caomengxuan666
caomengxuan666 marked this pull request as ready for review November 16, 2026 11:40
@caomengxuan666
caomengxuan666 merged commit 2ebc3a7 into master Nov 16, 2026
10 of 12 checks passed
@caomengxuan666

Copy link
Copy Markdown
Member Author

【WIN-AGENT-AUDIT】
PR #3611 第1轮 — 建议:PASS(已合入)
head: 5f03310(审计基线 0ffd036 + 本车道 rustfmt 整理 5f03310) base(merge-base): 27e1d0d 文件: 3 个 +260/-29
关联 issue: #3255(状态:open→本轮已 closed,reason=completed,squash 2ebc3a7)

机制核查:

腿:

  • 钉自跑(head 5f03310):issue3255_histexpand_prefix_invocation_name → test result: ok. 4 passed; 0 failed; 0 ignored(Windows 上 unix-only 交互 2 格被 cfg 跳过)。
  • fail-first(base 27e1d0d,钉文件原样放入):test result: FAILED. 2 passed; 2 failed; 0 ignored;红名 = {invocation_c_without_explicit_name_derives_script_name_from_bash_argv0, invocation_c_without_explicit_name_empty_bash_argv0_leaves_script_name_unset};绿名 = {invocation_c_with_explicit_name_keeps_operand, invocation_c_without_explicit_name_no_carrier_falls_back_to_program}(两端守卫格按 GNU 链在 base 就绿,正确)。交互改名格在 Windows 上不执行,用直接探针补(见 GNU 对照腿):base 打印字面 bash:,head 打印改名 basename → 判别成立。
  • 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 issue3255_histexpand_prefix_invocation_name 0 警告。
  • 卫生:cargo fmt --check 报 os error 206(仓库已知 Windows 限制),改逐文件 rustfmt --check:发现 tests/issue3255_histexpand_prefix_invocation_name.rs:101 一处不一致 → 本车道推 5f033104 style(test): rustfmt issue3255 pin (Refs #3255) 修平(纯换行,无语义),复检 CLEAN;marker-lint OK (117 registry consts, 268 allowlisted sites);utf8 scanned src / clean。
  • CI(head 0ffd036 的 run;新 head 5f03310 只改测试文件换行):红 = GNU regression goldens and canaries、Rust tests、Rust tests (macOS);逐个 job 日志红名均 = api::consumer_tests::issue2875_input_procsub_child_runs_as_rubash_shell → 基线。其余全绿。
  • GNU 对照:WSL /usr/local/bin/bash 5.3.20(1)-release(脚本文件 + 管道 stdin)exec -a myname /usr/local/bin/bash -i + !nosuchcmd123 → myname: !nosuchcmd123: event not found;平 argv0 → bash: !nosuchcmd123: event not found。rubash:head 复制为 zimsh.exe 跑 -i 管道 → zimsh.exe: !nosuchcmd123: event not found(Windows 可执行名带 .exe,unix 上 argv0 为 zimsh);base 同探针 → 字面 bash: !nosuchcmd123: event not found。与会话继续(FIRST/AFTER 都执行)一致。

F 点:无。

续作记录(本轮动过代码):

合入:

未跑/VOID 的腿:

  • 无(交互 2 格受 Windows cfg 限制未在 cargo test 内执行,已用直接探针 + GNU oracle 补齐并注明)。

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