Skip to content

fix(repl): a paste burst's trailing bare Enter submits the buffered chunk (closes #308) - #309

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/308-burst-enter-submit
Oct 13, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/308-burst-enter-submit

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Closes #308.

Root cause

PasteChunkEditMode::translate_event() (crates/niubash-runtime/src/repl.rs) treated every bare Enter arriving while a chunk was pending as paste data: the pending branch pushed '\n' into the buffered chunk unconditionally and returned ReedlineEvent::None. So a paste followed immediately by Enter — send(paste_crlf + "\r"), one write, the Enter <50 ms after the last paste key — was swallowed: the trailing CR became a newline inside the pending chunk, nothing executed, and the user needed a second Enter. (Instrumentation trace of the pre-fix build: bare enter with PENDING -> pushed as newline data.)

Fix — extend the #288 structural judgment to the pending branch

The pending branch no longer trusts the burst clock for Enters. A bare CR arriving on a pending chunk runs the same LF-partner lookahead the chunk-open Enter has used since #284 (now extracted as PasteChunkEditMode::cr_has_lf_partner, budget PASTE_LF_PROBE = 10 ms):

  • LF partner queued behind the CR → a break still INSIDE the pasted block: fold one '\n', partner consumed with its CR, burst continues quietly. Interior breaks of a multi-line CRLF paste stay data — existing paste buffering is untouched.
  • Silence, or any other queued key (typeahead text, a second Enter, a chord) → the block is complete and this is the user's submit: the chunk flushes as one InsertString and the Enter delegates in the same batch — first Enter executes, no second Enter, same flush-then-submit shape as the settled-burst path.

A directly dispatched Ctrl+J during a burst is by construction a lone LF (any paired LF was consumed by its CR's probe), so it stays newline data — and the now-provably-dead last_bare_cr pairing flag is retired.

Semantics anchor (reedline 0.50.0 — vendored in Cargo.lock / registry source)

  • src/edit_mode/mod.rs:44-47 — Event::Paste(body) → one EditCommand::InsertString with \r\n → \n: a paste's breaks are data of a single insert; a paste never carries an Enter event.
  • src/engine.rs:408-416 — use_bracketed_paste doc: with bracketed paste "all lines will appear in the buffer and can then be submitted with a separate enter" — once the body is complete, the next Enter IS the submit, never more data.
  • src/engine.rs:1052-1067 — the read loop's completed() helper stops every reedline batch at a bare Enter, so everything behind a dispatched CR is still in the console queue — the queue probe is sound (the CR's LF cannot have been consumed ahead of it).

Tests

Unit (niubash-runtime --lib, 469 pass incl. 13 paste-chunk):

  • paste_chunk_detector_enter_in_paste_burst_submits_the_chunk — [P2] Enter pressed within the paste burst window is swallowed as chunk data — needs a second Enter #308 itself: mid-burst bare CR with an empty queue flushes + submits the whole chunk (InsertString("\necho hi") + Enter in one batch), pending cleared, nothing pushed back.
  • paste_chunk_detector_interior_crlf_pair_stays_data_mid_burst — interior CR with its partner queued stays data; partner consumed, burst continues.
  • paste_chunk_detector_pending_enter_with_typeahead_behind_submits_in_order — typeahead behind the pending-Enter submit is pushed back and lands in order on the next line (GNU typeahead semantics).
  • The CRLF-absorption test now models the real feed queue (each interior CR has its partner queued behind it) and pins lone-LF-mid-burst as a real newline.

