Repository navigation
fix(history): grouped readers must not shadow a host HistoryProvider (#1007) - #1008
Merged
Merged
Conversation
…nixwin/niubash#508) Interactive niu REPL: a line routed through the engine's grouped reader — a `;` batch, or any token matching an alias name (oh-my-bash's `alias 1='cd -1'` makes `history 1` qualify) — ran run_script_with_history_at_line_offset, which unconditionally installed a fresh empty SessionHistory on the executor. job_builtins execute_history (builtins/history.def reads the shell's ONE list) and fc both prefer an installed session over the host HistoryProvider, so the scratch shadowed the provider's real list for the rest of the session: `history`/`fc` went permanently empty — the reported wipe. The provider IS the_history_list in the embedding (the precedence in execute_history already encodes it), so a per-read scratch must never be installed over it. run_script_grouped_at_line_offset gains an install_session flag keyed on has_history_provider; the scratch still backs the batch's expansion/record mechanics without becoming the shell's list. The PROMPT_COMMAND runner's empty-session arm moves to run_script_with_fresh_history_in_tracked with the same guard, and prepare_interactive_history no longer creates a session over a provider either — one invariant: an installed provider is never shadowed. Without a provider the scratch still installs, matching GNU's fresh per-shell history list (bashhist.c pre_process_line / shell.c reader). Regressions in tests/script_driver_history_in_regressions.rs cover both shapes: provider list surviving a grouped batch and a PROMPT_COMMAND run, plus the providerless fresh-install arms.
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 #1007. Fixes the history half of unixwin/niubash#508.
Root cause
Interactive niu routes
;-batches and alias-name-matching lines (omb'salias 1='cd -1'makeshistory 1qualify) throughrun_script_with_history_at_line_offset, which unconditionally installed a fresh emptySessionHistory.execute_history/fcprefer an installed session over the hostHistoryProvider, so the scratch permanently shadowed the provider's live list —history/fcread empty for the rest of the session.Fix — one invariant: an installed provider is never shadowed
src/script_driver.rs:run_script_grouped_at_line_offsetgainsinstall_sessionkeyed onhas_history_provider(); newrun_script_with_fresh_history_in_trackedfor the PROMPT_COMMAND empty-session arm;prepare_interactive_historyskips session creation under a provider.src/executor/public_accessors.rs:pub(crate) has_history_provider().src/executor/prompt_command.rs: empty-session arm uses the guarded fresh-scratch runner.tests/script_driver_history_in_regressions.rs: +4 tests (provider survives grouped batch; providerless still installs; PROMPT_COMMAND both arms).Providerless behavior unchanged: the scratch still installs as GNU's fresh per-shell list (bashhist.c pre_process_line). Embedding-contract fix, not a GNU semantic divergence — GNU has exactly one history list; the provider IS that list for the host.
Verification
cargo test --locked --test script_driver_history_in_regressions: 12/12cargo test --locked --lib: 771/771 (1 pre-existing ignore)echo a; echo b,alias 1='cd -1'+history 1prints the provider entry, subsequenthistoryintact.No niubash-side change required — the existing call site already routes through the fixed driver; consumption rides the normal release pin lane.