Repository navigation
fix(history): carry history_base + hist_last_line_added through the HistoryProvider contract (#2007, #2006) - #2144
Merged
Conversation
rubash#2007: after HISTSIZE trimming, the provider (niu REPL) path renumbered `history` output from 1; GNU keeps the global continuous numbering (PTY evidence p3-gnu-04 vs p3-hist-04: 399/400/401, not 1/2/3). The session path already matches GNU (PR #2021 pins); the provider path could not, because the HistoryProvider contract carried no display base. GNU specification: - lib/readline/history.c:113 `int history_base = 1` — the list number of entries[0]; builtins/history.def display_history numbers entries from it, and history.def:203-216,243-260 offset positive `history -d` operands by history_base. - history.c:389-404 (stifled add_history): dropping the oldest entry bumps history_base; history.c:675-698 (stifle_history) sets it to the dropped count. The global numbering survives trimming; it never restarts at 1. Fix (the issue's candidate solution A): - HistoryProvider gains `history_base()` with the unstifled GNU initial value (1) as the default impl; hosts that stifle their store override it with the advanced base (src/history.rs). - The provider branch of the history builtin fetches the channel once and uses it for both the display numbering (builtins/history.rs execute_with_history gains the parameter; the session path keeps its own shell.base) and the positive `history -d` operand offset (executor/job_builtins.rs), replacing the hard-wired base=1. Tests (tests/issue2006_2007_history_faces.rs): the provider-path stifle pin is un-ignored and passes (store base 4 -> display 4,5,6); new pin covers provider `history -d 5` against base 4. The #[ignore] removal is the acceptance step the issue adjudicated; the fixture adopts the channel explicitly because a stifled store's base is host-private state no default can synthesize. A/B: the pre-fix failure (" 1 echo h3..." vs " 4 ...") and the post-fix pass were both produced from this branch base d5c172a (origin/master tip). One environment-bound pre-existing failure (issue1830 interactive_histfile_null, Windows path-mangled diagnostic) fails identically on the pristine base and is not attributed here. Commit disclosed as --no-verify: the pre-commit `cargo fmt --check` hook cannot run in this shell (cargo fmt: os error 206, filename or extension too long); rustfmt --edition 2021 --check was run explicitly over all four changed files and is clean. Fixes #2007
…contract
rubash#2006: on the provider (niu REPL) path, `fc -l` listed the fc
command itself and the whole history; GNU excludes the fc line (PTY
evidence p3-gnu-03 vs p3-hist-03: GNU's list ends at `echo G2`, niu
printed `6 fc -l` too).
GNU specification:
- builtins/fc.def:328-335: "the current command line ... is already
part of the history list by the time we get to this point ... we
check hist_last_line_added" — `rh = remember_on_history || ...;
last_hist = i - rh - hist_last_line_added`.
- bashhist.c:174 (`int hist_last_line_added;`, zero-initialized),
cleared per line by maybe_add_history (bashhist.c:757-764), set when
the line was actually recorded by really_add_history (957-964).
- rh is ON for the interactive shapes the formula targets: shell.c
init_interactive arms remember_on_history (shell.c:1830-1842).
- The not-listing edit form deletes the fc line from THE history list
first (fc.def:403-421 -> bash_delete_last_history, bashhist.c:392-417).
The provider call site hard-coded all three inputs (history_base=1,
last_line_added=false, remember_on_history=false), so last_hist
pointed at the fc line and the default listing swept the whole store.
Fix: HistoryProvider gains `last_line_added()` (commit 1 added the
base channel); the fc provider branch passes the two channels plus
rh=true — the bridge replaces the engine's interactive recording, so
the interactive default applies — and the edit-form drop reaches the
host store via the existing history_provider_drop_last when no engine
session owns the list. Both trait defaults mirror the GNU C
initializers, so providers predating the contract keep compiling and
behave exactly as before.
Tests (tests/issue2006_2007_history_faces.rs): the provider-path fc
pin is un-ignored and passes (store [alpha, beta, fc -l], last_added
-> output "1 alpha / 2 beta", no fc line); new pin covers a stifled
store (base 5): default `fc -l` numbers 5,6,7 and excludes the fc
line, `fc -l 6 8` resolves through the base.
A/B: pre-fix failure ("3\t fc -l" listed; whole history) reproduced on
this branch's base; post-fix all pins pass. Environment-bound
pre-existing failures (issue1830/issue1852 session-path diagnostics,
Windows path-mangled text) fail identically on the pristine base and
are not attributed here.
Commit disclosed as --no-verify: the pre-commit `cargo fmt --check`
hook cannot run in this shell (cargo fmt: os error 206, filename or
extension too long); rustfmt --edition 2021 --check was run explicitly
over the three changed files and is clean.
Fixes #2006
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.
Summary
Two history-face bugs from the niubash#670 PTY audit, same root: the
HistoryProvidercontract (the niu REPL bridge) carried less state than the engine's own session history, so the provider path could not reproduce GNU faces the session path already matches (PR #2021 pins).Base:
d5c172ae(origin/master tip at branch time).Commit 1 — rubash#2007: HISTSIZE trimming renumbers
historyfrom 1PTY evidence
p3-gnu-04vsp3-hist-04: GNU prints399/400/401afterHISTSIZE=3; niu renumbered1/2/3.lib/readline/history.c:113(history_base = 1);history.defdisplay +history.def:203-216,243-260(history -dpositive operands offset by history_base); stifling advances the base (history.c:389-404stifledadd_history,history.c:675-698stifle_history) — global numbering never restarts.HistoryProvider::history_base()with the unstifled GNU initial value as default; provider display numbering andhistory -doperand offset consume it instead of hard-wired 1.Commit 2 — rubash#2006:
fc -llists the fc command itself and the whole historyPTY evidence
p3-gnu-03vsp3-hist-03: GNU'sfc -lexcludes the fc line; niu listed everything including6 fc -l.builtins/fc.def:328-335last_hist = i - rh - hist_last_line_added("the current command line is already part of the history list... we check hist_last_line_added");bashhist.c:174,957-964(hist_last_line_addedset byreally_add_history);fc.def:403-421edit-formbash_delete_last_history(bashhist.c:392-417).HistoryProvider::last_line_added()(default = the C zero initializer); the fc provider call site stops hard-codinghistory_base=1, last_line_added=false, remember_on_history=false— the bridge is the interactive recording path (shell.c:1830-1842 init_interactivearmsremember_on_history), and the edit-form drop now reaches the host store via the existinghistory_provider_drop_last.Both defaults mirror GNU's C initializers, so out-of-tree providers keep compiling and behaving as before; hosts following the save-at-accept contract override the channels.
Tests
tests/issue2006_2007_history_faces.rs:provider_path_history_numbering_survives_stifle— un-ignored (the acceptance step the issues adjudicated; the fixture adopts the channels explicitly since a stifled store's base is host-private state), plus newprovider_path_history_delete_offset_uses_base(commit 1).provider_path_fc_list_excludes_itself— un-ignored, plus a base-awarefc -lrange pin (commit 2).A/B on base
d5c172ae: both provider pins fail pre-fix with exactly the issue outputs (3\t fc -llisted;1/2/3renumbering); post-fix all pins pass. Pre-existing environment-bound failureissue1830 interactive_histfile_null(Windows path-mangled diagnostic) fails identically on the pristine base — not attributed to this PR.Disclosure: commits are
--no-verify— thecargo fmt --checkhook cannot run in this shell (cargo fmt: os error 206, filename too long);rustfmt --edition 2021 --checkwas run explicitly over every changed file and is clean.Fixes #2007
Fixes #2006