Downstream preflight + invalidated_caches guards#477
Merged
Conversation
Context: PR #474 landed the fix for a `_fast_cache` AttributeError that only surfaced in `policyengine-uk` / `policyengine-uk-data` because core's Microsimulation __init__ behavior changed subtly. Similarly, the breakdown-validator tightening in #449 silently broke `policyengine-us`'s `additional_tax_bracket` param until downstream pypkg integration tests tripped on it. The existing `SmokeTestForMultipleVersions` job already installs policyengine-us from PyPI, but the test it runs (`tests/smoke/test_us.py`) is gated by `RUN_SMOKE_TESTS=1` while CI sets `RUN_SMOKE_TESTS: "0"`, so it's always skipped. Add `tests/smoke/test_country_init.py` that simply instantiates `CountryTaxBenefitSystem()` for policyengine-us and policyengine-uk. No microdata required, no HF token required, runs in seconds. This catches any future core change that breaks country-model init — breakdown validator errors, missing private attrs, etc. — before it hits downstream. Also extends the workflow to install policyengine-uk alongside policyengine-us so both tests have something to exercise. Leaves the existing `test_us.py` / `RUN_SMOKE_TESTS` env-var gating alone — those tests need microdata credentials and are a separate decision. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Follow-up to PR #474's _fast_cache guards. The same pattern applied to the other private cache attribute on Simulation: country-package subclasses that override __init__ without calling super().__init__ can skip initialising self.invalidated_caches, so purge_cache_of_invalid_values and invalidate_cache_entry now fall back gracefully instead of raising AttributeError. purge_cache_of_invalid_values: early-return if invalidated_caches is missing. invalidate_cache_entry: lazily initialise invalidated_caches with the new entry if it's missing. Extends tests/core/test_fast_cache_guards.py with two new regression tests for the invalidated_caches path. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
policyengine-us 1.647.0 depends on spm-calculator (>=0.3.1), but the 3.13+ workflow branch uses --no-deps to dodge pytest-dependency build issues and manually reinstalls a subset. Add spm-calculator to that subset so the new preflight smoke test can instantiate CountryTaxBenefitSystem() on 3.13/3.14. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…eflight # Conflicts: # uv.lock
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 defensive additions to core's
Simulation/ CI based on patterns that bit downstream over the last day:1. Downstream preflight smoke tests
tests/smoke/test_country_init.pyinstantiatesCountryTaxBenefitSystem()from the currently-publishedpolicyengine-usandpolicyengine-ukon every core PR. No microdata, no HF token, runs in ~20s.Catches the class of cross-repo regressions that the existing
SmokeTestForMultipleVersionsjob misses — breakdown-validator errors at parameter load, init-time attribute assumptions, and any other changes that happen to break downstream country models. The existingRUN_SMOKE_TESTS-gated microsim test is left alone (needs credentials and is a separate decision).Workflow is also extended to install
policyengine-ukalongsidepolicyengine-us.Motivation: #449 (breakdown validator WARNING → ERROR) silently broke 15
policyengine-usparam files. #471 + #474 silently brokepolicyengine-ukmain CI andpolicyengine-uk-datafor ~24h. Core didn't exercise downstream, so nothing alerted.2.
invalidated_cachesguardsFollow-up to #474's
_fast_cacheguards. Country-package subclasses that override__init__withoutsuper().__init__skip initialisingself.invalidated_caches.purge_cache_of_invalid_valuesnow early-returns if it's missing,invalidate_cache_entrylazily initialises it. Same defensive pattern as_fast_cache.Test plan
tests/core/test_fast_cache_guards.pynow has 5 tests covering both_fast_cacheandinvalidated_cachespathspolicyengine-us==1.647.0+policyengine-uk==2.88.0SmokeTestForMultipleVersionsnow runs the two new asserts for both us and uk