Skip to content

Resize partial evaluation histories safely - #1241

Open
OskarEichler wants to merge 1 commit into
ruby:masterfrom
OskarEichler:codex/eval-history-resize
Open

Resize partial evaluation histories safely#1241
OskarEichler wants to merge 1 commit into
ruby:masterfrom
OskarEichler:codex/eval-history-resize

Conversation

@OskarEichler

Copy link
Copy Markdown
Contributor

Summary

Shrink evaluation history from the entries actually present rather than slicing with the configured maximum as an array index.

Reproduction

When a history configured for 100 entries currently contains only three, resizing it to two slices from index 98 and replaces the contents with nil. The candidate retains the last two entries and does nothing when the populated history is already within the new limit.

Verification

  • focused partial-history grow/shrink model
  • current and cumulative candidate suites: 402 tests / 2,488 assertions, zero failures/errors and three omissions
  • all 111 Ruby files pass syntax
  • RuboCop checks 113 files with no offenses
  • RDoc, candidate packaging and Rails 8.1.3.1 loading pass

Compatibility

Unlimited and non-shrinking sizes remain unchanged; partial histories now follow the configured limit safely. Prepared with AI-assisted source review; no repository tests were changed.

if size != 0 && size < @size
@contents = @contents[@size - size .. @size]
if size.positive? && @contents.size > size
@contents = @contents.last(size)

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.

Looks good 👍
Can you add a test for this?
Adding a test that does the below in test_eval_history.rb would be enough

out, err = execute_lines(
  "IRB.CurrentContext.eval_history = 2",
  "__",
  conf: { EVAL_HISTORY: 5 }
)

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.

2 participants