Skip to content

builtins: converge exec option-parse prefix args onto the shared derivation chain (Refs #3256) - #3352

Merged
caomengxuan666 merged 2 commits into
masterfrom
fix/3256-prefix-convergence
Nov 11, 2026
Merged

caomengxuan666 merged 2 commits into
masterfrom
fix/3256-prefix-convergence

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Refs #3256

What this changes

The exec builtin's option parser (parse_options in src/builtins/exec.rs) takes its diagnostic prolog as a string argument. The real dispatch face already passes the shared builtins::diagnostic::diagnostic_prefix, but three call sites restated a local "rubash: " literal:

  • replace_process_image now passes diagnostic_prefix(env_vars) — the same derivation the dispatch face uses. Its diagnostics go to io::sink, so the value was never observable.
  • status_is_option_parse_failure and command_operand_index now pass sink_option_prefix(), a new local helper that derives the prolog from the single argv[0] carrier chain (builtins::prefix, process-environment getter — the same getter the kill stdio face uses). Both probes write to io::sink, so no observable output changes.

Observable behaviour is byte-identical: every diagnostic the exec face prints goes through execute_impl's unchanged prefix argument, and the three converged sites discard their diagnostics. A convergence-lock pin (tests/issue3256_exec_option_prefix_lock.rs) asserts the option-diagnostic output byte-for-byte; the pin is green on both the base and this head by design (it is a lock, not a fail-first pin).

Deliberately NOT in this PR

The remaining literal faces named in the issue — the shared src/builtins/diagnostic.rs functions and the lib-level Prolog compositions in alias / set / setattr / unset / declare — are not converged here: on their incomplete-carrier arms the literal and the derived chain disagree (a renamed or path-invoked shell would print a different name), so converging them changes observable output. Under this lane's byte-identical mandate those faces are stopped and documented with full divergence matrices in the lane report for a captain ruling, rather than changed unilaterally.

本 PR 删除了什么

  • The three local "rubash: " literal arguments in src/builtins/exec.rs (in replace_process_image, status_is_option_parse_failure, and command_operand_index). No functions, files, or behaviours are removed.

@caomengxuan666
caomengxuan666 marked this pull request as ready for review November 11, 2026 12:05
@caomengxuan666
caomengxuan666 merged commit 20ba3ae into master Nov 11, 2026
11 checks passed
caomengxuan666 added a commit that referenced this pull request Nov 11, 2026
…ed argv0 chain (#3356)

Refs #3256

## What this wave does

The (b) wave of the diagnostic-prefix convergence (the first wave landed as PR #3352). The ten faces that had to wait each derived their diagnostic name privately — a hard-coded fallback literal, the shell-name carrier printed verbatim as the interactive name, or a process-env prolog that cannot see the interactive carrier at all. The renamed-shell experiment against the GNU 5.3.20 oracle showed GNU has exactly one name source for all of these faces (`error.c:90-120 get_name_for_error`; `shell.c:1797/1804`), and measured four divergence classes at the CLI. This PR migrates every remaining face onto the single argv[0] carrier chain in `builtins::prefix`:

- `builtins::prefix` gains a `sys_error_prefix` renderer (`error.c:275-281`: name segment only, never a line segment).
- `builtins/diagnostic.rs` — the diagnostic / sys_error / err_readonly builders delegate to the chain behind the interactive arm (basename, no line segment).
- Lib Prolog faces — `alias.rs`, `set.rs::prolog_for_env`, `setattr.rs`, `set/unset.rs`, and `PrologParts::Lib` in `executor/builtin_diag.rs`: the error name comes from the chain's fallback derivation and the interactive name cell holds the basename derivation instead of the raw shell-name carrier.
- `alias`/`unalias` now take the dispatcher's composed prolog (`Executor::diagnostic_prolog`), for the same dispatcher-owns-the-prolog reason as the Stage-2 ④ D3 migration: the lib prolog reads the process env, and the interactive carrier is never mirrored there.
- `builtins::set::builtin_error_prefix` (production consumer: the TIMEFORMAT diagnostic in `executor/read_helpers.rs`) derives every arm from the chain; the eval frame's `eval:` segment, which has no chain counterpart, keeps its existing shape.
- `setattr.rs`'s readonly prefix delegates to the chain's err_readonly renderer outside the interactive arm.

## 本 PR 删除了什么

- The literal-prefix shim in `executor/trap_exec.rs` (`execute_exec`'s no-operand path): it rewrote buffered builtin stderr beginning with the literal `rubash: ` to the executor's prefix. The builtin face now derives the same prefix from the same carriers through the shared chain, so the literal it matched can no longer be produced; the rewrite is removed rather than left as dead code. The script-form bare-exec cells of the new pin (and of the first wave's pin) cover the path it served.
- `builtins/diagnostic.rs`'s private `error_file_name` helper, subsumed by the chain's renderer inputs.
- Two expectation cells in `tests/executor_tests.rs` (`builtin_error_prefix_three_modes_match_gnu`) that encoded the old hard-coded fallback name: the line-only and carrier-less arms now end at the chain's terminal fallback, GNU's PROGRAM `bash`. This is a deliberate expectation change following the migration ruling, recorded here rather than silently edited.
- Two expectations in `tests/executor_command_chaining/part_023.rs` (`test_cd_redirects_stderr`, `test_cd_appends_stderr`): under the bare `Executor::new()` embedding (a line carrier but no file/name carrier) the cd diagnostic now renders the chain's line-only arm, `bash: line 1: cd: ...`, instead of the old face's hard-coded `rubash: ` fallback — the same shape the executor's own prefix locks for this embedding. Verified bilaterally in captain review (both pass on the head tree with the new expectations; the executor_tests failure name-set is byte-identical between base and head). The neighbouring `times` expectations in `part_024.rs` fail identically on both trees — a pre-existing, environment-sensitive red outside this wave's faces — and are untouched.

## Evidence

- New regression pin `tests/issue3256_renamed_prefix_matrix.rs` (whole stem `#![cfg(unix)]`, like its sibling stem): renamed invocations (arg0 rename; a physically copied binary invoked by absolute path) across the lib-reachable faces (alias, export, readonly, unset, exec, cd's sys_error face, the TIMEFORMAT face) in -c, script, and interactive forms, plus direct calls of the public prefix face. Expectations are the GNU 5.3.20 outputs from the dossier's renamed-matrix experiment.
- Fail-first, captain re-run on the PR's true base `f5f65d35` with the pin topped up: 3 passed / 6 failed — the six reds are exactly the interactive cells and the chain API cell, matching the experiment's four divergence classes; the -c and script cells pass on both sides (the startup seed already fed those faces the invocation name) and lock the migration against regression. On this head: 9 passed / 0 failed.
- The eval arm of `builtin_error_prefix` has no chain counterpart and no GNU interactive measurement behind it; it is pinned in its existing shape only (script + line + eval carriers), and that limitation is stated in the wave's report section rather than presented as coverage.
- Captain review (dossier `review-3356/CAPTAIN-VERIFY.md`): lib bilateral base 1245/0/4 vs head 1246/0/4 (difference is exactly the new sys_error unit test), failure name-sets empty on both sides; executor_tests failure name-sets identical at 57 on both sides (the box part_* environment family, pre-existing); issue1768 name-sets identical bilaterally (known base reds); -D warnings / marker-lint / UTF-8 hygiene / fmt all rc=0 on the head; final-head CI 11 legs all finished, zero red.
- The PR's branch base is `f5f65d35`; the lane's report ran its fail-first against the ancestor `20ba3aea` (the interval between them is PR #3215's two files, zero intersection with this wave's faces). The captain's re-run on the true base reproduces the lane's numbers exactly.

Closing-word scan (captain merge discipline): this body and the PR title were scanned in full; the only issue reference is the standalone `Refs #3256` line above, and no closing-keyword word form appears in any sentence containing an issue reference.
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