Skip to content

fix(read): re-tag carrier bytes on the C-locale byte-domain write-back (Refs #3489) - #3547

Merged
caomengxuan666 merged 2 commits into
masterfrom
fix/3489-read-byte-domain-carrier
Nov 15, 2026
Merged

caomengxuan666 merged 2 commits into
masterfrom
fix/3489-read-byte-domain-carrier

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Refs #3489

修了什么

read 内置在单字节 locale(LC_ALL=C;bats 在 env -i 下跑 formatter)的字节域回写把已打标的载体字节还原成裸字节入库:

  • 记录进入时 tag_read_carrier_text(read_helpers.rs)把 ASCII 载体字节(0x0c、0x11、0x13、0x14..=0x1f,含 ESC)打成 E000 标记对;标记对是非 ASCII,于是 read_byte_domain(read_split.rs,[bug] C locale 下多字节 IFS 字符按整字符拆分(GNU 按字节拆分) #2819)在 C locale 下走字节域。
  • 字节域字段回写 byte_domain_value 把每个 < 0x80 的字节当裸字符输出 → 标记被撤销,载体消费者随后吃掉这些字节:ESC 不再匹配 $'\e' 模式(junit formatter 的 xml_escape CSI 剥离循环失效,[0m/[K 残留),0x14 变 \,0x1f 变 $,0x11/0x13 消失(formatter failure 体里 ^M\\&#39;&#39;"\$stop` 的来源)。

修法:byte_domain_value 改为 bytes_to_shell_text(&shell_text_to_raw_bytes(text))——存储域的标准逆映射(UTF-8 重组、游离高字节保持标记、ASCII 载体重新打标,与 tag_read_carrier_text / $'...' 同一口径)。单变量、多变量拆分、read -a 三条路共用此回写,一处修。

删了什么

byte_domain_value 的手写 UTF-8 首字节分类循环(33 行)——它是 bytes_to_shell_text 的不完整复刻(缺载体重标、缺标记区字符转义)。

另:第二个提交只对 tests/d11_pipeline_squote_carrier_regressions.rs 做 rustfmt(#3511 落地的格式漂移让 master 上 cargo fmt --check 失败,pre-commit hook 与 CI fmt 都会红;#3531 带了同样的改动,两边相同 hunk 合并无冲突)。

GNU 依据

  • builtins/read.def:838-845:读入时对 CTLESC/CTLNUL 加 CTLESC 转义;read.def:1127(单变量)/ read.def:1061(拆分字段)dequote_string 撤销 → 绑定值与输入字节逐字节相同,与 locale 无关。字节值 0x1b 等不是 GNU 的 CTLESC/CTLNUL,本就不变。

验证

GNU 5.3.20(WSL /usr/local/bin/bash,脚本文件)对照:

  • 直跑 bats-core bats-format-junit(pre15-bats 副本)喂 GNU 生成的 xml-escape.bats 扩展 TAP 流,env -i、归一化 time/timestamp:修后 rubash 输出与 GNU 逐字节相同(含 ^Mstop</failure> 与三处 CSI 剥离);修前即 issue 所述残留。
  • 新钉 tests/issue3489_read_byte_domain_carriers.rs(4 例,期望值取自 GNU 5.3.20 实测):
  • 同族茎(修后):issue2819_c_locale_multibyte_ifs 9/9、issue277_read_carrier_domain_regressions 7/7、issue2662_read_high_byte_delimiter 12/12、issue1713_read_empty_ifs_regressions 7/7、issue1716_read_last_var_delimiter_regressions 5/5、issue1328_read_post_escape_count 4/4、issue1419_read_nul 1/1、a3_f3_read_ifs_backslash 2/2、issue1635_carrier_pair_views_regressions 0/0、issue1842_comsub_herestring_carrier_regressions 0/0(这两个目标在 Windows 下 0 例)、cargo test --lib read_ 8/8。
  • carrier_byte_class_regressions 14/16:user_pua_data_roundtrips_verbatim、user_pua_length_counts_one_char 两例在 未改动的 origin/master 上同样失败(与本改动无关,均不经过 read)。
  • fmt:cargo fmt --check 在 Windows 上因命令行超长(os error 206)无法运行;在 WSL 同树上 cargo fmt --check 干净(含 d11 格式化提交)。

新发现(另立单,不在本 PR 范围)

Owed

  • 完整 bats 套件 junit-formatter.bats 在 rubash 下的端到端复跑(issue 口径:bats-core 52439ebf、env -i、逐文件)未做;本 PR 只验证了 formatter 阶段直跑与 GNU 逐字节一致。端到端复跑确认后可把 Refs 改为 Fixes。
  • Linux/macOS 上未跑钉(仅 Windows)。

caomengxuan666 and others added 2 commits November 14, 2026 12:58
…k (Refs #3489)

read_split.rs byte_domain_value emitted every byte < 0x80 as a bare
char when it turned single-byte-locale fields back into storage text,
undoing tag_read_carrier_text. Under LC_ALL=C (bats runs formatters
under env -i) ESC stopped matching $'\e' patterns, so the junit
formatter's xml_escape CSI strip left [0m/[K behind; 0x14 became `\`,
0x1f `$`, 0x11/0x13 vanished. The write-back now goes through
bytes_to_shell_text, the storage-domain inverse of
shell_text_to_raw_bytes, which re-forms UTF-8 and re-tags carriers.

GNU: builtins/read.def:838-845 escapes CTLESC/CTLNUL and
read.def:1127 / :1061 dequote_string undoes it, so the bound value is
byte-identical to the input in every locale.

Generated with [Devin](https://devin.ai)
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
master fmt drift from #3511 makes `cargo fmt --check` (the pre-commit
hook and CI fmt) fail on every branch; formatting only, no test change.

Generated with [Devin](https://devin.ai)
Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@caomengxuan666

Copy link
Copy Markdown
Member Author

Lead full-ledger review (2026-11-14)

Fresh isolated Windows builds: base 8b48c164, head 275d5cfd; both vendor GNU Bash 5.3.20 at 9c465866.
Ran each unchanged scripts/true-baseline.sh with no suite arguments through WSL /usr/local/bin/bash, with the documented clean environment.
Both drivers exit 0; each helper-parity gate has 24 OK / 2 report-only.

83 suites measured on each side, 58 exact stdout comparisons on each. This is NOT 83/83 passing. After only exact worktree-root normalization, GNU stdout, Rubash stdout, and exit-code pairs are unchanged for all 83 suites between base and head. No newly observed stdout/exit-code regression in this run; no claim about whole-stderr equivalence.

Limitations: builtins times out with Rubash 124 / GNU 0 on BOTH trees; comsub-posix is GNU 0 / Rubash 2 on BOTH. Other matching nonzero exits are listed, not silently counted as passes. Both runs warn that the dedicated sh fixture is absent and /bin/sh falls back to PATH. The env-line count is the existing harness heuristic, not causal attribution.

Complete 83-suite stdout ledger and exit codes
Suite Base diff lines (env) Head diff lines (env) Base GNU/Rubash rc Head GNU/Rubash rc
alias 0 (0) 0 (0) 0/0 0/0
appendop 0 (0) 0 (0) 0/0 0/0
arith 8 (0) 8 (0) 1/1 1/1
arith-for 8 (8) 8 (8) 0/0 0/0
array 10 (0) 10 (0) 1/1 1/1
assoc 0 (0) 0 (0) 0/0 0/0
attr 0 (0) 0 (0) 0/0 0/0
braces 0 (0) 0 (0) 0/0 0/0
builtins 159 (0) 159 (0) 0/124 0/124
case 0 (0) 0 (0) 0/0 0/0
casemod 0 (0) 0 (0) 0/0 0/0
complete 3 (0) 3 (0) 2/2 2/2
comsub 2 (0) 2 (0) 0/0 0/0
comsub-eof 0 (0) 0 (0) 0/0 0/0
comsub-posix 56 (0) 56 (0) 0/2 0/2
comsub2 0 (0) 0 (0) 0/0 0/0
cond 0 (0) 0 (0) 0/0 0/0
coproc 4 (0) 4 (0) 0/0 0/0
cprint 0 (0) 0 (0) 0/0 0/0
dbg-support 0 (0) 0 (0) 0/0 0/0
dbg-support2 0 (0) 0 (0) 0/0 0/0
dstack 0 (0) 0 (0) 0/0 0/0
dstack2 0 (0) 0 (0) 0/0 0/0
dynvar 0 (0) 0 (0) 0/0 0/0
errors 2 (0) 2 (0) 0/0 0/0
exp 8 (0) 8 (0) 0/0 0/0
exportfunc 0 (0) 0 (0) 0/0 0/0
extglob 0 (0) 0 (0) 0/0 0/0
extglob2 0 (0) 0 (0) 0/0 0/0
extglob3 0 (0) 0 (0) 0/0 0/0
func 0 (0) 0 (0) 0/0 0/0
getopts 0 (0) 0 (0) 0/0 0/0
glob 62 (0) 62 (0) 0/0 0/0
glob-bracket 0 (0) 0 (0) 2/2 2/2
globstar 8 (0) 8 (0) 0/0 0/0
heredoc 0 (0) 0 (0) 0/0 0/0
herestr 0 (0) 0 (0) 0/0 0/0
histexp 0 (0) 0 (0) 0/0 0/0
history 27 (0) 27 (0) 0/0 0/0
ifs 0 (0) 0 (0) 0/0 0/0
ifs-posix 0 (0) 0 (0) 0/0 0/0
intl 4 (0) 4 (0) 0/0 0/0
invert 0 (0) 0 (0) 0/0 0/0
invocation 0 (0) 0 (0) 0/0 0/0
iquote 0 (0) 0 (0) 0/0 0/0
jobs 2 (0) 2 (0) 1/1 1/1
lastpipe 0 (0) 0 (0) 0/0 0/0
mapfile 0 (0) 0 (0) 0/0 0/0
more-exp 0 (0) 0 (0) 0/0 0/0
nameref 29 (0) 29 (0) 0/0 0/0
new-exp 15 (0) 15 (0) 127/127 127/127
nquote 0 (0) 0 (0) 0/0 0/0
nquote1 0 (0) 0 (0) 0/0 0/0
nquote2 0 (0) 0 (0) 0/0 0/0
nquote3 0 (0) 0 (0) 0/0 0/0
nquote4 0 (0) 0 (0) 0/0 0/0
nquote5 0 (0) 0 (0) 0/0 0/0
parser 2 (0) 2 (0) 0/0 0/0
posix2 0 (0) 0 (0) 1/1 1/1
posixexp 7 (0) 7 (0) 2/2 2/2
posixexp2 6 (0) 6 (0) 0/0 0/0
posixpat 0 (0) 0 (0) 0/0 0/0
posixpipe 0 (0) 0 (0) 0/0 0/0
precedence 0 (0) 0 (0) 0/0 0/0
printf 0 (0) 0 (0) 1/1 1/1
procsub 0 (0) 0 (0) 0/0 0/0
quote 6 (0) 6 (0) 0/0 0/0
quotearray 0 (0) 0 (0) 0/0 0/0
read 4 (0) 4 (0) 0/0 0/0
redir 0 (0) 0 (0) 0/0 0/0
rhs-exp 0 (0) 0 (0) 0/0 0/0
rsh 0 (0) 0 (0) 0/0 0/0
set-e 0 (0) 0 (0) 0/0 0/0
set-x 0 (0) 0 (0) 0/0 0/0
shopt 0 (0) 0 (0) 0/0 0/0
strip 0 (0) 0 (0) 0/0 0/0
test 8 (0) 8 (0) 0/0 0/0
tilde 0 (0) 0 (0) 0/0 0/0
tilde2 0 (0) 0 (0) 0/0 0/0
trap 0 (0) 0 (0) 0/0 0/0
type 10 (0) 10 (0) 0/0 0/0
varenv 16 (0) 16 (0) 0/0 0/0
vredir 0 (0) 0 (0) 0/0 0/0

Raw files are preserved in both V3489-{base,head}/target/issue-suites/results/: review3489/build.*, review3489/baseline.*, helper-parity.log, true-baseline-ledger.log, and true-baseline/<suite>/{gnu,rb}.{out,err,rc}. Local immutable comparison snapshot: backups/2026-11-14-sync/continue-review-20261114/3489-snapshot.json.

Focused pin independently rerun: base 1 passed / 3 failed (rc 101), head 4 passed / 0 failed (rc 0), using exactly cargo test -j 4 --locked --test issue3489_read_byte_domain_carriers with a 300-second bound. The UTF-8 control case already passes on base; the XML escaping, scalar carrier, and split/array carrier cases fail on base and pass on head. Logs: review3489/pin-final.{stdout,stderr,rc}.

An earlier cargo attempt was blocked before test execution by a locked rubash.exe (os error 5); it is preserved separately and is NOT counted as fail-first evidence. Two proven-owned FIFO background-wrapper suite leftovers were inventoried and stopped before the successful pin runs. No user terminal or unrelated process was stopped.

PR remains draft; no merge or issue closure is authorized by this ledger.

caomengxuan666 added a commit that referenced this pull request Nov 14, 2026
…2847) (#3556)

Fixes #2847

## 修了什么

`scripts/check-api-ledger.py` 的 §6 校验从「子树里有同名声明」改为「记录的路径就是真实导出路径」:

- `item rubash::a::b::Name`:从 `src/lib.rs` 起逐段解析,每一段必须是 `pub mod`(内联或文件,含 `#[path]`)或把模块 `pub use` 出来的再导出;末段 `Name` 必须在该模块**顶层**以 `pub` 声明(fn/struct/enum/trait/type/const/static/union/mod),或被该模块 `pub use` 再导出(具名、`as` 改名、glob;glob 目标可以是私有模块,如 `parser` 的 `pub use nodes::*`)。只认裸 `pub`,`pub(crate)` 不算对外面。
- `variant` / `method`:其所属类型路径按同一解析器校验(此前 method 完全不看类型路径)。
- 诊断区分两种失败:`declared in the tree but not exported under rubash::…`(路径错)与 `not found in tree`(符号没了)。
- 源码级近似:先抹掉注释与字符串/字符字面量,再按花括号深度判定「顶层」;不追宏生成的条目(真遇到会大声失败、需人工处理)。
- 自检(`--self-test`)新增一组:真实导出路径(具名/改名/私有模块 glob/`#[path]`/根再导出/子模块路径)必须过;未再导出、穿私有模块、类型路径错的 item/variant/method 必须各自失败。

## 删了什么

`item_exists` 原先的「模块子树 rglob + 声明模式」判定(即 issue 所说的盲区)。`PUB_DECL_PATTERNS` 只保留用于失败诊断(区分「路径错」与「不存在」)。

## 依据

工程面,无 GNU 锚。

## 验证

- issue 复现:取 #2850 之前的树(`4f0d493c~1`,`CandidateKind` 尚未在 `src/api/mod.rs` 再导出):
  - 旧脚本:`all 279 ledger symbols present`,rc=0(假绿)
  - 新脚本:5 条失败(`item rubash::api::CandidateKind` + 4 个 variant,均为 `declared in the tree but not exported under rubash::api::CandidateKind`),rc=1
- 当前 master:`all 287 ledger symbols present`,rc=0;`--niu D:/repo/niubash`:287 present、97 consumed paths recorded,rc=0。
- `--self-test` rc=0(四段自检全部通过)。
- 运行时间与旧脚本持平(约 13.5s,瓶颈仍是原有的 method 全树扫描)。
- 另带一个仅格式化提交:`tests/d11_pipeline_squote_carrier_regressions.rs`(#3511 在 master 留下的 fmt 漂移,pre-commit hook 必红;与 #3531/#3547 中的同一 hunk 相同,合并无冲突)。

## Owed

- `docs/api-ledger.md` §5 第 1 条仍写「proves presence by declaration patterns only」,现已不准确;但该文件要求与 niubash 副本逐字节相同(canary `cmp`),需 rubash/niubash 成对改,本 PR 未动。
- 未在 CI(`niu-canary.yml` 的 `ledger` / `pairing` job)上实跑,仅本地 Windows Python 3 运行。


## 队长复核(合入时)

- 判词 PASS:L1–L8 一手跑过全绿(287/287、--self-test、复现树双向对照旧假绿 279 / 新 5 缺失、--niu 97 consumed、两份账本 sha256 identical)。
- CI run 43560449915:3 fail 逐名 = issue2875 ×2(goldens、macOS)+ issue2859 Linux-only;issue2859 按 #3292 类确认为 VOID(同头 macOS/goldens 该 cell 绿、零 Rust 产品代码、不碰 jobs/sleep 面)。
- 交集 ∅(merge-base 8b48c16 = live tip),无需 update-branch。
- 合入体:接受正文 Fixes #2847,#2847 随合入自动关闭。
@caomengxuan666

Copy link
Copy Markdown
Member Author

【WIN-AGENT-AUDIT】

PR #3547 第1轮 — 建议:PASS
head: 275d5cf base(merge-base): 8b48c16 文件: 3 个
关联 issue: #3489(状态:open,我核过的时间:2026-11-15 本地)

机制核查:

  • byte_domain_value(src/executor/read_split.rs)改调 bytes_to_shell_text——存储域逆函数:有效 UTF-8 重组字符、>=0x80 游离字节保留 raw-byte marker、ASCII 载体字节(0x0c,0x11,0x13,0x14..=0x1f,0x1b)重新打标为 marker pair,正好抵消 tag_read_carrier_text 的入口打标。对应 GNU read.def:838-845(记录内 CTLESC/CTLNUL 转义)+ read.def:1127/:1061 dequote_string——绑定值与输入逐字节一致。修复前 <0x80 字节以裸字符发出,载体被词法器消费者认领(ESC 失配 $'\e'、0x14→\、0x1f→$、0x11/0x13 消失)。
  • 可疑/无关改动:d11 仅 rustfmt。机制为正确逆映射,非黑名单打补丁。

腿:

  • 钉自跑:issue3489_read_byte_domain_carriers head 上 4/4(我自跑与队长复核同值)。
  • fail-first:base 8b48c16 上 1 passed / 3 failed,红名 = {junit_xml_escape_strips_csi_from_read_line_in_c_locale, scalar_read_keeps_carrier_bytes_in_c_locale, split_and_array_read_keep_carrier_bytes_in_c_locale},utf8 守护对照绿——与队长复核(1/3 → 4/4)一致。
  • lib 双边:head {api::consumer_tests::issue2084_session_end_restores_host_process_state} / base 同 / 差集 ∅。队长另已跑 83-suite 全账本双侧(58 精确 stdout 对)无新增回归,原始件留档于 V3489-*/review3489/。
  • -D warnings:errors 全部落在 tests/issue2447_history_bang_first_line.rs 等未改测试文件(unused consts/fns)——不在本 PR diff,基线存量。
  • 卫生:rustfmt --check 三个改动文件全过。
  • CI:3 个红 job 红名单各只有 issue2875_input_procsub_child_runs_as_rubash_shell,全为基线。
  • GNU 对照:WSL /usr/local/bin/bash 5.3.20(1)-release,LC_ALL=C 探针 target/audit-w2/probe3489.sh:标量 read 全载体字节逐位一致(same/len=17)、split 与 read -a 载体保留(pEq|rTs、uEv|wUz)、junit xml_escape 的 CSI 双序列干净剥离([ok 1 x&lt;&gt;&amp; (0x1b)])——rubash head 输出逐字节一致。

F 点:无

未跑/VOID 的腿:无(lib base 集复用同 merge-base 实跑结果;83 账本引用队长已留档证据)。

@caomengxuan666

Copy link
Copy Markdown
Member Author

【WIN-AGENT-AUDIT】勘误(接上证):-D warnings 实际报错文件是 tests/issue2390_for_list_procsub_regressions.rs(unused RUBASH/Outcome/run_script 等),上一条写成 issue2447 系笔误;该文件同样不在本 PR diff,结论不变(基线存量)。

@caomengxuan666
caomengxuan666 marked this pull request as ready for review November 15, 2026 02:04
@caomengxuan666
caomengxuan666 merged commit cf12561 into master Nov 15, 2026
8 of 11 checks passed
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