Skip to content

fix(prompt,executor): #813 CR followups — ${var@P} comsub status bracket (parse.y:6684-6697), sudo no-handler route pins, prompt-render benchmark - #854

Merged
caomengxuan666 merged 2 commits into
masterfrom
fix/813
Oct 19, 2026

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Closes #813 — the five-item follow-up package from the #810 (#759/#757) CR findings.

五项逐项状态

1. ${PS1@P} 通道泄漏命令替换状态 — 已修(语义修)

GNU 律(vendored 5.3 实锚):decode_prompt_string 在 promptvars 遍历前后快照/恢复 last_command_exit_value 与 last_command_subst_status(parse.y:6684-6697,expand_prompt_string 在 :6689);subst.c string_transform 'P' 走同一 decode_prompt_string,${var@P} 同受覆盖。与 #604 的关系:#604 修的是交互渲染通道(expand_prompt_string_mut 快照恢复 rc/PIPESTATUS,PR #605),本票是 @P operator 路径——遍历引擎的 comsub 边界把 $( ) 体收割状态写进替换状态 cell,赋值边界把它当替换退出规则发布。

落点:共享 prompt 遍历引擎 expand_embedded_parameters_double_quoted(它的两个 caller 都是 prompt 通道:@P 变换 + 管道 -i 渲染)把 cell 恢复到遍历前值(保真恢复而非清零),外加 expand_prompt_string_mut 的同款 cell 括号(parse.y:6687/:6697 连 last_command_subst_status 一起恢复)。保真性:w=$(false)${PS1@P} 的词自身替换状态照常发布(GNU rc=1,两侧一致)。

GNU 差分(WSL GNU Bash 5.3.0 stdin,2026-10-19):

形态 GNU rubash 修复前 rubash 修复后
true; PS1='x$(false)y'; p=${PS1@P}; echo $? 0,p=[xy] 1 0,p=[xy]
false; q=${PS1@P}; echo $? 0 1 0
PS1='r$(true)'; w=$(false)${PS1@P}; echo $? 1,w=[r] 1 1,w=[r]
q2=$(false); echo $?(对照) 1 1 1

回归:tests/issue813_prompt_transform_status_regressions.rs(3 例)。GPL 红线:无 GPL 文本,parse.y 只引语义坐标。

2. sudo 无 handler 执行路由两臂测试钉 — 已钉(纯测试,windows-only)

CR F4 的两臂(lookup_paths.rs routes_as_builtin = windows+handler 门):

  • sudo_without_handler_executes_the_path_command:假 sudo.cmd 上 PATH 实跑(marker 输出 + rc 0 透传),"elevation handler" 诊断不复现;
  • builtin_sudo_without_handler_reports_not_a_shell_builtin:builtin: sudo: not a shell builtin,rc 1(GNU 措辞)。

3. prompt 渲染基准条目 — 已补

