Skip to content

test(repl): pin empty-line paste byte fidelity; retire the #291 probe's self-failing assertion (closes #291) - #315

Closed
caomengxuan666 wants to merge 1 commit into
masterfrom
fix/291-empty-line-paste-swallow
Closed

caomengxuan666 wants to merge 1 commit into
masterfrom
fix/291-empty-line-paste-swallow

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Closes #291.

结论(TL;DR)

#291 的“最小复现”不成立:1f2180d 的粘贴管线在空行边界没有任何字节丢失。 报告中的探针 zz_minimal_empty_line_paste_probe 连续 5/5 红在同一断言上,而断言本身自相矛盾:

assert!(!screen.contains("cho two"), ...)

"cho two" 是正确渲染 "echo two" 的严格子串——任何一次完全正确的执行都必然包含 "cho two",该断言在任何正确运行上都不可能通过。5 次失败的全部屏幕快照里 echo two 渲染完整、one/two 输出正确、单次 Enter 提交整块。

根因(file:line)

环节 位置 判定
chunk 行切割 / CRLF 折叠 crates/niubash-runtime/src/repl.rs:863-891(translate_event 的 pending 分支:CR 进数据、LF 按 last_bare_cr 配对折叠) 逐字节正确
chunk 打开时的 LF partner 消费 repl.rs:680-731(enter_opens_chunk:首 CR 的 lookahead 消费排队的 LF,CRLF = 一个 \n) 逐字节正确
空行边界(\r\n\r\n → \n\n) 同上两处协同:首个 CRLF 开 chunk,第二个 CR 推 \n、其 LF 被配对折叠 无 off-by-one
探针断言 原 tests/interactive.rs:1708(子串负断言) 复现的唯一“故障”点,本 PR 退役

证明方式:新增 feed_paste_burst()(repl.rs 单元测试)把 owner burst 的精确控制台事件流(含每个 CR 的排队 LF partner、尾随孤立 LF)灌过 PasteChunkEditMode,从翻译后的事件重组出到达 reedline 的文本,断言与输入逐字节相等(CRLF 折叠为 LF)。四种形态全绿。

Owner 症状对照表

Owner 真机(issue 正文/comment 4) 本 PR 在 1f2180d 的验证 结果
if is_even 10; then → _even 10; then(丢 if is,空行后) 同型 ASCII 形态 echo one\r\n\r\necho two\r\n\n,事件级重组 + 屏幕渲染 + 执行输出三层断言 字节完整
echo "===== Bash 非交互测试脚本 =====" → 丢 echo (空行后) 缩进/普通行紧跟空行变体 字节完整
16 个空行边界、4 处可见丢字 连续两个空行变体(双边界) 字节完整
prompt 为 claimed/custom(user@host ~ %,comment 3,原 30 连跑未覆盖的变量) 新增 claimed-PS1 变体测试 通过、字节完整
(comment 1 已排除)pre-#288 构建 owner 已确认 hash = b5e1a2f5386c = 1f2180d 排除
剩余嫌疑 机器特定输入路径:中文 IME 注入、conhost QuickEdit、WT 版本/渲染器的 paste 合成差异 待 owner 复测:请在升级到含本 PR 的构建后重放原脚本;若再现,请附 WT 版本与粘贴方式(右键/Ctrl-V/QuickEdit)

