Skip to content

Preserve history session boundaries across list mutations - #1795

Merged
tleonhardt merged 4 commits into
python-cmd2:mainfrom
mayankdhingra02:fix-history-session-mutations
Oct 31, 2026
Merged

tleonhardt merged 4 commits into
python-cmd2:mainfrom
mayankdhingra02:fix-history-session-mutations

Conversation

@mayankdhingra02

@mayankdhingra02 mayankdhingra02 commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Removing or inserting entries before session_start_index currently leaves it pointing at the wrong place, so unbounded history ranges and searches omit current-session commands or include persisted ones.

Adjust the existing boundary after successful list mutations, including slices, pop() and remove(). When a replacement spans the boundary, recognize the leading retained persisted entries by identity. In-place filtering then agrees with deleting the same entries, and equal commands from different sessions are kept distinct. Self-assignment remains stable; in-place repetition that clears history resets the boundary. truncate() uses the shared deletion handling, and the public API fix is recorded under 4.4.0 in the changelog.

Validation on macOS:

  • All 900 history tests pass, including 78 mutation/control cases covering filtering, negative/stepped slices, reordered and repeated entries, replacement iterators, failure-state preservation and composed operations. On pre-revision head a77a1a5b, 21 revised/new cases fail.
  • Required make check, make test and strict make docs-test pass on Python 3.12: 2,914 tests passed and five skipped, with 100% statement coverage for history.py (99.4% overall).
  • The exact test-group CI recipe also passes on Python 3.11, 3.13, 3.14, 3.15 and free-threaded 3.15: 2,913–2,915 passes with four to six skips per runtime. Workers were capped at two; the free-threaded interpreter reports the GIL disabled.
  • make check and strict docs also pass on the CI quality/docs Python 3.15 runtime. Wheel and source distribution builds pass.

Linux and Windows remain for CI.

Closes #1788.

Signed-off-by: Mayank Dhingra <mayankdhingra02@gmail.com>
@codecov

codecov Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.75%. Comparing base (c6c664b) to head (b1f529b).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1795   +/-   ##
=======================================
  Coverage   99.75%   99.75%           
=======================================
  Files          23       23           
  Lines        6574     6624   +50     
=======================================
+ Hits         6558     6608   +50     
  Misses         16       16           
Flag Coverage Δ
unittests 99.75% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@tleonhardt tleonhardt left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing CHANGELOG entry

#1787 added a Bug Fixes entry for truncate() under 4.4.0, and this change is the same kind of fix to a public API. Something like:

Fixed deleting, popping, removing, inserting, or slice-assigning History entries before the current session leaving session_start_index stale.

Comment thread cmd2/history.py Resolved
@tleonhardt

Copy link
Copy Markdown
Member

I merged main into this branch which includes a fix for a test that was intermittently failing for free-threaded Python variants.

Track retained persisted entries by identity when a replacement spans the
session boundary. In-place filtering now agrees with deleting the same
entries, including repeated command values.

Add filtering, reordering and failed-replacement controls, and record the
public History mutation fix under 4.4.0.

Signed-off-by: Mayank Dhingra <mayankdhingra02@gmail.com>
@tleonhardt tleonhardt self-assigned this Oct 31, 2026
@tleonhardt
tleonhardt merged commit 226c3b7 into python-cmd2:main Oct 31, 2026
32 checks passed
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.

History list mutations other than truncate() leave session_start_index stale

2 participants