Interactive (tests/interactive.rs, NIU_INTERACTIVE_TESTS=1 RUST_TEST_THREADS=1):

  • New paste_with_same_burst_enter_submits_on_first_enter — the 100% repro form, one write s.send("echo $TS1\r\necho $TS2\r\n\r"): both markers and the fresh prompt on the first Enter. Verified to fail on pre-fix code (times out waiting for output, exactly the issue's swallowed-Enter shape).
  • All existing paste/burst/Enter scenarios stay green: multiline_crlf_paste_buffers_whole_chunk_and_executes_once, multiline_raw_paste_windows_crlf_buffers_and_cr_executes_per_line, rapid_input_burst_all_lines_execute, send_line_first_enter_submits_and_typeahead_executes ([P1][regression #252] Windows 粘贴块启发式吞掉每个提示符后的第一次 Enter —— ConPTY 驱动/脚本/快速打字全部丢提交 #284), multiline_bracketed_paste_buffers_whole_chunk, ctrl_v_clipboard_paste_single_buffer_execution, esc_sequenced_arrow_keys_edit_without_absorption.

Verification: cargo fmt --check clean; RUSTFLAGS=-D warnings cargo check --all-targets clean; full interactive suite 43 passed / 1 failed — the only failure is the pre-existing baseline ctrl_d_after_background_job_exits.

…hunk (closes #308)

A paste followed immediately by Enter — send(paste_crlf + "\r"), one
write, the Enter <50 ms after the last paste key — was swallowed: the
pending-chunk branch of translate_event() pushed every bare Enter into
the chunk as newline data unconditionally, so nothing executed and a
second Enter was needed.

Extend the #288 structural judgment to the pending branch: a bare CR
now runs the same LF-partner lookahead as the chunk-open Enter
(extracted as PasteChunkEditMode::cr_has_lf_partner). An LF partner
queued behind the CR proves the break paste data (a break still INSIDE
the block); silence or any other queued key proves the block complete
and the Enter the user's submit — the chunk flushes and submits in one
batch, first Enter, no second. Anchored in reedline 0.50.0 bracketed
paste semantics: Event::Paste folds breaks into \n data of one insert
(edit_mode/mod.rs:44-47) and the buffer "can then be submitted with a
separate enter" (engine.rs:408-416); the probe is sound because
reedline's batch loop itself stops at a bare Enter
(engine.rs:1052-1067), so the queue behind a dispatched CR is intact.

The CR now always consumes its partner when present, which retires the
last_bare_cr pairing flag: a directly dispatched Ctrl+J during a burst
is by construction a lone LF — real newline data, never a folded pair.

Tests: unit — pending bare CR without partner flushes+submits the
whole chunk mid-burst (chunk content pinned), interior CRLF pair stays
data with the partner consumed, typeahead behind the pending Enter
submits in order; interactive — paste_with_same_burst_enter_submits_
on_first_enter pins the one-write repro (fails on pre-fix code, verified).
@caomengxuan666
caomengxuan666 merged commit 31eee15 into master Oct 13, 2026
11 checks passed
caomengxuan666 added a commit that referenced this pull request Oct 13, 2026
…false positive

"echo two".contains("cho two") is true by substring semantics (the
editor echo of the input line contains it), so the probe failed on
healthy shells too. Execution-level verification (flush trace, submit
buffer, arithmetic-mark outputs) shows the paste bytes intact on
current master; the real paste defects are #308 (fixed by #309) and
the owner-machine investigation tracked in #291.
caomengxuan666 added a commit that referenced this pull request Oct 13, 2026
… and #309 coverage (refs #291) (#317)

The niubash#291 "minimal repro" is a false positive: the scratch probe's
negative assertion !screen.contains("cho two") fails on a CORRECT run
too, because "cho two" is a strict substring of the intact rendering
"echo two". Every captured failure screen shows "echo two" complete with
both outputs correct on a single submit; ~70 execution-level runs across
builds/claim/write-shapes reproduce no byte loss. #291 therefore stays
OPEN pending owner-side evidence (history bytes / rc / terminal / IME /
build provenance) - this PR closes nothing.

What lands here, all test-only (zero runtime code changed):

- Unit (crates/niubash-runtime/src/repl.rs): feed_paste_burst() feeds the
  exact console event stream of a one-write CRLF paste through
  PasteChunkEditMode (scripted lookahead queue, post-#309 semantics:
  every pasted CR consumes its queued LF partner) and reassembles the
  text reaching reedline from the translated events. Four shapes must
  reassemble byte-for-byte: the reported empty-line burst, two
  consecutive empty lines, an indented line after an empty line, and a
  no-empty-line CRLF control.

- Interactive (tests/interactive.rs): execution-level marker technique -
  the pasted body carries `echo RES_$((40+2))`-shaped lines, so the
  output RES_42 appears nowhere in the echoed input and proves the line
  executed with every leading byte intact; a swallowed head leaves no
  marker. Substring assertions against the screen are banned in this
  suite (the probe's trap). Shapes: the owner burst with a settled
  submit, the SAME-burst submit Enter (one write - niubash#309 coverage
  on the empty-line shape: first Enter must submit, the test sends
  nothing else), two consecutive empty lines, indented line, the
  no-empty-line control, and the claimed/custom-PS1 surface from issue
  comment 3 (the one variable the original 30-run sweep never varied).

Adjacent semantics pinned green on current master: whole-CRLF-block
integrity (#288 surface), burst interior Enters stay data (#284), the
burst-settled Enter submits the whole chunk once, and #309's first-Enter
submit holds on the empty-line shapes.

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: new suite green; lib suite green.
@caomengxuan666
caomengxuan666 deleted the fix/308-burst-enter-submit branch October 13, 2026 07:06
caomengxuan666 added a commit that referenced this pull request Oct 13, 2026
…#292)

* feat(prompt): built-in Git Bash compatible factory default on Windows (owner adjudication 2026-10-12)

The factory default prompt on Windows is now the Git Bash skeleton:
green user@host, yellow POSIX-persona cwd, cyan branch (+ dirty *) and
`$ ` — the MINGW64 environment segment is deliberately omitted (that is
MinGW identity) and there is no static product tag (single-environment
shells have no disambiguation need; identity lives in the banner).

The branch/dirty segment reads the repository through git2
(owner-approved library dependency, adjudication option d;
Windows-target-only compile) instead of a git child process — the
prompt path never spawns (niubash#145 red line). Measured on this
machine against a real repository: cold 39ms, warm p50 2.5ms / p90
3.7ms per prompt, versus Git Bash's per-prompt __git_ps1 fork
(~100-300ms).

Claims still win: a PS1/theme claim displaces the floor per prompt
(prompt_slot_claimed check in prompt_for_display), set -o vi keeps the
live editing-mode indicator (niubash#184 surface), and the theme does
not exist off-Windows — a config naming it there falls back to the
template floor, keeping the unix cfg-strip clean (#570 precedent).

Tests: git_prompt unit matrix (branch/dirty/detached/tilde/persona/
budget), real-ConPTY factory-prompt scenario incl. cd into a repo, and
the vi floor indicator updated to the new factory prompt char.

* fix(prompt): gate the git_prompt module to Windows in lib.rs

The unix acceptance lanes caught it: the module declaration had no cfg
gate, so unix targets compiled src/git_prompt.rs against the
Windows-only git2 dependency (E0433). Same #570 discipline as the rest
of the theme.

* test: drop the empty-line paste probe - its contains assertion was a false positive

"echo two".contains("cho two") is true by substring semantics (the
editor echo of the input line contains it), so the probe failed on
healthy shells too. Execution-level verification (flush trace, submit
buffer, arithmetic-mark outputs) shows the paste bytes intact on
current master; the real paste defects are #308 (fixed by #309) and
the owner-machine investigation tracked in #291.

* fix(prompt): allow the write-only flag off-Windows

The unix -D warnings lanes flag gitbash_prompt_active as never-read
(the refresh site is cfg'd out there); cfg_attr keeps the field for
the Windows state machine while silencing the unix dead-code leg.
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.

[P2] Enter pressed within the paste burst window is swallowed as chunk data — needs a second Enter

1 participant