Skip to content

fix(xtrace): complete G16 - single raw (( )) trace, for/case heads, assignment prefix - #107

Merged
caomengxuan666 merged 3 commits into
masterfrom
feat/gnu-compat-batch1
Sep 16, 2026
Merged

caomengxuan666 merged 3 commits into
masterfrom
feat/gnu-compat-batch1

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Closes two xtrace sub-gaps of tests/gnu-compat/GAPS.md G16, verified byte-identical against WSL /usr/local/bin/bash 5.3.0(1).

(( )) 双打印 + 格式(565ba986)

set -x 下 (( n )) 之前打两行(通用站点 + arith 专点各一次),且格式与 GNU 不符。GNU 只打一行并保留括号间原文:+ (( n ))(execute_cmd.c:3940,通用 simple-command trace 对算术命令不生效)。

  • 通用 xtrace 站点跳过算术命令节点(command_dispatch / command_prepare)
  • 新增 xtrace_print_arith_cmd_raw(不 trim_start)给普通 (( )) 路径;for ((...)) 的 init/test/update 继续用 trim 变体(本就逐字节正确)

for/case 头与赋值前缀(79aac755)

  • for 头每迭代一行(execute_cmd.c:3062 → print_cmd.c:609):for i in 0 1 2 每次迭代打 + for i in 0 1 2;for i; 隐式形式打字面 + for i in "$@"
  • case 头一行(execute_cmd.c:3679 → print_cmd.c:742):pattern 展开前打 + case abc in
  • 赋值前缀独立成行:foo=one echo hi → + foo=one + + echo hi(GNU 分两行,rubash 之前拼一行)

验证

  • WSL 5.3.0(1) A/B:普通 (( )) / let / for ((...)) / plain for / for i; / case / 赋值前缀全部逐字节一致
  • 上游 set-x.tests:修复前 rubash 缺 9 行 for/case/赋值追踪;修复后剩余差异只剩 BASH_XTRACEFD 与 xtrace 词引用两个独立子 gap(已记入 GAPS.md)
  • cargo test --lib 397 passed;hygiene check clean;全量 83 套件 check 无回归(varenv 的 ±2 行为本身非确定,master 同)

附带:GAPS.md 复核记录(8811ce2c)

本轮双端探针复核发现 ledger 多条已过时(G8①/G13/G9/G10/G23/G1 均已在近期提交中修好),已更新;同时记入新发现的 varenv 非确定问题。

🤖 Generated with WorkBuddy

`set -x` traced `(( n ))` twice: once through the generic simple-command
site (words join prints the normalized `(( n ))`) and once through
execute_arithmetic_command (trim_start prints `(( n  ))`). GNU traces it
exactly once, with the verbatim between-parens text on both sides:
`+ ((  n  ))` (execute_cmd.c:3940 passes the word to xtrace_print_arith_cmd
without normalization; the generic execute_cmd.c:4480 simple-command trace
never fires for arithmetic commands).

- executor/command_dispatch.rs + command_prepare.rs: skip the generic
  xtrace for arithmetic command nodes (execute_arithmetic_command owns it)
- executor/prompt_expansion.rs: add xtrace_print_arith_cmd_raw (no
  trim_start) for the plain-command path; the arith-for init/test/update
  paths keep the trimming variant, which already matches GNU byte-for-byte
  (`for (( i=0; i<2; i++ ))` traces `+ (( i=0 ))`, `+ (( i<2 ))`,
  `+ (( i++  ))`)

Verified: upstream third_party/bash/tests set-x.tests now matches
set-x.right 72/72 (CRLF-normalized); targeted A/B against WSL
/usr/local/bin/bash 5.3.0(1) byte-identical for plain (( )), let, and
arith-for forms; cargo test --lib 397 passed.

🤖 Generated with [WorkBuddy](https://workbuddy.cn)
…ollow-up)

GNU traces three more shapes that rubash's `set -x` missed on LF scripts:

- for head, once per iteration (execute_cmd.c:3062 ->
  xtrace_print_for_command_head, print_cmd.c:609): `for i in 0 1 2` traces
  `+ for i in 0 1 2` before each body run; the implicit `for i;` form
  traces the literal `+ for i in "$@"` (map_list keeps the unexpanded "$@").
- case head, once before pattern expansion (execute_cmd.c:3679 ->
  xtrace_print_case_command_head, print_cmd.c:742): `case abc in`.
- assignment prefix on its own line (execute_simple_command trace):
  `foo=one echo hi` traces `+ foo=one` then `+ echo hi`, not one joined
  line.

Implemented via xtrace_print_for_command_head emission in the iteration
loop (loop_select.rs), a head trace in execute_case_command
(compound_exec.rs), and an xtrace_assignment_text split at both generic
trace sites (command_dispatch.rs / command_prepare.rs, helper in
prompt_expansion.rs).

Verified byte-identical against WSL /usr/local/bin/bash 5.3.0(1) for
plain for / `for i;` / case / assignment-prefix forms; cargo test --lib
397 passed; upstream set-x.tests diff shrank from 39 to 13 lines (the
rest is the BASH_XTRACEFD and xtrace word-quoting gaps, tracked
separately in tests/gnu-compat/GAPS.md).

🤖 Generated with [WorkBuddy](https://workbuddy.cn)
@caomengxuan666
caomengxuan666 merged commit 951fe49 into master Sep 16, 2026
3 checks passed
@caomengxuan666
caomengxuan666 deleted the feat/gnu-compat-batch1 branch September 16, 2026 03:47
caomengxuan666 added a commit that referenced this pull request Sep 16, 2026
fix: niubash #106/#107/#108 regressions + restore #103 array fix lost in rescue merge
caomengxuan666 added a commit that referenced this pull request Sep 16, 2026
…as-char sites

- README/README.zh-CN: new "Fixed today" section covering niubash #106 (CRLF
  line-terminator handling), #107 (-c GNU first-non-option-argument), #108
  (type output capture), plus the nameref/history convergence and the
  debug-instrumentation cleanup from the local batch landing.
- check-utf8-boundary-hygiene: extend the execution_misc.rs allowlist entry
  with the two reviewed byte->char widening patterns introduced by the batch:
  `out.push(byte as char)` under the 0x20..=0x7e printable-ASCII arm and the
  octal digit math `b'0' + ((byte >> n) & 0o7)` (always 0x30..0x37) — both can
  never involve a UTF-8 continuation byte.
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