benchmarks/30-prompt-render-transform-x5000.sh(#607-#609 同款 PERF 元数据方法学):无 spawn 的主题形 PS1(prompt escapes + 参数/算术/裸特殊参数内容)5000 次 ${PS1@P} 渲染,钉 CR 实测的 ~50µs/次引擎预算。本地双引擎实跑(scripts/run-perf-suite.sh,runs=3):rubash 539ms vs WSL GNU 75ms 中位(~7.2x,10x 告警线内)。

4. command_execute.rs 冗余析取 — 已清(CR F7)

heredoc-fatal 分类里的 is_shell_builtin_name(&expanded) || 删除——两个平台的 routes_as_builtin 均以纯表开头,完全覆盖。

5. CHANGELOG — 已补

新增 ### 变更 节披露 Windows 无宿主 sudo 行为变化(#810:"elevation handler is not configured" rc 1 → PATH 实跑/127;introspection 契约不变),外加第 1 项的 ### 修复 条目。

验证三行

  1. WSL oracle:x=${PS1@P} 类形态(PS1 内嵌 $(false))GNU $?=0;修复后 rubash 三形态(干净/前置失败/混合 RHS)逐一对齐;[perf][P1] $(...) inside PS1 renders ~100x slower than the same call in PROMPT_COMMAND - four oh-my-bash themes hit 10x rr budget on CI #604 面回归 4/4 绿(issue604),prompt 家族 42/42 绿(393/421/431/433/757/pb10k)。
  2. 全量双向对比:cargo test --no-fail-fast -- --test-threads=1,branch 失败集 34 == 干净 origin/master(b79e678a)基线失败集 34,按用例名 1:1 双向 comm 为空;merge 最新 master(fff4adaf,build(package): exclude target-variant dirs from the crate — guard against >10MiB upload rejection #851 仅 .gitignore/Cargo.toml)后重跑 35,唯一新增为文档化的 executor::path listing-cache flake(重跑即绿)。
  3. fmt / -D warnings / 基准:cargo fmt --check 0 diff;RUSTFLAGS="-D warnings" cargo check(lib+bins)0 error;基准条目双引擎本地可跑(见第 3 项数据)。

…atus bracket, sudo no-handler route pins, prompt-render benchmark

#813 items from the #810 (#759/#757) CR findings:

1. ${var@P} prompt-transform channel no longer leaks command-substitution
   status into $? (CR F3). GNU parse.y:6684-6697 snapshots/restores
   last_command_exit_value + last_command_subst_status around the promptvars
   pass (parse.y:6689) inside decode_prompt_string; subst.c string_transform
   'P' routes through the same function, so ${PS1@P} is covered. rubash#604
   fixed the interactive render channel (expand_prompt_string_mut rc/PIPESTATUS
   bracket); the operator path published the embedded $( ) body's reaped
   status through the comsub-status cell the assignment boundary reads.
   Fix lands in the shared prompt-pass engine (expand_embedded_parameters_
   double_quoted — both its callers are prompt channels: the @p transform and
   the piped -i render) restoring the cell to its PRE-pass value, plus the
   same cell bracket in expand_prompt_string_mut (parse.y:6687/:6697 restores
   last_command_subst_status with the exit value). Restore is value-preserving,
   not clearing: w=$(false)${PS1@P} keeps rc 1 like GNU.
   WSL GNU 5.3.0 probes: true; p=${PS1@P} -> rc 0 p=[xy] (was 1);
   false; q=${PS1@P} -> rc 0; mixed RHS -> rc 1. Regression:
   tests/issue813_prompt_transform_status_regressions.rs (3).

2. sudo no-handler execution-route pins (CR F4), windows-only:
   sudo_without_handler_executes_the_path_command (fake sudo.cmd on PATH
   actually runs, rc 0) and builtin_sudo_without_handler_reports_not_a_
   shell_builtin (GNU wording, rc 1). tests/regression.rs.

3. benchmarks/30-prompt-render-transform-x5000.sh (CR F6): 5000 ${PS1@P}
   renders of a spawn-free theme-shaped PS1 pinning the ~50us/render
   engine budget; runs OK under scripts/run-perf-suite.sh on both engines
   (rubash 539ms vs WSL GNU 75ms median, runs=3).

4. command_execute.rs heredoc-fatal classification drops the is_shell_
   builtin_name disjunct — fully subsumed by routes_as_builtin on both
   platforms (CR F7).

5. CHANGELOG: new 变更 section disclosing the Windows no-host sudo
   behavior change (#810: 'elevation handler is not configured' rc 1 ->
   PATH/127), plus the 修复 entry for item 1.

Gate: cargo fmt --check clean; RUSTFLAGS='-D warnings' cargo check clean;
full --test-threads=1 --no-fail-fast failure set identical 1:1 to a clean
origin/master (b79e678) build (34 == 34); merged tree rerun 35 with only
the documented flaky executor::path listing-cache lib test, green on rerun;
issue604/757/393/421/431/433/pb10k suites all green.
@caomengxuan666

caomengxuan666 commented Oct 19, 2026 •

Copy link
Copy Markdown
Member Author

独立代码评审:APPROVE-WITH-NITS

评审树:自建 detached worktree @ 802257c(base fff4ada 实为 merge-base,已核实单 commit)。全部验证实做,逐点如下。

五项主张逐条核实

1. ${PS1@P} 状态泄漏修复面(F3)— 核实成立

  • 引擎 expand_embedded_parameters_double_quoted 的生产 caller 恰好两个,均为 prompt 通道:@p 变换臂(parameter_transforms.rs:427)与管道 -i 渲染(public_accessors.rs:46 ← script_driver.rs:3227,唯一渲染点)。括号放引擎内不伤及非 prompt 语义。mut 通道(expand_prompt_string_mut)自带 cell 括号,与 fix(prompt): PS1/PS0 渲染保持读者的 $/PIPESTATUS;#604 profile 数据进 PR (closes #604) #605 结构一致(注:该函数目前无生产 caller,括号仅测试可达,无害)。
  • 无双重恢复/漏恢复:两处括号均为 save/restore 前值对,嵌套可组合;decode_prompt_string 为纯转义解码(\$ 仅渲染 $/#),自身不执行 $(),@p 的替换执行全部落在括号内。深度守卫早退路径(embedded_parameters.rs:122)在括号之前,无泄漏。
  • GNU 引文核实:vendored parse.y 6686-6697 确为快照/恢复 last_command_exit_value(:6687→6695)、last_command_subst_pid、last_command_subst_status(:6689→6697)+lastarg,行号引用准确。
  • 保真恢复语义(核心):WSL GNU 5.3.0(1) oracle 与修复后 rubash 逐形双向对齐——true; p=${PS1@P}→rc=0 p=[xy](双端一致);false; q=${PS1@P}→rc=0(一致);w=$(false)${PS1@P}→rc=1(一致,证明恢复取遍历前值而非清零);加测「PS1 内嵌两次替换、第二次失败」a$(true)b$(false)c→rc=0 r=[abc](一致);$(exit 5)→rc 0(一致);x=$(p=${PS1@P})→rc 0(一致)。基线二进制实测 pre-fix 复现:true; p=${PS1@P} 在 fff4ada 上 rc=1 p=[xy]——bug 实存、修复真实生效。
  • 溢出面核实:@Q/@E/@A/@a/@K/@k(及 U/u/L)在 apply_parameter_transform(parameter_replace.rs:524)全为纯文本变换,不进引擎、不执行 $(),无同族泄漏面;@p 是唯一走引擎的变换,修复面充分。
  • lastarg 面:GNU 对 last_lastarg 同样恢复;实测 $_ 两形双端逐字节一致,无分歧。

2. sudo 两臂测试钉(F4)— 核实成立

  • PATH 注入只在子进程脚本内 export PATH='<bindir>':"$PATH",run_rubash_in 本身 env_clear + minimal_path(System32),对同机其他测试零污染;假 sudo.cmd 前置必胜宿主 sudo.exe,builtin sudo 臂不咨询 PATH、与宿主无关,两臂均确定性。
  • #[cfg(windows)] 门正确(elevation 机制全程 cfg(windows));.cmd 假 shim 是套件既有惯例(executor_tests、issue370 等)。本机 3 例 sudo 测试全绿(含预存 sudo_is_not_reported_as_a_builtin)。

3. 基准(F6)— 核实可跑、口径一致

4. 冗余析取清理(F7)— 核实行为中性

  • routes_as_builtin 两个 cfg 臂(lookup_paths.rs:94/:102)均已蕴含 is_shell_builtin_name(windows 臂 = 纯表 ∨ (sudo∧handler);非 windows 臂 = 纯表),被删析取完全被蕴含。

5. CHANGELOG — 核实无遗漏:新增「变更」节披露 #810 无宿主 sudo 行为变化(rc 1 → PATH/127、builtin sudo rc 1),与实现一致;「修复」条目机制描述与本 diff 一致。

门禁复核(本机实测)

  • cargo fmt --check 干净;RUSTFLAGS="-D warnings" cargo check 干净。
  • 全量双向:PR 树 vs 干净 fff4ada 基线,--test-threads=1 --no-fail-fast,失败集 35 == 35;唯一名字互换两侧各为 rerun-绿 flake(基线侧 fixture_text_tree_matches_normalized_output、PR 侧 fractional_timeout_expires_with_142,各自单测复跑均 ok)——失败集语义恒等。
  • [perf][P1] $(...) inside PS1 renders ~100x slower than the same call in PROMPT_COMMAND - four oh-my-bash themes hit 10x rr budget on CI #604 回归 4/4;prompt 家族全绿(604/757/393/421/431/433/pb10k/813/parameter_transform 共 56 例);新 issue813 3/3。
  • 夹带扫描:7 文件恰为五项所列,无夹带。评审全程未动他人 worktree、未 stash、无进程击杀。

非阻塞备注(NIT / 建议跟进票)

  1. 同族残留面(建议另开票,非本 PR 义务):本修复恢复的是替换状态 cell(GNU last_command_subst_status 的 rubash 对应物),但 word_expansion_comsub_exit overlay(GNU 恢复的 last_command_exit_value 在词内 $? 读侧的对应物,command_substitution.rs:636 由内嵌替换写入)未随括号恢复——引文律覆盖两个状态字,此处相对引文不完整。实测两形分歧(master 上 pre-existing,非本 PR 引入):
  2. 基准台账建议把比率记为不变量(绝对数机器敏感,本机与主张相差 ~3x 但比率稳定)。
  3. expand_prompt_string_mut 现无生产 caller(仅 tests.rs:359);mut 通道括号目前只有测试可达——与 fix(prompt): PS1/PS0 渲染保持读者的 $/PIPESTATUS;#604 profile 数据进 PR (closes #604) #605 结构一致,记录备查。

结论:APPROVE-WITH-NITS。 五项全部核实成立,门禁全过,无 BLOCKER。

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.

prompt/ expansion followups from #810 CR: comsub status leak in ${PS1@P}, no-handler sudo execution route untested, missing prompt benchmark entry

1 participant