Skip to content

audit(posix): complete the GNU posix-mode coverage audit - fatality family, redirect no-split, time stream, trap usage exit - #559

Merged
caomengxuan666 merged 5 commits into
masterfrom
docs/posix-mode-audit
Oct 12, 2026
Merged

caomengxuan666 merged 5 commits into
masterfrom
docs/posix-mode-audit

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

What

Second pass over the 75-sub-item matrix in docs/posix-mode-audit.md, after the first pass (items 19, 47, 52, 56, 58, 67, 68, 69). The matrix now reads 42 implemented / 10 doc-drift / 5 deferred / 12 n-a / 6 static (was 28 implemented / 17 not-implemented before the PR).

Fixed this pass

item behavior
35 bare ro=2 on a readonly var (no command word) exits status 1 in posix at top level; subshells were already fatal in both modes
36 assignment error before the command word exits posix status 1 and the command never runs — oracle correction: GNU 5.3 does this for EVERY command class (special builtin, builtin :, external ls, function), not just special builtins
37 readonly for/select loop variable exits at the bind (status 1)
40 export/readonly assignment-class failures (invalid identifier AND readonly conflict) arm special_builtin_failed → posix non-interactive exit; export -f nofn and non-special declare 9x=1 stay non-fatal, oracle-matched; unset -v 9bad was already fatal on master
10 redirect targets: split-produced whitespace is literal filename data (f="two words"; echo hi > $f opens one file, rc=0 like GNU); brace word lists stay ambiguous; default mode keeps "ambiguous redirect"
6 time report goes through the executor's fd-2 endpoint in posix ({ time …; } 2>f captures it byte-identical to GNU); default keeps the historical raw stream
68 (completed) the trap reset-by-name usage path now returns GNU's RAW internal EX_USAGE (258) so the execute_trap wrapper's > EX_SHERRBASE gate actually arms special_builtin_failed — the first draft returned the already-converted 2 and the posix exit silently never fired (caught by probe p30)

Oracle discipline

  • WSL GNU bash 5.3.0(1)-release, wsl.exe bash --posix -s stdin method.
  • 48-probe three-way harness (origin/master-posix vs branch-posix vs GNU-posix, argv[0]=sh.exe for true posix): 35 byte-identical after diagnostic-prefix normalization; every residual difference is a documented deferral (26/75 job-table lifetime, 29 .sh_history, 42 command-declare, 7 time-lexer), GNU 5.3 drift (12/20/22/33/51/55/66/71), or a wsl.exe file-capture artifact (GNU stdout before a jump-exit; re-verified through the pipe — p15/p17/p18/p21).
  • New unit tests: alias posix listing prefixes, kill sigspec validator, trap reset-by-name internal usage + display prefix stripping; fixed the stale alias_with_io call the first pass left in the pre-existing alias test (cfg(test) code is not compiled by cargo build).

Verification

  • cargo fmt; full cargo test --no-fail-fast on the rebased branch: the failure set is a strict subset of a fresh origin/master (db3218a) run — zero branch-only failures (53 shared, master's extra 5 are load-flaky cd/pushd/prompt/wait_n timing tests from the parallel build).
  • Rebased onto origin/master (db3218a): the 7 new master commits touch zero files in common with this PR.

Related

…fatality family, redirect no-split, time stream, trap usage exit

Second pass over the 75-sub-item matrix in docs/posix-mode-audit.md, after
the first-pass fixes (19, 47, 52, 56, 58, 67, 68, 69):

- 35/36 assignment-error fatality: apply_permanent_assignments /
  apply_temporary_assignments report failure to the dispatcher; a posix
  non-interactive shell exits status 1 (no command word: GNU exits in every
  mode and rubash subshells already did; before a command word GNU 5.3
  exits for EVERY command class - special builtin, ordinary builtin,
  external, function - and the command never runs; the default mode keeps
  apply-and-continue).
- 37 readonly for/select loop variable exits at the bind in posix.
- 40 export/readonly assignment-class failures (invalid identifier AND
  readonly conflict) arm special_builtin_failed via the dispatch gate;
  export -f not-a-function and non-special declare stay non-fatal,
  oracle-matched. unset was already fatal on master.
- 10 redirect targets: in posix the ambiguity gate treats split-produced
  whitespace as filename data (f="two words"; echo hi > $f opens one file
  like GNU) while brace word lists stay ambiguous; the no-glob gate already
  covered the pathname side.
- 6 time: posix routes the TIMEFORMAT/POSIX_TIMEFORMAT report through the
  executor's fd-2 endpoint ({ time ...; } 2>f captures it byte-identical to
  GNU); default mode keeps the historical raw stream.
- 68 completed: the trap reset-by-name usage path returns GNU's RAW internal
  EX_USAGE (258) so the execute_trap wrapper's >EX_SHERRBASE gate arms
  special_builtin_failed and converts to 2 - the first pass returned the
  already-converted 2 and the posix exit silently never fired (p30).
