Skip to content

Downstream preflight + invalidated_caches guards#477

Merged
MaxGhenis merged 4 commits intomasterfrom
add-downstream-preflight
Apr 18, 2026
Merged

Downstream preflight + invalidated_caches guards#477
MaxGhenis merged 4 commits intomasterfrom
add-downstream-preflight

Conversation

@MaxGhenis
Copy link
Copy Markdown
Contributor

@MaxGhenis MaxGhenis commented Apr 18, 2026

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.py instantiates CountryTaxBenefitSystem() from the currently-published policyengine-us and policyengine-uk on every core PR. No microdata, no HF token, runs in ~20s.

Catches the class of cross-repo regressions that the existing SmokeTestForMultipleVersions job misses — breakdown-validator errors at parameter load, init-time attribute assumptions, and any other changes that happen to break downstream country models. The existing RUN_SMOKE_TESTS-gated microsim test is left alone (needs credentials and is a separate decision).

Workflow is also extended to install policyengine-uk alongside policyengine-us.

Motivation: #449 (breakdown validator WARNING → ERROR) silently broke 15 policyengine-us param files. #471 + #474 silently broke policyengine-uk main CI and policyengine-uk-data for ~24h. Core didn't exercise downstream, so nothing alerted.

2. invalidated_caches guards

Follow-up to #474's _fast_cache guards. Country-package subclasses that override __init__ without super().__init__ skip initialising self.invalidated_caches. purge_cache_of_invalid_values now early-returns if it's missing, invalidate_cache_entry lazily initialises it. Same defensive pattern as _fast_cache.

Test plan

  • tests/core/test_fast_cache_guards.py now has 5 tests covering both _fast_cache and invalidated_caches paths
  • Full core suite: 512 passed (up from 510 pre-PR)
  • New preflight tests pass locally against policyengine-us==1.647.0 + policyengine-uk==2.88.0
  • Ruff format/check clean
  • CI: Test matrix green on 3.9–3.14 (ubuntu + windows)
  • CI: SmokeTestForMultipleVersions now runs the two new asserts for both us and uk

MaxGhenis and others added 2 commits April 17, 2026 20:03
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>
@MaxGhenis MaxGhenis changed the title Add downstream preflight smoke tests against published country models Downstream preflight + invalidated_caches guards Apr 18, 2026
MaxGhenis and others added 2 commits April 17, 2026 20:10
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>
@MaxGhenis MaxGhenis merged commit 51efa27 into master Apr 18, 2026
22 checks passed
@MaxGhenis MaxGhenis deleted the add-downstream-preflight branch April 18, 2026 00:27
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.

1 participant