Repository navigation
fix(executor): re-derive POSIX mode on POSIXLY_CORRECT bind (Refs #3661) - #3669
Conversation
|
队长复核:PASS(本地腿全齐;CI 按名待新代 run 落定,合入前补齐) 复核对象:新头 机制(队长亲读 diff):GNU 钉修正 4 格(非原处方 2 格)队长认可:set +o 的 stderr/rc 格、临时前缀特建提升格(新增第 21 格 腿(队长抽核 lib 日志原文 + REPORT 逐 stem 表):
待补:新代 CI(run 43716437689,头 9950cf9)在跑——Rust tests job 已显 failure,run 落定后队长按名补核;若出现 issue2875 基线 cell 之外的新红,本 PASS 失效待复议。 合入轮:update-branch 到现尖 |
e1d1b39 to
346a95a
Compare
Fail-first regression nails for rubash#3661: assigning POSIXLY_CORRECT at runtime must flip POSIX mode (GNU variables.c sv_strict_posix), so export -p prints the POSIX form. Covers the plain assignment, empty value (value preserved), unset, set -o/+o posix, temp-prefix restore, export/declare/readonly/local, compound/element/append, arithmetic, printf -v, read, comsub isolation and the modernish isset -x alias-handler shape. All expectations probed on the GNU 5.3.20 oracle with a clean environment before this commit.
GNU keeps POSIX mode derived from the variable: variables.c:5820 registers sv_strict_posix for POSIXLY_CORRECT, and variables.c:6257-6266 (sv_strict_posix) recomputes posixly_correct = var && var_isset(var) on every bind, then runs posix_initialize (general.c:103-128) + set_shellopts. rubash only flipped the mode from set -o posix (builtins/set.def:406-411 set_posix_mode) and from the startup environment scan, so a runtime assignment was invisible to the mode's consumers — observably, export -p kept printing the declare form instead of the POSIX form (builtins/setattr.def:504-510). Mechanism fix, by bind-funnel category rather than per-shape: - builtins/set/options.rs: split apply_posix_mode_transition into the set -o path (bind/unbind the variable, then walk) and a new sync_posix_mode_from_variable that only re-derives: it refreshes the __RUBASH_SETOPT_posix flag + SHELLOPTS and runs the same posix_initialize walk, never writing the variable itself (an empty value stays set-but-empty, as on GNU). - Hooks at every funnel that can bind or unbind the variable: plain/append/element statement assignments (temporary_assignments funnel + both command_prepare element sites), temporary-prefix restore (restore_temporary_assignments, BASH_COMPAT-shaped), function-local frame pop (restore_function_locals), unset, declare/local/export/readonly operand tails, arithmetic stores, and printf -v. - Written-text keying where GNU keys on the written text: the arithmetic hook fires only for a scalar lvalue spelled exactly POSIXLY_CORRECT (expr.c:352 expr_bind_variable passes the lhs verbatim to stupidly_hack_special_variables), and printf -v only for the bare operand (builtins/printf.def:112-113) — element spellings match no special variable and do not flip the mode. Statement element binds and declare/local element operands do flip: those routes reach the hook with the bare variable name (variables.c:5314, builtins/declare.def:1105). - Temporary prefixes on special builtins keep GNU's promotion (variables.c:4485-4525 push_posix_temp_var/merge_temporary_env): the tempenv path already promotes; the restore hook re-derives from the promoted state. Refs #3661
All four corrections re-probed on the GNU bash 5.3.20 oracle with a clean environment: - set_plus_o_posix_unbinds: `declare -p POSIXLY_CORRECT` after set +o posix prints `declare: POSIXLY_CORRECT: not found` on stderr with status 1, not a DECLARE line on stdout with status 0. - temp-prefix restore cell: a prefix on the special builtin export is promoted by GNU (variables.c:4485-4525 merge_temporary_env), so the restore shape now uses `command export -p` (regular builtin); the promotion itself is nailed in the new cell temp_prefix_special_builtin_persists (21 cells total). - arith_element_assign / printf_v_element_assign: expected DECLARE, not POSIX — GNU keys the post-bind hook on the written lhs/operand text (expr.c:352, builtins/printf.def:112-113), so an element spelling matches no special variable. Refs #3661
346a95a to
5e816ac
Compare
…after unset HISTTIMEFORMAT stay armed Refs #3535 ## 根因 GNU 的 `history_comment_char` 武装是粘性的:`variables.c:6168-6177 sv_histtimefmt` 在 HISTTIMEFORMAT 存在时把 `history_comment_char` 置 `'#'`(仅当其为 0),unset 时只清 `history_write_timestamps`,从不复位注释符。rubash 把武装建模为「HISTTIMEFORMAT 当前存在」(各 history 读取面采样 `get_env("HISTTIMEFORMAT").is_some()` 同时充当 write-timestamps 与 comment-char 武装),于是置过又撤掉之后,`history -r` 把 `#<epoch>` 行当普通条目读入、条目带空戳,列表渲染为 `??` 三行,与 GNU 的两行带戳不符。 已合入的 #3537(#3393)只建模了同样粘性的 `history_multiline_entries`,未动注释符武装——本 PR 补这一面。 ## 修法(机制,非个案) - `ShellState` 新增粘性闩 `history_comment_char_armed`(readline `history_comment_char` 进程全局的移植,随 Clone fork 边界传递);`Executor::new` 以进程环境导入的 HISTTIMEFORMAT 播种(GNU 对环境导入变量同样跑 sv_histtimefmt)。 - 赋值面闩定:`execute_command` 每命令边界在 HISTTIMEFORMAT 存在时闩定;临时(前缀)绑定在 `apply_temporary_assignments` 内闩定(其恢复先于命令边界,GNU 探针证实 `HISTTIMEFORMAT='[%Y] ' true` 同样粘性武装)。 - `SessionHistory` 读取面把两个 GNU 状态拆开传参:`comment_char_armed`(粘性,管 `#<digit>` 识别与读时戳,histfile.c:375-383 + history.c hist_inittime)与 `timestamps_armed`(现值 = history_write_timestamps,仅继续管 multiline 重组门,histfile.c:384——粘性不放宽该门,钉 multigate 格守此界)。 ## GNU 锚点 - `variables.c:6168-6177` sv_histtimefmt(武装粘性本体) - `lib/readline/histfile.c:375-383` + `:466`(文件首行戳仅借用本读、读毕复位——不闩定) - `lib/readline/history.c:322-333` hist_inittime(条目戳首字 = 当前 comment char) - `lib/readline/histfile.c:384`(multiline 门 = history_write_timestamps 现值) 期望值全部以 GNU bash 5.3.20 脚本文件实测(repro / 从未武装对照 / 前缀绑定 / 空值绑定 / `history -n` 面 / multiline 门,共 6 形)。 ## 回归钉 `tests/issue3535_history_comment_char_sticky.rs`(6 格):武装后撤除的 `-r` 形、从未武装对照组、前缀绑定、空值绑定、`-n` 面、multiline 门不放宽。 ## 本 PR 删除了什么 无删除。纯增性改动:新增一个 ShellState 布尔闩与其播种/闩定点、读取面签名增加一个参数(仓内 5 个调用点同步更新)、新增钉文件。`src/script_driver.rs`、`src/executor/init.rs` 的改动仅为上述闩的播种与调用点传参。 ## Captain verification (merge round R5, head 84a58c5, base 78060e4) - Pin `issue3535_history_comment_char_sticky`: 6/6 green on the merged shape (fail-first banked at delivery: 4 red / 2 green on base). - Neighbors: issue3393 8/8, issue1669 2/2, both aligned with base. - `RUSTFLAGS="-D warnings" cargo check --locked --lib --bins`: rc=0, zero warnings. `rustfmt --check` on all 9 changed files: rc=0. - Full lib bilateral (head vs base 78060e4, bin-first): 1249/0/4 both sides, failure name-set diff empty. - CI on the R5 head (run 43729056059, head == 84a58c5): 3 failing jobs (Rust tests, Rust tests (macOS), GNU regression goldens and canaries), each failing ONLY on the issue2875 baseline cell (`api::consumer_tests::issue2875_input_procsub_child_runs_as_rubash_shell`); niu-canary success. PASS comment 6894417642 stands. - Intersection (merge-base eaa357f..78060e4 vs the PR's 9 files): exactly 2 files, both released by the captain after personally reading both sides' hunks — `src/executor/command_execute.rs` (tip #3686 @@ -468 and #3690 @@ -600, both in `execute_command_with_procsub_scope`, vs PR @@ -30 in `execute_command`; ~438 / ~570 lines apart, different functions, no text overlap) and `src/executor/temporary_assignments.rs` (tip #3669 @@ -1482 in `apply_shell_assignment` vs PR @@ -186 in `apply_temporary_assignments`; ~1296 lines apart, different functions, no text overlap). Rebase onto 78060e4 was clean, zero conflicts; the rebased diff is byte-identical to the R4 shape except the two base-blob index lines. Tip unmoved after all legs. Refs #3535 (the issue stays open until the captain hand-closes it on this merge).
Summary
Fix for rubash#3661:
POSIXLY_CORRECTassigned at runtime now re-derives POSIX mode, like GNU. The branch carries the original fail-first nails (fe879b3), the mechanism fix (608c4ec), and oracle-verified nail corrections (9950cf9).Root cause
GNU derives POSIX mode from the variable on every bind:
variables.c:5820registerssv_strict_posixforPOSIXLY_CORRECT, andvariables.c:6257-6266recomputesposixly_correct = var && var_isset (var), then runsposix_initialize()(general.c:103-128) +set_shellopts(). rubash only flipped the mode fromset -o posix(builtins/set.def:406-411path) and from the startup environment scan, so a runtime assignment was invisible to the mode's consumers — observably,export -pkept printing thedeclare -xform instead of the POSIX form (builtins/setattr.def:504-510), and the modernishisset -xgate in the #2902 close-out chain died on it.Fix (mechanism, by bind-funnel category)
src/builtins/set/options.rs:apply_posix_mode_transitionis split into theset -opath (bind/unbind the variable, then walk) and a newsync_posix_mode_from_variablethat only re-derives — it refreshes the__RUBASH_SETOPT_posixflag +SHELLOPTSand runs the sameposix_initializewalk, never writing the variable itself (an empty value stays set-but-empty, as on GNU).restore_temporary_assignments), function-local frame pop,unset,declare/local/export/readonlyoperand tails, arithmetic stores, andprintf -v.POSIXLY_CORRECT(expr.c:352passes the lhs verbatim tostupidly_hack_special_variables), andprintf -vonly for the bare operand (builtins/printf.def:112-113) — element spellings match no special variable and do not flip. Statement element binds anddeclare/localelement operands do flip: those routes reach the hook with the bare variable name (variables.c:5314,builtins/declare.def:1105).variables.c:4485-4525push_posix_temp_var/merge_temporary_env); the restore hook re-derives from the promoted state.Nail corrections (4 cells, all re-probed on the GNU 5.3.20 oracle, env -i)
set_plus_o_posix_unbinds: GNU printsdeclare: POSIXLY_CORRECT: not foundon stderr with status 1 afterset +o posix, not a DECLARE line on stdout with status 0.command export -p(regular builtin): a prefix on the special builtinexportis promoted by GNU instead of restored; the promotion is nailed separately in the new celltemp_prefix_special_builtin_persists(21 cells total).arith_element_assign/printf_v_element_assignexpect DECLARE, not POSIX (written-text keying above).Legs (captain re-verification welcome; all run locally under the single build slot, -j 1)
set -opath).export -pform +SHELLOPTS+set -oreport, incl. declare/export/readonly/read/arith/printf element spellings, temp prefixes, comsub isolation, controls): 25/25 SAME, 0 DIFF.test result: ok(posix/shopt, assignment chains, temp-env, local/declare, readonly, arith cache, printf -v, unset, export filters); the 4 arith/printf stems re-run after the written-text narrowing, all ok.RUSTFLAGS="-D warnings" cargo check: rc=0, zero warnings.scripts/check-utf8-boundary-hygiene.sh: clean. All touched files rustfmt-clean (two pre-existing base drifts —src/main.rs,tests/issue3353_...— were left untouched).本 PR 删除了什么
No product code or files are deleted. The fix commit is +194/−3 across 12 source files (the −3 is the refactored transition body in
options.rs). The nail-correction commit rewrites the expectations of 4 existing nail cells and the file header's probe summary, per the oracle evidence above; no nail cell was removed (one was added:temp_prefix_special_builtin_persists).Known accepted gaps (documented in the lane report)
++/op=on an already-typed variable) do not fire the hook; they cannot create the variable from unset (an unbound name takes the slow path), and an existing value stays isset, so the mode cannot diverge there.mapfile POSIXLY_CORRECTdoes not flip on GNU either (oracle-verified) — no hook, matching GNU.local POSIXLY_CORRECTcreation edge is not hooked.Refs #3661
UNVERIFIED-BY-CAPTAIN