- docs/posix-mode-audit.md: matrix re-baselined to 42 implemented / 10
  doc-drift / 5 deferred / 12 n-a / 6 static, oracle corrections recorded
  (35 top-level, 36 all-command-classes, 40 unset already fatal), wsl.exe
  file-capture artifact noted, unit tests added (alias listing prefixes,
  kill sigspec validator, trap usage/display) and the stale alias_with_io
  call in the pre-existing alias test fixed.

Oracle: GNU bash 5.3.0(1)-release via WSL (wsl.exe bash --posix -s);
48-probe three-way harness (master-posix vs branch-posix vs GNU-posix):
35 byte-identical after diagnostic-prefix normalization, all residual
differences documented deferrals, GNU drift, or capture artifacts.
…d re-record errors.snap - the goldens gate caught a wrong oracle reading

The CI goldens gate (upstream_suite_slice_snapshots: errors) on the first
push of #559 exposed two things:

1. The second pass's item-36 reading ("GNU exits for every command class")
   was wrong - an artifact of stdout pipe buffering over GNU's jump-exits.
   Re-probed cell-by-cell with stderr-only per-process probes, GNU 5.3
   posix on a failed readonly tempenv assignment:
   - special builtin command word: the shell exits (status 1) - `ro=2 :`;
   - ordinary builtin / external / function: the command is SKIPPED, the
     rest of the command list is abandoned with status 1, the script
     continues (the ksh93 emulation GNU's own errors7.sub comment
     describes: `x=8 echo` runs nothing, `after non-special builtin: 1`);
   - no command word: fatal (item 35, unchanged);
   - subshell forms exit the subshell with 1, the parent continues.
   The dispatch gate now branches on is_posix_special_builtin:
   ExecuteError::ExitCode(1) only for the special-builtin class,
   ExpansionFailure(1) (the skip-and-abandon contract) otherwise; the
   function-call fast path takes the skip-and-abandon arm too.
2. Both early-return paths skipped restore_temporary_assignments, leaking
   an unbalanced tempenv mark that corrupted every later restore - the
   full-file errors7 run behaved differently from the isolated probe with
   the same constructs. Both paths restore the partial binds first now.
3. `${v:=val}` against a readonly variable before the special builtin `:`
   (the parameter-expansion assignment arm in both parameter_assignment_error
   sites) is fatal in posix (GNU probe: subshell exits 1, nothing after
   runs); default keeps the status-2 discard rubash already had.

tests/regression/snapshots/errors.snap is re-recorded via the module-header
protocol (RUBASH_REGRESSION_RECORD=1). Every default-run byte is kept; the
delta is exactly the `-o posix` child-run lines, which now match
`bash -o posix` byte-for-byte on errors4.sub and errors7.sub - the previous
recording had baked in the pre-audit engine's never-exits posix behavior,
which the audit's GNU evidence shows was not GNU-aligned. No other snapshot
is touched (comsub/heredoc/nquote, which fail locally even with pure
origin/master src, are a master-side local-recording divergence reported on
the PR for triage).

Verification: rubash posix now matches GNU cell-for-cell on the 12-cell
matrix, and errors4.sub/errors7.sub match GNU byte-for-byte in BOTH modes
(default mode remains identical to the old-master engine); the 12-probe
fix battery stays byte-identical to GNU; full cargo test --no-fail-fast
failure set remains a strict subset of the fresh-master baseline.
@caomengxuan666

Copy link
Copy Markdown
Member Author

Goldens-gate triage pushed as 4b0635c:

  • errors.snap — the diverging lines were all from the -o posix child-run sections; the recording predated the audit and had baked in the engine's never-exits posix behavior. Real GNU (verified per-construct with stderr-only, per-process probes — the earlier "every command class exits" oracle reading was a stdout pipe-buffering artifact over jump-exits) exits on bare assignments and special-builtin assignment failures, and for ordinary builtins/externals/functions SKIPS the command, abandons the command list (status 1) and continues (ksh93 emulation per GNU's own errors7.sub comment). Item 36 was re-implemented to that table (plus two fixes the gate exposed: a tempenv-mark leak on the early-return paths, and the ${v:=val}-on-readonly parameter-expansion arm). errors.snap re-recorded via RUBASH_REGRESSION_RECORD=1: every default-run byte kept, posix-run lines now byte-identical to bash -o posix on errors4/7.
  • comsub / heredoc / nquote — not this PR: with this branch's src/ replaced by pure origin/master (505e33d) the same three suites still fail locally while master CI is green — a local recording/environment divergence on the master side (suspect: the third_party/bash submodule state used for the last golden re-record vs this checkout), flagged here for triage. No snapshot other than errors.snap is touched.

@caomengxuan666
caomengxuan666 merged commit 59d2321 into master Oct 12, 2026
6 checks passed
@caomengxuan666
caomengxuan666 deleted the docs/posix-mode-audit branch October 13, 2026 02:00
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