四个相邻语义的回归证明(全部共用该代码,全部保持,零代码改动)

  1. 无空行块完整性:crlf_paste_without_empty_lines_control_keeps_every_line_intact + 单元 paste_chunk_reassembles_crlf_block_without_empty_lines_byte_exact。
  2. 块内 Enter 是数据([P1][regression #252] Windows 粘贴块启发式吞掉每个提示符后的第一次 Enter —— ConPTY 驱动/脚本/快速打字全部丢提交 #284):全部变体单次写入、中途无执行(marker 输出只出现在提交后);既有 paste_chunk_detector_* 单元组保持全绿。
  3. burst 后独立 Enter 提交整块:每个变体 200ms 后单发 \r,一次提交全部执行。
  4. [P2] Enter pressed within the paste burst window is swallowed as chunk data — needs a second Enter #308(burst 内 Enter 吞提交):与 [P1][regression?] interactive paste drops leading characters on some lines: 'if is_even 10; then' executes as '_even 10; then' #291 共用 translate_event 但是独立缺陷,本 PR 未触碰——其修复已在 fix/308-burst-enter-submit(022871c)完成,建议先合该 PR、本 PR 若有文案冲突以它为准 rebase。

测试

  • 单元(repl.rs):paste_chunk_reassembles_empty_line_paste_byte_exact、..._two_consecutive_empty_lines_...、..._indented_line_after_empty_line_...、..._crlf_block_without_empty_lines_...。
  • 交互(interactive.rs):empty_line_paste_keeps_the_next_line_intact(正确表述的吞字检查:matches("cho two") == matches("echo two") 计数相等,孤儿出现即红)、marker 执行证明、连续两空行、缩进行、无空行对照、claimed-PS1 变体。

验证

  • cargo fmt --all --check 干净;RUSTFLAGS="-D warnings" cargo check --all-targets 干净。
  • RUST_TEST_THREADS=1 NIU_INTERACTIVE_TESTS=1 cargo test --test interactive × 3:每次 48 passed,唯一红为既有基线 ctrl_d_after_background_job_exits。
  • cargo test --lib -p niubash-runtime:470 passed。

…'s self-failing assertion (closes #291)

The reported P1 minimal repro - one burst of 'echo one\r\n\r\necho two
\r\n\n' plus a separate submit Enter, screen shows 'cho two' - does not
reproduce a byte loss at 1f2180d. The probe failed 5/5 runs on ONE
assertion: !screen.contains("cho two") is unfailing on a CORRECT run
too, because 'cho two' is a strict substring of the intact rendering
'echo two'. The captured screen in every failure shows 'echo two'
complete, both outputs correct, single submit.

Byte fidelity is now pinned at two layers:

- unit (crates/niubash-runtime/src/repl.rs): feed_paste_burst() feeds the
  exact console event stream through PasteChunkEditMode with the scripted
  lookahead queue and reassembles the text that reaches reedline from the
  translated events. Four shapes - the owner burst, two consecutive empty
  lines, an indented line after an empty line, and a no-empty-line CRLF
  control - must reassemble byte-for-byte (CRLF folded to LF). The
  empty-line boundary handling (translate_event's pending CRLF push at
  repl.rs:863-891 and enter_opens_chunk's partner consumption at
  repl.rs:680-731) is exact: no off-by-one exists to correct at this rev.
- interactive (tests/interactive.rs): the scratch probe becomes
  empty_line_paste_keeps_the_next_line_intact with the sound swallow
  check - every 'cho two' on screen must be the tail of an intact
  'echo two' (count equality); a real swallow leaves an orphan (the
  executed 'cho two' line and its not-found diagnostic) and breaks it.
  Marker-output variants ($M1/$M2) prove both lines EXECUTE, including
  the line after the empty line, plus: two consecutive empty lines, an
  indented line after an empty line, a no-empty-line CRLF control, and
  the claimed/custom-PS1 surface from issue comment 3 (the one variable
  the original 30-run sweep never varied - passes too).

Adjacent semantics pinned by the same suite (all green, unchanged code):
whole-CRLF-block integrity (#288 surface, control test), burst interior
Enters stay data (#284: no mid-burst execution, asserted by the marker
variants' single submit), the burst-settled Enter submits the whole chunk
once (every variant), and #308 is NOT touched here - it is a distinct
defect in the same function with its own fix pending on
fix/308-burst-enter-submit.

Verification: cargo fmt --check clean; RUSTFLAGS="-D warnings" cargo
check --all-targets clean; RUST_TEST_THREADS=1 NIU_INTERACTIVE_TESTS=1
cargo test --test interactive x3 = 48 passed + the pre-existing baseline
ctrl_d_after_background_job_exits red each run; lib suite 470 passed.
@caomengxuan666

Copy link
Copy Markdown
Member Author

已被 #317 取代:本 PR 标题/提交信息带了 closes #291,而 #291 按纠偏结论应保持 open(复现为断言伪影,非真实字节丢失)。#317 以 refs 措辞重开同一交付的修订版(执行级 marker 断言 + #309 覆盖判别验证),请审 #317。

@caomengxuan666
caomengxuan666 deleted the fix/291-empty-line-paste-swallow branch October 13, 2026 07:06
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.

[P1][regression?] interactive paste drops leading characters on some lines: 'if is_even 10; then' executes as '_even 10; then'

1 participant