Skip to content

fix(repl): consume the engine's PROMPT_COMMAND exit jump and end the session (niubash#191) - #232

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/prompt-command-exit-jump
Oct 9, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/prompt-command-exit-jump

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

closes #191

Summary

PROMPT_COMMAND='exit' must end the interactive session. The engine half shipped in rubash#433 (4b6234c5): the pre-prompt PC runner re-arms exit_jump_pending when the PC text raises a top-level unwind (exit, or the errexit break — evalstring.c:396-403 + :618-619 re-raise after the out: cleanup), and the engine's own piped--i reader consumes it. The remaining niu-side gap was the product REPL: run_bash_prompt_command (shell.rs) dropped the re-armed state, so the session re-armed the prompt and lived on.

Fix

  • shell.rs run_bash_prompt_command now consumes the engine's re-armed jump and reports it; on the jump path the pre-PC $? snapshot restore is skipped (parse.y:3021's restore is longjmped past in GNU), so the jump's status survives in last_exit_code (PC='exit 5' keeps rc 5).
  • shell.rs run_precmd_hooks propagates the jump and skips the remaining pre-prompt work (prompt re-sync, title hooks).
  • repl.rs — both REPL loops (reedline and --noediting) consume the jump at the pre-prompt hook point: the EXIT trap runs with the jump's status and the process exits with it, the same shape as the engine's piped -i route (src/main.rs run_interactive_stdin). A plain failing PC or a PC parse error re-arms nothing: the session continues with the pre-PC $?.

Tests

  • tests/interactive.rs (ConPTY, NIU_INTERACTIVE_TESTS=1): mid-session PC='exit 5' ends the session rc 5 with the follow-up input line never run; PC='false' keeps the session alive; a PC='exit 7' from the rc kills a --noediting session before the first prompt renders (new spawn_custom_with_args driver entry).
  • tests/issue191_prompt_command_exit_jump_repl.rs (black-box): piped--i pins for the engine contract the REPL fix leans on (rc 5 / no follow-up line; plain-failure survival); -c and script forms pin that a non-interactive shell never executes the PC (it is a pre-prompt hook) and that plain exit N status propagation is untouched.

Suite status

interactive 38/38; niubash-runtime lib 385/385 (the 3 plugins::sources git-dependent tests need git on PATH — they pass with niugit prepended); repl_command, startup_files, theme_preview_channel, issue117_foreign_ps1 all green. cargo fmt clean.

@caomengxuan666
caomengxuan666 merged commit 599d3b1 into master Oct 9, 2026
3 of 9 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/prompt-command-exit-jump branch October 9, 2026 13:22
caomengxuan666 added a commit that referenced this pull request Oct 10, 2026
- Delete docs/eco-harvest-resume-wt97b.md: point-in-time lane resume/handoff snapshot; the harvest/test line now runs on GitHub Actions (eco-harvest-ci.yml) and the diagnosis lives in git history.
- CHANGELOG: add Unreleased entries for strip (#228), setup help/non-tty banner (#229), bundled niugit/ripgrep/fd + setup detection (#230/#231), PROMPT_COMMAND exit jump (#232), PS0 stderr (#233), bracketed paste (#234).

Co-authored-by: docs-audit <[email protected]>
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.

[P2] REPL 层 PROMPT_COMMAND 的 exit-jump 重武装:引擎 API 已暴露(wt99 #433 交接)

1 participant