Repository navigation
test(source): pin sourced exit N shell-termination semantics (rubash#426) - #457
Merged
Merged
Conversation
…h#426) Issue rubash#426 (wt92/harvest divergence group 6): a sourced file whose body runs `exit 0` did not terminate an interactive `niu -i` session — the sourced exit surfaced as a script-level status instead of a session-level exit jump, so the REPL kept prompting and read the rest of stdin while GNU bash dies (builtins/source.def -> evalfile.c evalfile_internal -> evalstring.c parse_and_execute runs in the CURRENT shell; the exit builtin's jump_to_top_level(EXITPROG) unwinds past evalfile into reader_loop, evalstring.c:396-403/:618-619, and exit_shell carries N). Root cause and fix: the engine-side defect was the grouped runner converting ExecuteError::ExitCode into a plain status without recording the jump, and the interactive reader never consulting it. That invariant was repaired by the rubash#433 work (4b6234c: run_source_impl marks exit_jump_pending on ExitCode/FatalFunctionError at the list top; run_interactive_stdin accept_line ends the session on a non-parse jump and finish_shell carries the jump's status). At this HEAD the sourced-exit path is GNU-correct in every reachable shape, so this change pins the contract with a dedicated black-box suite instead of re-touching the engine: tests/issue426_sourced_exit_regressions.rs (11 tests, CARGO_BIN_EXE_rubash, piped-`-i` interactive probes in the #433 harness shape): - `-c`: sourced `exit N` exits N, trailing text never runs (N = 3 and the issue's `exit 0`); - nested `.`: the inner file's exit unwinds both source frames (rc 7); - `exit N` inside a function called from a sourced file still ends the shell (rc 9); - `return N` keeps its source-local unwind: sourcing stops, the shell lives on, $? = 4; - EXIT trap fires at the sourced exit's boundary with the sourced status and cannot resurrect the shell (rc 5 / rc 9); - interactive piped-`-i`: sourced `exit 0` ends the session before the next line is read (exactly one prompt, rc 0); `exit 5` ends with rc 5 and the trailing input is never echoed or run; `return 4` keeps the session alive with $? = 4; nested-source exit and the EXIT-trap shape. Also sweeps two rustfmt-only fixes (src/executor/external_finish.rs, tests/cat_redirect_stream_regressions.rs) left unformatted by a prior merge — the pre-commit cargo fmt gate requires the clean tree. Related suites green: issue297_300_interactive_init_regressions, issue343_345_trap_regressions, issue419_console_repl_channel_regressions, issue433_prompt_command_exit_regressions, issue70_subshell_trap_regressions, host_internal_trap_suppression, issue312_interactive_noedit_defaults. Closes #426.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
closes #426
Summary
Issue #426 (wt92/harvest divergence group 6): a sourced file whose body runs
exit 0did not terminate an interactiveniu -isession — the sourced exit surfaced as a script-level status instead of a session-level exit jump, while GNU bash terminates the whole shell (builtins/source.defsources throughevalstring.c parse_and_executein the CURRENT shell; theexitbuiltin'sjump_to_top_level(EXITPROG)unwinds pastevalfileintoreader_loop, evalstring.c:396-403/:618-619, andexit_shellcarries N).Root cause / state of the engine
The engine-side defect was the grouped runner converting
ExecuteError::ExitCodeinto a plain status without recording the top-level jump, and the interactive reader never consulting it. That invariant was repaired by the rubash#433 work (4b6234c:run_source_implmarksexit_jump_pendingonExitCode/FatalFunctionErrorat the list top;run_interactive_stdin'saccept_line!ends the session on a non-parse jump, andfinish_shellcarries the jump's status). At this HEAD the sourced-exit path is GNU-correct in every reachable shape (verified: -c rc propagation, piped--isession death with the jump's status, nested., exit-in-function, EXIT-trap interplay,returnlocality, ConPTY probe).This PR therefore pins the contract with a dedicated black-box suite so the sourced-exit path cannot regress into a script-exit again, and closes the issue.
Tests
New
tests/issue426_sourced_exit_regressions.rs(11 black-box tests,CARGO_BIN_EXE_rubash, piped--iinteractive probes in the #433 harness shape):-c: sourcedexit Nexits N, trailing text never runs (N = 3 and the issue'sexit 0).: the inner file's exit unwinds both source frames (rc 7)exit Ninside a function called from a sourced file still ends the shell (rc 9)return Nkeeps its source-local unwind: sourcing stops, the shell lives on, $? = 4-i: sourcedexit 0ends the session before the next line is read (exactly one prompt, rc 0);exit 5ends with rc 5;return 4keeps the session alive; nested-source exit and the EXIT-trap shapeAlso sweeps two rustfmt-only fixes (
src/executor/external_finish.rs,tests/cat_redirect_stream_regressions.rs) left unformatted by a prior merge — the pre-commitcargo fmtgate requires the clean tree.Related suites green: issue297_300_interactive_init_regressions, issue343_345_trap_regressions, issue419_console_repl_channel_regressions, issue433_prompt_command_exit_regressions, issue70_subshell_trap_regressions, host_internal_trap_suppression, issue312_interactive_noedit_defaults.