Repository navigation
seed-aware BASH_SOURCE bottom pop for interactive source - #3135
Merged
caomengxuan666 merged 9 commits intoNov 10, 2026
Merged
Conversation
caomengxuan666
force-pushed
the
fix/3125-interactive-source-bash-source-frame
branch
from
November 8, 2026 13:22
3b10d8f to
618e37a
Compare
…3125) GNU variables.c:5721 push_source holds only real frames; rubash's BASH_SOURCE views popped the stack bottom whenever there was no script main frame, assuming it was the $0 seed installed by set_env(__RUBASH_SCRIPT_NAME). An interactive session never installs that seed, so the pop ate the real sourced-file frame. Record the seed value at seeding time (bash_source_seed) and pop the bottom entry only when it really is the seed.
This was referenced Nov 10, 2026
caomengxuan666
marked this pull request as ready for review
November 10, 2026 15:43
caomengxuan666
added a commit
that referenced
this pull request
Nov 11, 2026
…#2731 #2732 #2733 #2734) (#3245) W-I1 interactive routes: histexpand seeding respects explicit opt-out; interactive definitions record `main`; monitor + diag faces pinned (head 7075bed) Fixes #2733 Fixes #2732 Refs #2731 Refs #2734 ## Per-issue account (captain review, true merge-base 9ec0355 + top-up pins) | Issue | Stem | Base | This head | Head merged with current master | |---|---|---|---|---| | #2733 | issue2733_interactive_histexpand_routes (5) | 4 passed / 1 failed (sole red `histexpand_optout_controls`) | 5 / 0 | 5 / 0 | | #2732 | issue2732_interactive_bash_source_main (5) | 2 / 3 | 2 / 3 (record value now `main`; remaining reds are the view-layer pop covered on master by PR #3135) | 5 / 0 | | #2731 | issue2731_interactive_monitor_default (6) | 6 / 0 | 6 / 0 (regression lock; host-side follow-up stays with the niu chain) | 6 / 0 | | #2734 | issue2734_interactive_diag_line_segment (7) | 5 / 2 | 5 / 2 (pins and fail-first evidence only; product code for this face is a separate lane) | 7 / 0 (the separate repair lane reached master first as PR #3332; the pin file is byte-identical on both sides) | ## Changes - #2733 seeding: GNU shell.c:1839 seeds the interactive histexpand default from the invocation-time state, so an explicit opt-out is the user's word. Both unconditional seeding sites (`apply_init_interactive_defaults` in src/main.rs, `initialize_interactive_history` in src/script_driver.rs) now seed set-if-unset on the `__RUBASH_SETOPT_histexpand` carrier: a command-line `+H` and a startup-file `set +H` both survive. - #2732 record face: GNU make_cmd.c:746-762 records `main` for a function defined at the interactive top level. New `definition_source` in src/executor/function_calls.rs records `main` when the BASH_SOURCE stack is empty and the invocation is interactive; every other route keeps the existing `current_bash_source` value, and that function itself is unchanged. The remaining view-layer half of the issue landed on master with PR #3135; the two halves together take the stem to 5/0, as measured on the merged tree during review. - Pins for all four stems are carried in from PR #3175 unchanged. ## Verification (captain review, landed logs) - Base red name sets match the registration exactly (2733 sole red `histexpand_optout_controls`; 2732 the three interactive-definition cells; 2734 the piped and `-i -c` cells). - Neighbour stems on the head: issue1252 3/0, issue1668 6/0, issue2072 4/0, issue2948 6/0; issue2142 4/1 with the same single red name on the base tree (pre-existing, outside this change). - Lib bilateral (both trees built `--bin rubash` first): base 1243 passed / 0 failed / 4 ignored, head 1243 / 0 / 4, failure name-set difference empty. - `RUSTFLAGS="-D warnings"` check (lib + bins) rc=0 with the flag proven loaded; `cargo fmt --check` rc=0; whole-tree UTF-8 boundary hygiene rc=0; marker-literal check rc=0; `cargo check --tests` rc=0. - Head CI (final head): 10 success + 1 skipped + 0 failures. On the review head the macOS library step failed once on the `issue2859_jobs_face_reaped_job_does_not_count` count race, a known load-flake family outside this change's files; that step is green on the final head. ## What this PR deletes - The two unconditional "set histexpand on" seeding writes (behaviour deletion: an explicit `+H` / `set +H` is no longer overwritten by the interactive default). - No files, no public API surface, and no tests are deleted. The four pin files arrive unchanged from PR #3175.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3125 — 交互
source不推 BASH_SOURCE 帧(Refs #3125,修法本身只解决本单)现象
交互 shell(PTY REPL)里
source ./sourced_outer.sh后,sourced 文件顶层读${BASH_SOURCE[0]}为空、${#BASH_SOURCE[@]}为 0;嵌套 source 内层深度为 1(GNU 为 2);sourced 文件定义的函数在 REPL 调用时读到空 / N=0;set -u下 sourced 文件内"$BASH_SOURCE"报unbound variable。-c与脚本文件形态全部正确,只有交互驱动路径偏离。实害:bash-completion pytest 套件(#2905 链)在交互 fixture 里source bash_completion,其顶层_comp__init_collect_startup_configs "$BASH_SOURCE"触发 unbound variable,2248 例卡在 fixture setup。根因
rubash 的
bash_source_stack底部由set_env(__RUBASH_SCRIPT_NAME)的两个播种臂(src/executor/public_accessors.rs:1687IS_C 臂、:1695普通臂)装入一个$0种子——本地实现装置,GNU 没有。三个 BASH_SOURCE 视图臂用“没有脚本主帧 ⇒ 栈底即种子 ⇒ 弹出”来补偿(src/executor/dynamic_arrays.rs:1516、dynamic_arrays.rs:1710、src/executor/arrays/executor.rs:68)。交互会话从不装种子(
run_interactive_stdin不设__RUBASH_SCRIPT_NAME,栈从空开始),于是source推入的真实帧成了栈底唯一元素,视图的pop()把它当种子吃掉。GNU 锚点(
bash-5.3/):builtins/evalfile.c:253source_file()无条件push_source;variables.c:5721push_source就是array_push,栈从空开始、无$0种子;execute_cmd.c:5313函数调用推定义文件;shell.c:1640主帧只对脚本文件推。GNU 的bash_source_a只含真实帧。修法:种子感知的弹出(seed-aware pop)
播种只发生在
set_env(__RUBASH_SCRIPT_NAME)以整栈替换装入单元素时;真实帧只从索引 0 插入;弹出只从索引 0——种子若存在,恒在栈底。新增bash_source_seed: Option<String>记录播种值,视图臂只在栈底确实等于已记录种子时弹出:src/shell/state.rs:bash_source_stack旁新增bash_source_seed: Option<String>(手动Clone同步加项)src/executor/init.rs:初始化为Nonesrc/executor/public_accessors.rs:两播种臂同步置种子(__RUBASH_IN_SOURCE臂不动栈、种子不动)src/executor/dynamic_arrays.rs:新增bash_source_bottom_is_seed()判定,两 BASH_SOURCE 臂弹出条件改为“栈底是种子”(其余门原样保留)src/executor/arrays/executor.rs:caller臂同改src/executor/external_finish.rs:fresh-shell 子进程前后保存/恢复加种子字段不改:
store_indexed_array_state存储格、current_bash_source()回退链、push_bash_source/pop_bash_source、函数入口/出口、has_script_main_frame()。#2732(REPL 定义函数的BASH_SOURCE[0]应为main)不在本单修法范围,两单正交。验证
tests/issue3125_interactive_source_bash_source.rs(4 格 PTY 形态,期望值逐字节取自 GNU oracle):fail-first 在真基底cd41459b上 0 passed / 4 failed(红法与 §1 逐字一致);头树 4 passed / 0 failed。probes/drive_oracle.sh+-c/-s/脚本对照):头树二进制与 GNU 逐字节一致——交互 OUTER-preBS0=[./sourced_outer.sh] N=1、INNERN=2、FNBS0=[./sourced_outer.sh] N=1、nounsetN=1/NS-RC=0;-c/-s/脚本对照全部一致。基底二进制同探针复现全部 4 处偏离。RUSTFLAGS="-D warnings"下cargo check --locked --lib --bins:通过——Finished dev profile in 40.56s,H2_EXIT=0,零警告/零错误(全日志warning/error[命中均为墙死段的写失败,非编译警告)。cd41459b,cargo test --locked --lib):头树1206 passed; 0 failed; 4 ignored(29.07s,LIB_HEAD_EXIT=0)、真基底1206 passed; 0 failed; 4 ignored(20.78s,LIB_BASE_EXIT=0),完全一致,修法对 lib 套件零影响。issue15872/2、issue10161/1、issue23027/7、issue231412/12、issue231712/12、issue5195/5、issue156313/13、issue20232/2;cli_testsfunction_call_stack_*3/3 通过(472 filtered out)。issue2142为基底本有失败(测试 bug),非本修法回归:头树 4/1 与基底树 4/1 完全一致(仅 nested 格失败,断言逐字相同);caller在嵌套-c帧上报 argv[0] 逐字值,测试以绝对路径调用却期望裸名bash,GNU 在同一调用形下亦印绝对路径。处置待定(另立单修测试 / 随本 PR 修)。cargo fmt --check全树通过;python3 scripts/check-marker-literals.pyOK(117 registry consts,265 allowlisted sites)。残余
REPL 定义函数的
BASH_SOURCE[0]:GNU[main] N=1;基底[] N=0;本修法后[environment] N=1——N 已恢复正确,值[environment]是 REPL 定义函数的记录定义位置,即 #2732 待修的面,本单不动。本 PR 删除了什么
无删除。纯新增字段(
bash_source_seed)+ 三处弹出条件收窄(stack.pop()改为“栈底是种子时才 pop”)。净 +60/−3 行(6 文件)+ 钉子 224 行。