Skip to content

api: Session::run admits live expand_aliases with an empty table - #3672

Merged
caomengxuan666 merged 4 commits into
masterfrom
devin/session-alias-live-empty-table
Nov 17, 2026
Merged

caomengxuan666 merged 4 commits into
masterfrom
devin/session-alias-live-empty-table

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Summary

Session::run's grouped-driver admission required a non-empty alias table on top of the live expand_aliases flag — so a submission where the flag is armed at reader start but no aliases exist yet (-o posix / --posix / -O expand_aliases; shell.c:1853 init_noninteractive seeds expand_aliases = posixly_correct) took the whole-source route. That route's word-level alias fallback expands reserved words without parse.y:5751-5769's posix ordering (posix checks reserved words BEFORE alias expansion), so alias for=echo + al for foo in v under -o posix expanded for to echo and died on a syntax error where GNU runs the loop and prints foo=v bar=.

The flag is the whole admission — the same answer run_command_string_with_init computes as alias_live_at_start for the bin -c route (rubash#414). GNU's reader is incremental (evalstring.c parse_and_execute) and the alias gate is consulted on every token (parse.y:5759), so aliases defined by an earlier line must be live for the lines read after it. One-line change: drop the non-empty-table term; plus a session_api regression test pinning a posix run through this contract.

Refs #3605 (class B, run-alias tail — clears the suite's last diff).

GNU anchors

  • shell.c:1853 init_noninteractive — expand_aliases = posixly_correct for a non-interactive posix shell (aliases live from the first line).
  • parse.y:5751-5769 read_token_word — posix reserved-word check BEFORE alias_expand_token (parse.y:3249); default mode after.
  • evalstring.c parse_and_execute — incremental command-by-command reading; alias definitions apply to subsequent input.
  • main.rs alias_live_at_start = executor.alias_expansion_enabled() — the bin-side admission this contract now matches.

Verification (macOS arm64, GNU bash 5.3.20 oracle)

  • niu -o posix -c 'alias al=" "; alias foo=bar; alias for=echo\nal for foo in v\ndo echo foo=$foo bar=$bar\ndone' → foo=v bar= (byte-identical to GNU; was foo in v + syntax error near unexpected token 'do').
  • niubash gate run-alias → PASS (last diff cleared).
  • cargo test --test session_api — new posix_run_expands_aliases_defined_in_the_same_submission pins the contract; all 9 issue414 reserved-word-alias regressions still pass. One pre-existing macOS-only flake (build_run_and_state_views_round_trip, /var → /private/var canonicalization) is unrelated.
  • Default mode unchanged: niu -c (no posix) still expands for→echo per parse.y:5768.

Test plan

  • cargo test --test session_api
  • cargo test --test issue414_posix_reserved_word_alias_regressions
  • niubash upstream gate run-alias PASS

caomengxuan666 and others added 2 commits November 15, 2026 00:42
…field (Refs #3605)

GNU hands `%.<digits>' verbatim to the host libc's printf(3) via the
PF() macro (builtins/printf.def:152-175). On BSD/Darwin libc the
precision digit run accumulates into an int field (xprintf.c:558-559),
wrapping mod 2^32: `printf "%.9223372036854775825s" XY' prints XY, and
the vendored printf.right golden expects exactly that. The previous
EOVERFLOW+PRETURN model fits an inline field *width* (xprintf.c:604-625
feeds an INT_MAX-checked pad) but not precision.

Precision overflow now wraps the digit run two's-complement into i32:
positive results apply as precision, negative results are "as if it
were missing". Inline width overflow keeps the EOVERFLOW error, and
the printstr specs (b/q/Q/T/S/C/wide) keep GNU decodeint() erange
semantics unchanged.

Verified on macOS arm64 vs GNU bash 5.3.20: %.9223372036854775825s/d
render as %.17s/%.17d, %.4294967295s prints the full string, and
niubash run-printf is PASS (the only remaining diff is the Mach-O
exec gap covered by PR #3586). New unit tests pin the wrap, the
wrapped-negative case, and the width EOVERFLOW boundary.

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

rubash#3605 class B (run-alias tail): Session::run's grouped-driver
admission required a NON-EMPTY alias table on top of the live
expand_aliases flag, so a submission like '-o posix -c' text — where
shell.c:1853 init_noninteractive seeds expand_aliases before the
reader starts but no aliases are defined yet — took the whole-source
route. That route's word-level alias fallback expands reserved words
without parse.y:5751-5769's posix ordering (posix checks reserved
words BEFORE alias expansion), so 'alias for=echo\nal for foo in v\ndo
...' expanded 'for' to 'echo' and died on a syntax error where GNU
runs the loop and prints 'foo=v bar='.

GNU's reader is incremental (evalstring.c parse_and_execute) and the
alias gate is consulted on every token (parse.y:5759), so aliases
defined by an earlier line must be live for the lines read after it —
the same admission main.rs computes as alias_live_at_start for the -c
route (rubash#414). Drop the non-empty-table term: the flag is the
whole admission, matching the bin-side answer.

Verified: niu -o posix -c 'alias for=echo; al for foo in v; do echo
foo=$foo bar=$bar; done' now prints 'foo=v bar=' (GNU bash 5.3.20
identical); niubash gate run-alias diff cleared (PASS). New
session_api test pins the posix run over this contract; the
pre-existing macOS-only build_run_and_state_views_round_trip /var ->
/private/var canonicalization flake is 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 #3672 第1轮 — 建议:PENDING(缺腿/阻塞;不合、不关单)
head: bbd2952 base(merge-base): 96802ca 文件: 4 个 +119/-7
关联 issue: #3605(open,umbrella 目录 issue — 按铁律不关单;核于 2026-11-16 20:3x 本地)

阻塞结论(为什么不合):

机制核查(只看本 PR 自己的两个文件):

  • src/api/session.rs:491-508:alias_live 从 alias_expansion_enabled() && !aliases_snapshot().is_empty() 改为只看 alias_expansion_enabled()。GNU 依据成立:reader 是增量式(builtins/evalstring.c parse_and_execute),别名门在每个 token 上查(parse.y:5759),posix 非交互 shell 启动即置 expand_aliases(shell.c:1853 init_noninteractive),所以「第 1 行 alias for=echo、第 2 行才读 al for ...」必须走分组/增量驱动,空别名表只是当前状态、不能当成「后续不会出现别名」。这与 main.rs 的 alias_live_at_start 口径一致,属修不变量而非加特判。
  • diff 里没有桥接/翻译层;无无关面改动(printf 部分是 test(builtins): pin inline printf width/precision overflow EOVERFLOW (Refs #3605) #3671 的,不计本 PR 机制)。

腿(逐项给数字与名字):

  • 钉自跑(head,cargo test --test session_api):18 passed; 2 failed。红名 = {posix_run_expands_aliases_defined_in_the_same_submission(本 PR 新钉), build_run_and_state_views_round_trip}。后者在 base 同红(见 fail-first 行),是 Windows 既存红(\\?\ verbatim 前缀 vs 普通路径,tests/session_api.rs:107),不记本 PR 的账。
  • 本 PR 新钉在 Windows 上红,根因不是产品语义,而是测试自身的路径拼接:tests/session_api.rs 里 out.display() 产出 C:\Users\...\out.txt 直接嵌进脚本文本 done >{path},反斜杠被 shell 当转义吃掉,实际写到了当前目录下名为 CUserscmxAppData...out.txt 的文件(我在 %TEMP%\rubash-session-api-posix-alias-live-empty-table-* 目录里看到了该文件),于是 read(dir,"out.txt") 找不到。作者在 macOS(/tmp/... 无反斜杠)看不出来。建议改成相对文件名或 POSIX 路径。
  • fail-first(本 PR 自己的改动,行为级):我用一个临时探针 tests/tmp_audit_3672.rs(未提交,跑完删除)在 Session::run 上跑同一形状、只用相对重定向 >out.txt:
  • GNU 对照(WSL GNU bash 5.3.20(1)-release, x86_64-pc-linux-gnu):
    • bash -o posix -c '<上面 6 行脚本>' → foo=v bar=,rc0;
    • rubash head -o posix -c 同形 → foo=v bar=,rc0(一致);父提交二进制同形也已是 foo=v bar=(CLI 路径早已修,只有 Session::run API 路径坏),所以 CLI 形不是判别腿,判别腿是上面的 API 探针。
    • 文件形 bash -o posix script.sh → foo=v bar=,rc0;rubash 同形一致。
  • lib 双边:head 失败名集 {api::consumer_tests::issue2084_session_end_restores_host_process_state}(1352 passed/1 failed/4 ignored)/ base 同集 {同一条} / 差集 ∅。
  • -D warnings(cargo check --all-targets):rc=101,唯一 error 是基线既有告警 tests/issue1794_user_group_completion.rs:15 unused import std::path::PathBuf(非本 PR 文件);本 PR 两文件 0 告警。
  • 卫生:rustfmt --check(session.rs、session_api.rs、printf.rs、printf_tests.rs)clean;check-marker-literals.py → OK;check-utf8-boundary-hygiene.sh → clean。
  • CI(head bbd29523,run 43700321284):红 = Rust tests / Rust tests (macOS) / GNU regression goldens and canaries,唯一 FAIL 均为 api::consumer_tests::issue2875_input_procsub_child_runs_as_rubash_shell(consumer_tests.rs:3503 "no rubash binary found")→ issue2875 基线,非本 PR;无 E0063/编译类红。

F 点(PENDING,按「待修」列出):

未跑/VOID 的腿:无(新钉在本机以临时探针替代跑通,原钉的 Windows 红已定位为测试路径缺陷)。
平台局限:GNU 对照为 WSL Linux 5.3.20;结论不依赖平台专属行为。

@caomengxuan666

Copy link
Copy Markdown
Member Author

【WIN-AGENT-AUDIT】
PR #3672 第2轮 — 建议:PASS
head: cbc0b02(远端;本地等价物 da497664d8f5da4c50c78339215664034a023a47,tree SHA 逐层核验一致)base(merge-base): fcc1de5 文件: 2 个 +54/-2
关联 issue: #3605(状态:open umbrella,我核过的时间:2026-11-17 02:20 本地)

机制核查:

  • src/api/session.rs:Session 准入由 alias_expansion_enabled() && !aliases_snapshot().is_empty() 改为只看 alias_expansion_enabled()。GNU 侧增量 reader(evalstring.c parse_and_execute 逐条读执行)下,expand_aliases 在 shell.c:1853 init_noninteractive 由 posixly_correct 初始化、早于任何输入读取;alias 表为空只是"尚无定义",脚本第 1 行 alias 定义、第 2 行即可用(parse.y:5751-5769 别名/保留字同层判定)。原实现把"表空"误当"别名关闭",POSIX 模式下同一 submission 内定义的别名永不生效——机制修正在不变量层(准入条件),非个案补丁。
  • diff 无无关改动(相对 merge-base 仅 session.rs + session_api.rs 两文件);merge 冲突解在 printf_tests.rs 一侧取 master 的 glibc EOVERFLOW 口径(WSL GNU bash 5.3.20 oracle),非本 PR 语义面。

腿(逐项给数字与名字):

  • 钉自跑(head,本地 Windows cargo test --test session_api posix_run_expands_aliases_defined_in_the_same_submission):1 passed / 0 failed
  • fail-first(merge-base fcc1de5 独立 worktree 原样放钉):0 passed / 1 failed,status left=2/right=0,parse_error=true——alias for=echo 未展开导致 for 循环语法错,与缺陷一致,钉有效
  • 钉文件全量(head):tests/session_api.rs 19 passed / 1 failed;唯一红 build_run_and_state_views_round_trip 为 Windows \\?\ verbatim 前缀环境差异(断言左 C:\... 右 \\?\C:\...),与本 PR 无关,master 同文件同测在 WSL 下 1/1 绿
  • lib 双边:本轮未本地重跑全量 lib;CI "Rust tests" job 在 head cbc0b02 上 pass(含 lib),足以覆盖本 diff(API 准入一行 + 钉)
  • -D warnings:session_api test target 编译 0 警告
  • 卫生:rustfmt --edition 2021 --check src/api/session.rs tests/session_api.rs clean
  • CI(head cbc0b02,run 43928035585):Rust tests / Rust tests(macOS) / Shell functionality / Compatibility CLI / Cross-target darwin / Cross-target linux/android / Windows compile / niubash builds / API ledger 全 pass;GNU goldens fail 与 master fcc1de5 同 run(43920250786)同为 {issue_753::case_9_declare_indexed_operand_binds_nothing, upstream_suite_slice_snapshots(braces golden)} 两条基线红;Regression pin stem census 截至发评时仍 pending
  • GNU 对照:机制依据为 GNU C 源(上述行号),行为面由 fail-first + 钉自跑双侧钉住;CLI 路径不经 Session API,本钉专测 in-process 仿真分支

F 点:无

续作记录:

未跑/VOID 的腿:

  • Regression pin stem census(CI):发评时 pending,跑完后若出现 session_api 相关新红需复核(本地钉已绿,预期无新增)

@caomengxuan666

Copy link
Copy Markdown
Member Author

【WIN-AGENT-AUDIT】
补充(第2轮 census 收尾复核):Regression pin stem census 已跑完 fail——session_api stem 全部 PASS,其中 posix_run_expands_aliases_defined_in_the_same_submission PASS;census 总红为已知基线量级(master 同 job 同量级红),本 PR 无新增失败名。维持 建议:PASS。

@caomengxuan666
caomengxuan666 marked this pull request as ready for review November 17, 2026 01:48
@caomengxuan666
caomengxuan666 merged commit 9b826d2 into master Nov 17, 2026
10 of 12 checks passed
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