Skip to content

fix: honor the configured history_limit instead of a hardcoded cap - #245

Merged
FalkWoldmann merged 2 commits into
httpmock:masterfrom
danieleades:fix/history-limit
Aug 7, 2026
Merged

FalkWoldmann merged 2 commits into
httpmock:masterfrom
danieleades:fix/history-limit

Conversation

@danieleades

@danieleades danieleades commented Jul 11, 2026 •

Copy link
Copy Markdown
Contributor

Problem

HttpMockServerBuilder::history_limit(...) (and the --request-history-limit CLI flag in standalone mode) was dead plumbing: the builder stored the value, but build() discarded it, and the request-history trim in serve_mock used a hardcoded > 100 check marked // TODO: Make max history configurable.

Fix

  • Introduce DEFAULT_HISTORY_LIMIT = 100 and store the configured limit in MockServerState.
  • build() now passes history_limit.unwrap_or(DEFAULT_HISTORY_LIMIT) through.
  • The trim check uses the configured limit.
  • HttpMockStateManager::default() changes from new(usize::MAX) to new(DEFAULT_HISTORY_LIMIT) — effective behaviour is unchanged since the old hardcoded cap was 100 regardless of that parameter.
  • Adds unit tests for the cap and the default.

Notes

  • Out-of-the-box behaviour is unchanged (default cap stays 100); the setting is simply no longer ignored.
  • There is a pre-existing off-by-one: the trim runs when len > limit before pushing, so the history stabilises at limit + 1 entries. This PR preserves that behaviour (and the new test documents it) rather than silently changing it — happy to fix it here or in a follow-up if preferred.

Verification

cargo test --all-features unit + integration suites pass locally (124 + 137 tests).

HttpMockServerBuilder::history_limit stored the value but build()
ignored it, and the request-history trim used a hardcoded cap of 100
with a TODO. Store the limit in MockServerState and use it in the trim
check. The default stays 100, so out-of-the-box behavior is unchanged.
@codecov

codecov Bot commented Jul 11, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.96970% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/server/state.rs 96.77% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@FalkWoldmann

Copy link
Copy Markdown
Member

Thanks! The 100 + 1 thing seems unintended, so feel free to create a follow-up :)

@FalkWoldmann
FalkWoldmann merged commit dec9b7f into httpmock:master Aug 7, 2026
9 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.

2 participants