Skip to content

test(repl): echo-proof ctrl_d_midline; #368 read-unit/line-identity audit report - #419

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/368-audit
Oct 18, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/368-audit

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Closes part of #368 (host-side deliverables). Engine defect found by the audit is filed upstream: unixwin/rubash#817.

What

  1. tests/interactive.rs — ctrl_d_midline_does_not_exit echo-proofing. The expected marker (half-typed) appeared verbatim in the submitted input, so the terminal echo of the typed text could satisfy expect even when the completed line never executed — the exact trustworthiness class niubash#367 called out for the alias matrix. The probe now types echo half-typed, survives the Ctrl-D, extends the word in place (-ok), and asserts on half-typed-ok — a string the input never contains — so the assertion proves the line both survived the EOF key and executed. Checklist item D of [P2] Audit read-unit / line-number identity across alias + line-based semantics (follow-up to #367) #368.
  2. docs/audit/findings/i368-read-unit-line-identity.md — the [P2] Audit read-unit / line-number identity across alias + line-based semantics (follow-up to #367) #368 audit report (checklists A/A2/B/C/D, file:line evidence, GNU differ tables, runtime probe inventory).

Audit verdicts (details in the report)

  • A: of 65 __RUBASH_CURRENT_LINE references on rubash master 8ab35e89, exactly one is load-bearing (the alias same-read guard, arithmetic_aliases.rs:832-834,867-878); all others are report-only (LINENO/caller/diagnostic prefixes/comsub line seeding). That one site carries a confirmed cross-read-unit collision (source/eval-defined alias suppressed with command not found where GNU expands) → rubash#817 with two GNU-differed repros and a must-survive semantics table.
  • A2: function-definition lines / $LINENO / caller / trap stamping match GNU in the probed shapes; -i/-i -c expand_aliases default and cumulative interactive $LINENO (1, 2) match GNU.
  • B: host fast-path vs grouped-reader parity verified clean (cd C:/x, bare C:, cd /c/x, pipeline) — both routes converge byte-identically (ConPTY probe, --test-threads=1).
  • C: unalias/unalias -a marker cleanup already fixed upstream (alias_set_builtins.rs:15,20-57, pinned by rubash's issue367_alias_line_hygiene_regressions.rs); child-env leak analysis clean (env_clear spawn path; wrapper/coproc line identity is designed GNU-fork equivalence; child parse errors use token-derived lines — verified line 1, not the parent's stale marker).
  • D: alias matrix echo-proofing landed (6/6 green on d60276e); this PR fixes the one remaining echo-satisfiable active test.

Test gates

  • ctrl_d_* trio: green on this branch (--test-threads=1).
  • Alias matrix (6 tests): green.
  • Full interactive suite: 63–64 pass; the failures (continuation_single_quote_ps2_and_completes, continuation_subshell_paren_completes, ctrl_c_interrupts_external_command, gitbash_factory_prompt_renders_and_tracks_the_branch, occasionally ctrl_d_after_background_job_exits) reproduce identically on pristine d60276e (baseline run: same 4 + flake) — pre-existing ConPTY-timing flakes on this host, unrelated to this change.

Not to be merged by the author; based on origin/master d60276e.

…t/line identity

- ctrl_d_midline_does_not_exit: the expected marker ('half-typed') appeared
  verbatim in the submitted input, so the terminal echo could satisfy the
  assertion without the completed line ever executing — the exact class
  niubash#367 called out. The probe now extends the word in place after the
  EOF key and expects 'half-typed-ok', which the input never contains, so
  the assertion proves the line survived Ctrl-D AND executed.
- docs/audit/findings/i368-read-unit-line-identity.md: niubash#368 audit —
  65 __RUBASH_CURRENT_LINE consumers classified (1 load-bearing: the alias
  same-read guard, confirmed cross-read-unit collision filed upstream as
  rubash#817); host fast-path vs grouped-reader parity verified clean;
  child-env leak analysis clean; -i/-i -c expand_aliases + LINENO match
  GNU; alias matrix echo-proof status recorded.

@caomengxuan666 caomengxuan666 left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independent CR (cr-419) — verdict: APPROVE-WITH-NITS

Reviewed at 98bd821 in an isolated worktree; mutation experiments were run and fully reverted (tree pristine afterward, ctrl_d_midline_does_not_exit re-verified green).

1. Echo-proof hardening works (mutation-verified)

Mutation: rebound mid-line Ctrl-D in the emacs keymap to EditCommand::Clear (reedline 0.50 add_binding(CONTROL, 'd', Edit([Clear]))) — models the masked failure class "half-typed input handled/echoed, completed line never executes".

  • NEW test turns red on the mutant (half-typed-ok never appears; -ok runs alone → command not found). Reverted → green again. This is exactly the regression ctrl_d_midline_does_not_exit exists to catch, and the old expect("half-typed") + expect_prompt() pair could not catch it (a discarded line still produces an echo satisfiable half-typed and a fresh prompt on non-coalescing render paths).
  • Empirical note: on this Windows host the old assertion also failed on this particular mutant, but for a different reason — the paste-chunk state machine (crates/niubash-runtime/src/repl.rs PasteChunkEditMode) buffers a key burst and only flushes it into the edit buffer on the next key event, so the mutant's flush+Clear coalesced into one repaint and the typed text never rendered at all. So the docstring's mechanism ("the terminal echo of the typed text satisfies expect") is host/timing-dependent rather than universal; on per-char render paths (Unix delegate, gap-separated keys) it applies as written. The hardening strictly dominates either way.

2. NIT — residual hole: the marker is still a literal of the completed buffer

half-typed-ok is a verbatim substring of the buffer once -ok lands (echo half-typed-ok). If a regression swallowed Enter after the suffix reached the buffer, the editor's repaint of the unsubmitted line prints echo half-typed-ok contiguously → expect("half-typed-ok") satisfied, and expect_prompt() is satisfied by the same repaint (the prompt is re-rendered on every redraw). False pass remains possible in that narrow shape. The alias-matrix discipline this PR's own report praises (markers must be runtime-derived output — rc variables / printf formats — never a literal that can sit in the buffer) would close it, e.g. complete with && echo ok-$((40+2)) and expect ok-42. Also fine to leave as-is given the realistic regressions (exit on Ctrl-D, discard on Ctrl-D, split-line) are all caught; but the docstring's "a string the input never contains" deserves a footnote that it means the input byte stream (the \x04 separates the halves), not the completed buffer.

3. Audit report — spot-checks pass (5/5)

All verified against the pinned engine base rubash 8ab35e89:

  • src/executor/arithmetic_aliases.rs:832-834 gate + :867-878 reader/comparison — exact; both lines unchanged on current rubash master c6f4a9b.
  • src/executor/alias_set_builtins.rs:65 (record_alias_definition_lines(.., cmd.line)) + :88 (marker insert) + :15,20-57 (clear_alias_definition_lines) — exact.
  • src/executor/trap_exec.rs:460-480 eval renumbering caller_line + i - 1 — exact.
  • src/builtins/source/execution.rs:291-293,351-358 __RUBASH_CURRENT_LINE save/restore — exact.
  • Host refs: tests/interactive.rs:64/:82 (closed/closed' weak secondaries, load-bearing markers precede them) — accurate; :351/:372-407 ignore reasons — accurate; shell.rs:770-812 execute_interactive_reader_batch (actual 777-809) and normalizers 2435-2560,2682-2869 — land.

Nit: the report cites tests/interactive.rs:380-575 as "the whole alias matrix" — the six alias fns actually span 416-577 on d60276e; 380-407 is history_bang_*. Substance correct, range off by a few lines on both ends.

4. Change surface & gates

  • Diff vs d60276e: exactly 2 files — tests/interactive.rs (+15/-3, one test + doc comment) and the new report. No product code, no stowaways.
  • Full interactive suite, --test-threads=1: 64 passed / 4 failed / 7 ignored. Failure set = {continuation_single_quote_ps2_and_completes, continuation_subshell_paren_completes, ctrl_c_interrupts_external_command, gitbash_factory_prompt_renders_and_tracks_the_branch} — exactly the four pre-existing named in the PR description; the fifth disclosed flake ctrl_d_after_background_job_exits did not fire in the suite run but reproduced intermittently in isolated re-runs afterward (ok → FAILED → ok on three consecutive solo runs), matching the "occasionally" disclosure. ctrl_d_* trio green on the branch.

5. rubash#817 cross-reference — accurate

unixwin/rubash#817 exists (OPEN), and its title/body match the report's defect section verbatim in substance (both repros, the load-bearing sites, the must-survive table, the read-unit-generation fix direction). PR body's "Closes part of #368 (host-side deliverables)" is consistent with the report's deliverables section.

Not merging. Nits are non-blocking; fix-or-followup at author's discretion.

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