Skip to content

api: Session::run diagnostic text is the input text, not the source name (Refs #2860) - #2888

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/2860-session-diagnostic-text
Nov 6, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/2860-session-diagnostic-text

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Refs #2860 (engine half; the host half retires niubash's last direct script_driver call onto this contract — captain sequences the §2.1 ledger row and closes the issue).

What this fixes (Q-B of the #2860 ruling)

Session::run's line route passed source_name — the run's name, or the session's argv0 seed — into run_source_with_line_offset's diagnostic_text parameter. That parameter is the text the parse's offending-line echo reads: GNU parse.y:6814 print_offending_line (from report_syntax_error, parse.y:6833) echoes the verbatim line of the shell's input.

Measured pre-fix behavior of the contract (lane probes P-S5/P-S6, GNU 5.3.20 oracle):

  • Named run, echo a;; → echo line is `bash' — the NAME echoed as the offending line.
  • Named run, echo ok\necho )bad → `echo ) bad' — space-joined token reconstruction.
  • Unnamed runs fell back to the input text and echoed verbatim — which is why the GAP-2 diagnostic-value pins (message + line only) could not see the defect.
  • The grouped route was never affected: its per-group parses pass no diagnostic text and fall back to the group text. The scoping record's grouped-route charges (no echo, no prefix execution) were re-measured against the oracle and are GNU-correct for the interactive shape that was probed: GNU runs no same-line prefix (the reader unit is the line; complete earlier lines run) and suppresses the echo for the interactive shell's own input stream.
  • Prefix execution matches GNU on both routes for all 12 probed shapes — no routing change is needed (Q-C closes by evidence).

The fix passes the input text explicitly (Some(source)). The name keeps its own jobs: the diagnostic values' source_name and the run event record. No public surface changes — the api-ledger is untouched by this PR.

Pins

Two pins in src/api/consumer_tests.rs, using the issue2084 child-process pattern (the echo is text on fd 2, not a diagnostic value, so the parent asserts on the child's captured stderr):

  • issue2860_named_source_echoes_the_input_line_not_the_name — RunOptions.source_name = "bash".
  • issue2860_argv0_seeded_session_echoes_the_input_line_not_the_name — Session::builder().argv0("gap2860.sh"), the host's script-file shape.

Both run one scenario (echo a;; / two-line prefix / same-line prefix / subshell list) asserting value surface in the child and verbatim echo + line-unit prefix behavior in the parent. Mutation-checked: with the name restored to the slot both pins fail; with the fix both pass. Neighborhood: api::consumer_tests 114/114, --test session_api 19/19, --test issue845_subshell_stray_close_regressions 6/6.

本 PR 删除了什么

Nothing deleted — the change is one mis-threaded argument plus its explanatory comment in src/api/session.rs, and the two pins (+123 lines in consumer_tests.rs). Net: +138/−1 across 2 files.

… not the source name (Refs #2860)

The line route of Session::run passed `source_name` (the run's
name, or the session's argv0 seed) into
run_source_with_line_offset's diagnostic_text parameter. That
parameter is the text the parse's offending-line echo reads:
GNU parse.y:6814 print_offending_line (from report_syntax_error,
parse.y:6833) echoes the verbatim line of the shell's INPUT.
With a name in the slot, a named run echoed the name itself for
a one-line input (`bash: `bash'` for `echo a;;`) and a
space-joined token reconstruction for a later line
(`` `echo ) bad' ``); unnamed runs fell back to the input text
and echoed verbatim, which is why the GAP-2 diagnostic-value
pins could not see the defect. The grouped route was never
affected (its per-group parses pass no diagnostic text and fall
back to the group text).

Pass the input text explicitly. The name keeps its own jobs:
the diagnostic values' source_name and the run event record.

Pins (consumer_tests, child-process stderr capture per the
issue2084 pattern, because the echo is text on fd 2, not a
diagnostic value): a source named via RunOptions.source_name
and a session seeded with builder argv0 (the host's script-file
shape) both echo every offending line verbatim across the
stray-close shapes, with GNU's line-unit prefix rule (earlier
lines run, the offending line's own commands never do).
Mutation-checked: both pins fail with the name restored to the
slot.

本 PR 删除了什么: the mis-threaded argument only — no code
deleted; the change is one argument plus its comment, and two
pins (+123 lines in consumer_tests.rs). Net: +138/-1.
@caomengxuan666
caomengxuan666 marked this pull request as ready for review November 6, 2026 09:13
@caomengxuan666
caomengxuan666 merged commit b3af6de into master Nov 6, 2026
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