Repository navigation
fix(state-views): snapshot seeded array/assoc vars from their mirror storage, not the import-seeded scalar cell (Refs #3083) - #3101
Merged
Conversation
caomengxuan666
force-pushed
the
fix/3083-snapshot-dynamic-rhs-prefix
branch
from
November 8, 2026 07:22
c48a090 to
8d7e7a2
Compare
…ars (Refs #3083) The inspection snapshot of BASH_VERSINFO / DIRSTACK / BASH_ALIASES / BASH_CMDS currently carries the raw env-mirror storage string as a Scalar (the STORAGE_WORD_PREFIX-led storage form for the indexed pair, "()" for the assoc pair) instead of the array value the snapshot's own declaration text renders. GNU keeps these as real ARRAY cells from birth (variables.c:1018 make_vers_array; variables.c:1882 init_dynamic_array_var for DIRSTACK with get_dirstack at variables.c:1619), and its environment import (variables.c:368 initialize_shell_variables) binds only plain scalars. Four tests drive the public Session inspection face: seeded indexed pair, live DIRSTACK after pushd, seeded assoc pair plus a live alias, and a user-binding control group. UNVERIFIED-BY-CAPTAIN
…ializing storage arm (Refs #3083) capture_variable trusted the typed cell first, but for the four startup-seeded array/assoc names (BASH_VERSINFO, DIRSTACK, BASH_ALIASES, BASH_CMDS) the typed cell is a plain Scalar holding a verbatim copy of the mirror storage string — VariableStore:: from_environment binds the whole init-seeded table as exported scalars, prefix byte and all — so snapshots (Session inspection, DAP variables) leaked the raw storage form, U+001D word prefix included, typed as a scalar. GNU's import binds only the process environment's plain scalars (variables.c:368 initialize_shell_variables); its own array cells are born as ARRAY objects (variables.c:1018 make_vers_array; variables.c:1882 init_dynamic_array_var("DIRSTACK", get_dirstack, assign_dirstack)), and the stack's live value is composed on access (variables.c:1619 get_dirstack). Fix the capture path, not the render boundary: when an array/assoc-marked name's typed cell is a plain Scalar and a mirror exists, capture through parameter_array_storage — the same materializing arm the mirror-absent capture already consults for exactly these names — falling back to the mirror text. Structured typed cells still win, so user arrays capture exactly as before. No render-side stripping; #3074's decode is untouched. Pin: tests/issue3083_snapshot_array_values.rs (previous commit) — 1 passed / 3 failed on base 9d155da, 4/0 with this fix.
caomengxuan666
force-pushed
the
fix/3083-snapshot-dynamic-rhs-prefix
branch
from
November 8, 2026 07:59
8d7e7a2 to
1805a40
Compare
This was referenced Nov 8, 2026
Member
Author
caomengxuan666
marked this pull request as ready for review
November 8, 2026 08:40
This was referenced Nov 8, 2026
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.
Refs #3083
队长复核 PASS(独立 clone 全腿亲验,见 ~/workspace/review-3083/verify.log)。
问题与根因
Session 快照(
views().inspection(),DAPvariables同源)在四个启动种子数组/关联名(BASH_VERSINFO、DIRSTACK、BASH_ALIASES、BASH_CMDS)上泄漏镜像存储串原文——含 U+001D 词前缀字节——且值类型报为 Scalar。字节级核实后根因与立案时的假设不同:前缀是真 U+001D 字符而非字面文本
\x1d,也不是declaration_scalar_rhs产生。init 把四名以存储形态种入 env 表,Executor::new经VariableStore::from_environment把整张种子表绑成 exported Scalar,typed cell 里于是躺着镜像存储串的逐字副本;capture_variable先信 typed cell,快照遂泄漏。DIRSTACK/BASH_ALIASES 的镜像本身还是出生快照(pushd/alias 不刷新),活值由parameter_array_storage在命名访问时合成(GNU variables.c:1619 get_dirstack 同形)。GNU 锚点:导入只绑进程环境的纯标量(variables.c:368 initialize_shell_variables);自家数组 cell 出生即 ARRAY 对象(variables.c:1018 make_vers_array;variables.c:1882 init_dynamic_array_var("DIRSTACK", get_dirstack, assign_dirstack))。
修法
修捕获路径,不动渲染边界(#3074 的渲染解码未碰,无渲染侧剥前缀):在
capture_variable的通用路径值匹配里新增一臂——array/assoc 标记名、typed cell 为纯 Scalar、且镜像存在时,经parameter_array_storage(镜像缺席臂本就为同组名字咨询的物化合成面)捕获,合成为空时回退镜像文本。结构化 typed cell 仍优先,用户数组捕获与此前逐字一致。本 PR 删除了什么
无删除。第二个提交为纯新增一支捕获臂(+37 行,含注释);第一个提交为新增测试文件。被否决的立案假设(字面文本说 / declaration_scalar_rhs 说)只存在于讨论中,未落代码,无可删。
验证(队长复核,独立亲验)
tests/issue3083_snapshot_array_values.rs:头树 4/0;fail-first(终版钉移植干净基底9d155da3)1p/3f,失败恰为三缺陷格、对照格绿;基底失败输出坐实根因(typed Scalar 躺镜像存储串、真 U+001D)。RUSTFLAGS="-D warnings"rc=0;fmt rc=0;utf8 hygiene clean;check-marker-literals OK(117 consts / 265 sites,无新增 allowlist);CR 无。declare -pGNU vs 头二进制同 cwd 逐字节 SAME,双边 rc=0、头 stderr 空。state_views.rs+37 为单一新臂(typed 臂之前),渲染边界零改动;未碰 continuation.rs 与 api-ledger.md。残余(均已立单,不挡合入)
declare -p BASH_ALIASES在 debug 构建 panic(variable_state.rs:1106)——复核用单内原脚本在基底与头二进制上同行同文亲验复现,既有缺陷、与本 PR 同根异面。attrs.exported对种子名误报 true;与已验机制一致,低风险。