Add :load hook fired on cached fixture access#198
Merged
Conversation
Cached fixtures can hold values whose validity depends on real-world time, and downstream consumers currently have no clean place to refresh them per test run. The existing :execution and :time_access triggers only fire on cache miss / time access, leaving cache-hit reads unobservable. This adds a :load hook that fires inside Store#get when a cached reference is successfully resolved by the locator, passing (definition, value) so consumers can perform per-test refresh work (e.g. updating a stale calendar-derived attribute on a cached record). The hook only fires on a true cache hit — not on the initial build (the recursive isolation-load path can repopulate the reference within the same get call, so we capture pre-existing reference state before isolation-dependency loading) and not on the recovery rebuild path when the locator returns nil. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
mnelson
approved these changes
Apr 29, 2026
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.
Motivation
Cached fixtures can hold values whose validity depends on real-world time (e.g., a
start_datealigned to a calendar payroll boundary). Today fixtury exposes:executionand:time_accesstriggers, which only fire on cache miss / time access — there is no callback when a cached fixture is restored via the locator on each test run, so downstream consumers have no clean place to refresh stale per-test state.This adds a
:loadtrigger that fires insideFixtury::Store#getwhen a cached reference is successfully resolved by the locator, passing(definition, value)to hook callbacks. It deliberately does not fire on the cache-miss build path (:executionalready covers that) or on the recovery rebuild path when the locator returnsnil.Intended consumer usage
Implementation notes
Store#getcallsmaybe_load_isolation_dependenciesbefore the cache-hit check, and that path can recursively callgetfor the same fixture (when the fixture'sisolation_keydefaults to its own pathname). That recursive call builds and stores the reference, so the outer call would otherwise observe a synthetic cache hit on the very firstget. To distinguish a true cache hit from this build-via-isolation-recursion case, we capture the reference state before isolation-dependency loading and only fire:loadwhen a real reference existed beforehand.Bumps version to 2.4.0 (additive, no breaking changes).
Test plan
bundle exec rake test— 74 runs, 171 assertions, 0 failures:loadfires on cache hit:loaddoes not fire on initial cache-miss build:loaddoes not fire when locator returns nil (recovery rebuild):loadhooks fire in registration orderNote
Medium Risk
Touches the core fixture retrieval path (
Store#get) and introduces a new callback that can run user code on cache hits, which could affect test behavior/performance if misused.Overview
Adds a new
:loadhook that fires whenFixtury::Store#getsuccessfully resolves a cached fixture via the locator, passing(definition, value)for consumers to refresh per-test state.Updates
Store#getto avoid false positives caused by isolation-group dependency loading (only firing when a real reference existed before dependency loading) and to skip the hook when the locator returnsniland a rebuild occurs; adds tests covering these cases and bumps the gem version to2.4.0.Reviewed by Cursor Bugbot for commit 0c9168f. Bugbot is set up for automated code reviews on this repo. Configure here.