Skip to content

fix(main): derive startup diagnostics from argv[0] (#3254) - #3447

Merged
caomengxuan666 merged 5 commits into
masterfrom
fix/3254-main-rs-argv0-diagnostics
Nov 15, 2026
Merged

caomengxuan666 merged 5 commits into
masterfrom
fix/3254-main-rs-argv0-diagnostics

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Refs #3254

根因

src/main.rs 启动期诊断族硬编码字面程序名(bash: / rubash:),不随 argv[0] 派生:-o/-O 坏名、无效短选项、-c 缺参、未知长选项、长选项缺参、--profile-output 缺参、show_shell_usage usage 块、debugger starter 缺失对、init-file 读失败,共 11 处。另有两处名形差:run_args 的 --rcfile/--init-file 缺参臂恒印 --init-file 全名(GNU 印去横线名,且按实际选项分 init-file/rcfile)。

修法

启动期建单一名字源,全族共用:

  • 选项解析族(run_args / parse_long_options / show_shell_usage):run_main 一次算出 startup_error_name(argv[0] 逐字,NIU_INVOKED_AS 转发面优先;空名留空,缺失时回落 PROGRAM bash),逐层传参。usage 块用同一名字,唯空 argv[0] 时按 shell_name 救援为 bash。
  • 驱动时族(start_debugger / run_init_file):读执行器当刻绑定的 $0(driver_error_name:BASH_ARGV0 优先,空留空,缺失时回落调用名再回落 bash)——-c 的 $0 操作数与脚本名在驱动前已重绑 $0,与 GNU 一致。

GNU 锚点

  • shell.c:467 set_shell_name、shell.c:475/493 选项解析、shell.c:492 this_command_name = shell_name(-o 双名来源)、shell.c:529 this_command_name = NULL(-O 无第二名的原因)
  • error.c:90-120 get_name_for_error(名 = $0 逐字;空 $0 停住不回落,见 空 argv[0] 调用时 $0 被种成 /、诊断印 /: …(GNU 印空名) #3355;缺失时 PROGRAM)
  • shell.c:863-867 长选项缺参(名去横线)、shell.c:874-881 未知长选项、shell.c:519-528 -c 缺参、shell.c:1547-1566 start_debugger、shell.c:2057-2103 show_shell_usage、shell.c:1613 脚本/-c $0 重绑
  • 探针:本地 5.3.20 实测全矩阵(argv0=myname / 空 / 全路径 / BASH_ARGV0 导入 / -c $0 / 脚本形),脚本与日志见工作区 probes/gnu-3254-oracle.sh 与 REPORT。

本 PR 删除了什么

  • 删除 src/main.rs 中 11 处字面 bash:/rubash: 启动诊断前缀,改走单一派生源;删除 show_shell_usage 的字面 bash usage 行首。
  • 删除 run_args --rcfile/--init-file 缺参臂恒印 --init-file 的名形(改印实际选项去横线名)。
  • 未删除任何产品行为、选项或公开面;未改 docs/api-ledger.md;未碰 src/lexer/continuation.rs。

既有测试期望更新

  • tests/issue547_bash_o_listing_regressions.rs、tests/issue106_107_108_regressions.rs:旧期望写死 bash:,改为 harness 二进制路径(argv[0] 逐字,GNU 同理)。
  • tests/cli_tests/bashdb_compat.rs:debugger 对期望改走 cli_normalized_text(路径归一为 bash,与套件既有口径一致)。
  • 新钉:tests/issue3254_main_rs_argv0_diagnostics.rs(17 格,argv[0] 变体全族)。

相邻观察(未修,待队长立案)

GNU 对缺失/不可读的 --init-file/--rcfile 文件保持静默(无诊断、继续执行 rc 0),产品 run_init_file 则打印诊断并返回 1。本 PR 只修该诊断的名字,不改其触发与否。

验证状态

UNVERIFIED-BY-CAPTAIN

  • 本车道未执行任何 cargo 腿:本地构建禁止;box 探针时 cargo 锁被他道占用、MemAvailable 2.45G 未达 2.5G 门、盘仅剩 1.4G,按纪律停手;X299 跳板口令本车道无权取用。
  • 新钉 fail-first 未实测执行:CI 的 Rust tests 腿只跑精选 nextest 表,不含新钉 stem(见 CI 不跑新回归钉 stem:Rust tests 只跑精选 nextest 表 #3430)。钉按构造必红(期望字面量与基底硬编码字面量逐字不同),复核轮须先在基底跑新钉(应红)再在头跑(应绿),并跑全量 lib 与 base 逐数对齐、RUSTFLAGS="-D warnings" check、hygiene + fmt。
  • CI 首验待完。

Fail-first nails: src/main.rs startup diagnostics print literal
bash:/rubash: instead of deriving the program name from argv[0]
(-o/-O/-c/long-option/debugger family, plus the show_shell_usage
block). GNU anchors: shell.c:1779-1806 set_shell_name,
error.c:90-120 get_name_for_error, shell.c:1547-1566 start_debugger.
Refs: #3254
Single startup_error_name (argv[0] verbatim, NIU_INVOKED_AS face
first; empty stays empty, absent falls back to PROGRAM) shared by
the option-parse family (-o/-O/-c/long-option/--profile-output
diagnostics plus the show_shell_usage block, whose empty-argv[0]
name rescues to bash per shell_name); driver-time diagnostics
(debugger starter pair, init-file read failure) read the
then-current $0 from the executor (BASH_ARGV0, rebound by the -c
$0 operand and the script name before the drivers run). The
--rcfile/--init-file missing-argument arm now prints the actual
option name without dashes (init-file/rcfile) instead of always
printing --init-file.

GNU: shell.c:467 set_shell_name, shell.c:475/493/529 option parse,
error.c:90-120 get_name_for_error, shell.c:863-867/874-881/519-528,
shell.c:1547-1566 start_debugger, shell.c:1613 $0 rebinding,
shell.c:2057-2103 show_shell_usage.
Refs: #3254
@caomengxuan666

Copy link
Copy Markdown
Member Author

PR #3447 复核评论稿(FAIL,未发,队长发)

判词:FAIL — 产品对,钉错一处

复核了 cron 车道 PR #3447(Refs #3254,头 8e117215):main.rs 启动诊断族改走 argv[0] 派生,设计与 GNU 锚点(shell.c:467/492/529/863-867/1547-1566/1613;error.c:90-120)一致;新钉 17 格期望与 REPORT §0 的 GNU 实测矩阵逐字对得上(静态核查)。但 CI 唯一红腿是真失败,需返工:

bashdb_compat::bash_compat_debugger_options_run_init_file_before_script(Compatibility CLI tests 腿,471 测中唯一 1 败):

  • head 实测:target/rubash-bashdb-debugger-options-probe.sh: /usr/local/share/bashdb/bashdb-main.inc: No such file or directory + 同前缀 warning 行
  • 测试期望:bash: ... ×2

产品是对的:本轮亲跑 GNU 5.3.20 精确形态(--init-file <init> --debugger <script>,无 starter),两行前缀均为脚本路径本身,GNU 不印 bash:。错的是测试期望——cli_normalized_text 只归一化 harness 自身 exe 路径,从不碰脚本路径(其 doc 注释明言此类输出不得走它);车道把 arm B 期望改走该 helper 仍期望 bash:,是模型错。车道自己的新钉同形格(issue3254_debugger_missing_starter_uses_script_name)期望的正是脚本路径,与旧期望自相矛盾,新钉是对的。基底对照:base 同测试断言 raw rubash: ... 通过,head-only 失败,非 base-red。

返工范围(仅测试文件,产品码不动):tests/cli_tests/bashdb_compat.rs arm B(约 :1036-1045)——期望改带脚本路径(建议用 script.display() 拼,与新钉同口径),去掉该断言上的 cli_normalized_text 包裹。返工后重跑该单测 + 新钉 stem 17/17 + 全腿,终头 CI 全绿后重审。

欠账(本轮双堵未跑,如实记):本地写墙关(内容写全堵,1MB 写 EPERM、git init 失败;1KB 写"成功"实为 0 字节静默丢弃)+ 盒盘 691M 空低于 1.2G 门——新钉 fail-first/17/17、lib 名集、-D warnings、fmt/marker/UTF-8、X299 Windows 靶均未跑,返工轮补齐。

Owed:REPORT §5 相邻观察(缺失/不可读 --init-file/--rcfile,GNU 静默 vs 产品诊断 + rc 1)队长另立一单跟进,不阻塞本 PR。

)

The debugger no-starter pair prints the script path, not `bash:`: GNU
shell.c:1547-1566 carries the script name into the debugger-start
diagnostics. The test wrapped arm B in `cli_normalized_text`, which only
normalizes the harness's own exe path and must not wrap a script-path
leader (its doc comment says so).

Refs #3254
@caomengxuan666

Copy link
Copy Markdown
Member Author

复核(重审第 3 轮):FAIL(钉-only 返工)

队长复核(返工新头 63c031ce):钉 head 12/17、base 1/17——fail-first 成立(头修了基底 16 败中的 11 格),但 5 格仍红。

5 败分解

4 格 usage 格式(unknown_long_option / invalid_short_option / full_path_argv0 / empty_argv0):名全对(myname、/weird/path/foo、空→bash 救援均正确),只缺格式——产品印 myname [GNU long option]...,缺 Usage:\t 前缀与第二行 \t。GNU oracle 实测确印 Usage:\t<path> [GNU long option]...,钉期望与 GNU 一致。但缺失是基底有意的:base/src/main.rs:1390-1393 show_shell_usage() 注释明言“GNU 印 Usage:\tbash ...;上游套件会 sed 掉该前缀,故产品直接印归一化形”;PR(head main.rs:1437-1438)只把硬编码 bash 换成派生名,格式沿用基底。

队长裁断:钉的 4 处断言改归一化形 + 名。理由:归一化形是基底有意的既定行为,本 PR 范围是 argv0 派生名、不是 usage 格式;钉须断言产品既定行为。raw GNU 形与归一化形的取舍、以及 src/usage.rs:275-276(--help 路印 raw 形)与 show_shell_usage 的内部不一致,是另案产品决策,不在本 PR 返工内扩面。

1 格 debugger 脚本名(钉 bug,必改):败在 stdout 断言(:295)而非 stderr——finish() 已把 stdout 归一化(scratch dir → $S),左值 script-0=$S/script.sh;期望却用未归一化的原始 script_arg 全路径。返工只修了该格 stderr,stdout 漏改。改期望为 script-0=$S/script.sh;修后其 stderr 侧(arm B 返工)才得验证。

已绿的面

  • bashdb 套件 head 43/43(内含被改的 arm B 单测,首轮唯一红腿现绿)——arm B 返工本身已证。
  • 相邻 adj547 5/5、adj106 10/10,双边皆绿。
  • 终头 CI 全绿(run 43277591898:9 success + 1 skipping;43277591959 success)。

Owed(返工后重审补齐)

lib 双边名集、-D warnings 全靶强制重检、fmt/marker/UTF-8、GNU 三方探针、X299 Windows 靶。

返工要求

钉-only:4 处 usage 断言改归一化形 + 名;1 处 debugger stdout 期望改 script-0=$S/script.sh。返工后重跑:钉 stem 17/17 + bashdb 套件 + §6 全腿,终头 CI 全绿后重审。

Re-review round 3 (captain comment 6837786757): pin head was 12/17.
Four usage cells expected GNU raw Usage:\t form, but the product
deliberately prints the normalized form (base src/main.rs:1389-1393:
upstream suites sed the Usage:\t prefix away, so show_shell_usage
prints the normalized form directly). Per the captain ruling (b),
the pin now asserts the normalized form with the derived name, plus
a negative guard against Usage:\t. The debugger script-name cell
expected the raw script_arg path in stdout, but finish() normalizes
stdout (scratch dir -> $S); expect script-0=$S/script.sh.
Two pre-existing rustfmt reflows in the same file included (the file
was fmt-dirty at the prior head).

Refs #3254
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

【WIN-AGENT-AUDIT】
PR #3447 第2轮 — 建议:PASS
head: 0e6135d base(merge-base): c28a9dd 文件: 5 个(src/main.rs + 4 测试文件)
关联 issue: #3254(open,核于 2026-11-15)

机制核查:

  • 产品 main.rs 启动诊断走 argv[0] 派生,GNU 锚队长已核(shell.c:467/492/529/863-867/1547-1566/1613;error.c:90-120),本轮未动产品码。
  • F 点复核:63c031ce 已将 bashdb_compat.rs arm B 期望改带 script.display() 路径(与新钉 debugger_missing_starter_uses_script_name 同口径)、去 cli_normalized_text 包裹 —— 实测该格转绿。

腿(X299 本机):

  • 红格复跑:cli_tests bash_compat_debugger_options_run_init_file_before_script 1/1 绿
  • 钉自跑 head(Windows 面):issue3254_main_rs_argv0_diagnostics 2 passed / 0 failed —— 15/17 格 cfg(unix) 门控,本机仅 2 个 control 格可跑(如实写,非「17/17」)
  • fail-first(base c28a9dd + 钉):0 绿 / 2 红 —— 2 个 control 格在 base 红(base 印 rubash: 前缀非 argv[0] 派生名)→ fail-first 成立(Windows 面全集红;unix 格待队长 Linux 腿)
  • lib 双边:head 1349/1/4 {issue2084_session_end_restores_host_process_state} / base 同集 / 差集 ∅
  • -D warnings:cargo check --lib --bins 前轮绿;钉目标 cargo test --no-run 修复前 3 条死代码警告(STARTER / system_starter_exists / assert_usage_block 仅被 cfg(unix) 格引用 → Windows 下死代码硬错)→ 本轮已修,0 错
  • 卫生:rustfmt --check 钉 + bashdb_compat 干净;marker-lint 前轮 OK
  • CI(前头 309c94a):唯一红为 issue2875 基线签名

F 点回应:

  • F1(arm B 期望错用 bash: 前缀):已由贡献者 63c031c 返工 —— 复核通过,该格绿。

续作记录:

  • 0e6135d test-only:为 STARTER / system_starter_exists / assert_usage_block 补 #[cfg(unix)],消除 Windows -D warnings 死代码硬错
  • 新 head: 0e6135d(push 前远端 head 309c94a 未被推进)

未跑/VOID 的腿:

  • 15/17 unix 钉格头侧 + fail-first(Linux 专属,队长侧);新 head CI 以队长复核时最新 run 为准

@caomengxuan666
caomengxuan666 marked this pull request as ready for review November 15, 2026 02:07
@caomengxuan666
caomengxuan666 merged commit 41fc7b2 into master Nov 15, 2026
8 of 11 checks passed
caomengxuan666 added a commit that referenced this pull request Nov 16, 2026
…s GNU does (Refs #3457) (#3549)

GNU runs every startup file through builtins/evalfile.c:339
maybe_execute_file with FEVAL_ENOENTOK: ENOENT is not diagnosed
(evalfile.c:120) and returns 0 (evalfile.c:130); EACCES and other open
failures still go through file_error, and a directory is reported as
`%s: is a directory` (evalfile.c:133-138). run_init_file diagnosed
ENOENT and, on Windows, reported a directory as `Permission denied`.

The diagnostic name prefix is untouched (PR #3447 owns it). Also
rustfmt the d11 stem (master drift from #3511) so the fmt hook passes.

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

Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
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