Skip to content

Refs #3108 - #3140

Merged
caomengxuan666 merged 3 commits into
masterfrom
fix/3108-snapshot-seed-exported
Nov 18, 2026
Merged

caomengxuan666 merged 3 commits into
masterfrom
fix/3108-snapshot-seed-exported

Conversation

@caomengxuan666

@caomengxuan666 caomengxuan666 commented Nov 8, 2026 •

Copy link
Copy Markdown
Member

Refs #3108

问题

Session 快照(views().inspection())把全部启动种子名报 attrs.exported = true,包括 BASH_VERSINFO、DIRSTACK、BASH_ALIASES、BASH_CMDS 等 GNU 从不导出的名字。env 表侧同名 attrs 为 exported: false,declare -p 文本不受影响。

根因

Executor::new 先经 initialize_fresh_shell_env_vars 把种子整表写入 env 表,再以 VariableStore::from_environment(&env_vars) 建 typed store,后者把整表无区别绑成 exported Scalar;capture_variable 的 merged_attrs 把 typed 的 exported 或入快照。真实进程环境条目 exported=true 无误,种子条目被一并打标才是误报源。external_finish 的 fresh-shell 子壳重建是同一形状的第二落点。

GNU 出处是逐条的:只有经进程环境到达的条目才带 att_exported|att_imported(variables.c:511-518);壳自身单元生来不带(variables.c:1010 make_vers_array;variables.c:1882 init_dynamic_array_var 以 attrs 0 注册 DIRSTACK)。

修法(队长裁定方案 i)

在绑定的源头定对:typed store 改从 VarTable 按其 attrs 出处绑定(exported 取表侧 attr_of),两个 from_environment 调用点(init 出生、external_finish fresh-shell)一并切换。不在 capture 合并规则处打补丁。

本 PR 删除了什么

删除 VariableStore::from_environment 在两个 executor 调用点上「整表无区别 exported」的绑定语义——该函数本身保留(其契约是导入裸进程环境映射,整表 exported 对该契约仍正确),executor 路径改走带出处的新绑定。无其他删除。

验证(接手车道复核,2026-11-09)

  • 钉基底 fail-first(tests/issue3108_snapshot_seed_exported,基底 88047f5):3 passed / 1 failed,唯一红 = seeded_names_snapshot_as_not_exported(恰缺陷格)。
  • 钉头:4 passed / 0 failed。
  • lib 基底:1206 passed / 0 failed / 4 ignored;lib 头旧轮唯一红为新单元测试自身的过期断言,已在提交头 9765d7b 中按实测语义订正(仅测试内断言与注释,无产品行为变化)。
  • 邻茎头:issue3083 4/4 + session_api 19/19。cargo fmt --check rc=0(提交头终树)。RUSTFLAGS="-D warnings" rc=0。
  • 提交头(9765d7ba)终轮复跑(钉/lib/邻茎/warnings 四腿)因本机间歇性写墙未能落地:多次尝试均 rc=101、腿日志 0 字节、零测试执行,同期 python 写探针全数 Operation not permitted——基础设施作废、非产品红(同日另一复核批同签名整批作废,已记 AGENTS.md)。期望终值:钉 4/4、lib 1207/0/4、邻茎 4/4+19/19、warnings rc=0;待写探针转绿后由队长复核补跑。

…(Refs #3108)

GNU binds att_exported only on entries that arrive via the process
environment (variables.c:511-518 initialize_shell_variables); its own
cells (variables.c:1010 make_vers_array, variables.c:1882
init_dynamic_array_var for DIRSTACK) are born unexported. The pin
asserts seeded names snapshot exported=false, inherited PATH/HOME
snapshot exported=true, declaration text keeps its shape, and the
write paths are unchanged. On the base tree only the seeded cell
fails (3 passed / 1 failed).
…venance (Refs #3108)

Executor::new and the fresh-shell rebuild in external_finish bound the
whole seeded env table via VariableStore::from_environment, which marks
every entry exported. The table already knows per-entry provenance:
initialize_fresh_shell_env_vars marks only genuine environment imports
exported (mark_initial_exported_vars) and seeds the shell's own names
(BASH_VERSINFO, DIRSTACK, BASH_ALIASES, BASH_CMDS, ...) after the sweep,
so the seeds are unexported on the table side while the snapshot
reported them exported=true through capture_variable's merged_attrs.

New VariableStore::from_var_table binds each entry's `exported` from
the table's own attr record; both executor birth sites switch to it.
from_environment is retained: its blanket-exported contract is correct
for a raw process-environment map.

GNU: variables.c:511-518 (initialize_shell_variables binds only
environment arrivals att_exported|att_imported); variables.c:1010
(make_vers_array binds BASH_VERSINFO readonly only);
variables.c:1882 (init_dynamic_array_var registers DIRSTACK with
attrs 0).
# Conflicts:
#	src/executor/external_finish.rs
@caomengxuan666
caomengxuan666 marked this pull request as ready for review November 18, 2026 08:30
@caomengxuan666
caomengxuan666 merged commit 932e402 into master Nov 18, 2026
10 of 12 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/3108-snapshot-seed-exported branch November 18, 2026 08:30
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