Repository navigation
Conversation
Tests for a scripts/bundle.py check-compatibility command that checks one Microcosm build against one model version, the record it writes, certify-data certifying on that record, and load-time acceptance of only the recorded build, model and core. They fail before the change: the modules they import do not exist yet. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
scripts/bundle.py check-compatibility checks one UK or US build against one model version: certify-data's metadata checks, the input columns of every microdata H5 file against the build's model and the new one, and a 2,000-household sample run through .py under the new model's PyPI wheel and the chosen core. A pass writes a record bound to the SHA-256 of the build's release_manifest.json and of the wheel. certify-data --compatibility-record (and --regional-compatibility-record) certifies on that record, on the basis compatibility_checked_exact_pair, and stores it in src/policyengine/data/compatibility/<country>.json. Loading a model accepts such a certificate only for the recorded build, wheel and core, with or without network access to the manifest. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- The probe installs the checkout editable, so uv cannot run an earlier cached build of it. - A malformed probe result refuses with a reason instead of raising a validation or attribute error. - A regional release's compatibility record holds only for the installed core, whatever the national build's basis. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Install the .py checkout editable in the probe environment, so the run imports the checkout's current source rather than a wheel uv cached. - Refuse a probe result with no policyengine_version, a file entry that is not a mapping, or no SHA-256 of the sampled household IDs, with a CompatibilityCheckError naming the field. - Match the regional release's compatibility record against the running model and the installed core, not the national certificate's. - Docs: the fingerprint basis is a planned further basis; the module docstring names the tagged-layout check and the missing built_at case. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
check-compatibility must import .py without building the installed country models, whose bundle certificate need not cover the installed model version. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- check-compatibility sets POLICYENGINE_SKIP_COUNTRY_IMPORTS before it imports .py, as the TRO commands do, so importing .py does not build the installed country models and check their bundle certificate. - The regional refusal says no installed record covers the running model and core, which also covers an installed record for another model or core. - The data-certification guide describes check-compatibility and certify-data --compatibility-record, and that a record binds its core. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
From the round 3 review's code-quality notes: - _microdata_artifacts returns each file with the revision and SHA-256 it is pinned to, so mypy checks them where the record and the input-column evidence take them. - The data-certification guide says a regional record names its core instead of the core claims check, and that a qualified pair or a compatibility check's record admits a core no release claims. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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.
Fixes #788
What this does
Adds a check of one Microcosm data build (UK or US) against one model version, and a certification basis that rests on a passed check.
python scripts/bundle.py check-compatibilityruns from a checkout:certify-data's metadata checks on the build's manifest. The build must record its model and core, must not have been built with the model version being checked, and must pin every microdata H5 file by revision and SHA-256.uv runenvironment, as the regional input audit reads it.create_datasets, thenSimulationwith a household-ID row filter) under exactly the verified wheel and core. The core is the bundle's pin or--core-version. The run happens in auv run --isolated --no-project --no-configenvironment that installs from PyPI only and is given no Hugging Face token. Inside that process, only the bundle-certificate lookup in the model-version constructor is replaced.policyengine-compatibility-sample-v1:<id>, lowest first.household_net_income,income_tax;universal_credit,child_benefit,state_pension,pension_credit,housing_benefit;snap,ssi,social_security.provenance/compatibility_record.py). It names the build by the SHA-256 of its rawrelease_manifest.jsonbytes and the model by its wheel's SHA-256. It also holds the sample method, the digest of the sampled IDs, the totals, and the never-modelled and defaulted columns.Certification and load time:
certify-data --compatibility-record(and--regional-compatibility-recordfor the regional release) certifies on the new basiscompatibility_checked_exact_pair.--core-versiondefaults to the record's core.--qualified-pair-id, and a record for the build's own model.src/policyengine/data/compatibility/<country>.json.built_with_model_packagestill applies for the build's own model.provenance/manifest.py), a certificate on the new basis is accepted only when the installed records file holds a record for the fetched manifest bytes, the build, the running model and core, and the bundle's wheel.scripts/generate_trace_tros.py) re-validates a certificate on the new basis with its stored record.docs/release-bundles.md(certification rules) anddocs/engineering/skills/data-certification.md(how to run the check and certify with its record).Tests and local results
The tests were written first and each set was committed before its code. Each set was run by node ID only: no full suite and no directory.
bd3a4adthene081234tests/test_compatibility_check.py,tests/test_compatibility_certification.py: 73 functions, 79 casesModuleNotFoundError: policyengine.provenance.compatibility_record,ImportError: compatibility_check)ec9142athend9e3457(round 1 fixes)19791dcthen37d9480(round 2 fix)check-compatibilityskips the country model imports)[None] == ['1'])ba498b5(round 3 typing cleanup, no new test)ruff checkandruff format --checkare clean on the changed files.certification.release_manifest_dir,bundle.main,release_lock.py,generate_bundle_artifacts.pyand an existing line ofgenerate_trace_tros.py.check-compatibilityagainst a real build. It downloads H5 files and installs wheels, so the tests replaceuvand the downloads with fakes.Review
Three rounds of adversarial review ran on the pushed branch before this PR.
e081234):uv run --with <checkout>could reuse a wheel uv had cached from an older state of the checkout. The checkout is now installed with--with-editable.d9e3457):check-compatibilityimported .py withoutPOLICYENGINE_SKIP_COUNTRY_IMPORTS, so building the installed country models could refuse before the check ran.37d9480):ba498b5): the pinned revision and SHA-256 of each microdata file are now typed, and two places in the core guidance were corrected.Bugs left: none.
Notes left, not fixed (low priority; all three reviewers called them notes, not bugs):
certify_data_releasederives the records file's location from the bundle folder's parent. This is right for the only production caller.built_atreads its build model without--exclude-newer. The build model and core are pinned exactly, so this can only refuse, never pass wrongly.CompatibilityCheckErrorand print a traceback.regional_input_surface.Review files are kept outside the repository.
What the merge waits for
38 earlier tasks; all are complete:
None needs a deployment. This PR pins, installs and documents no package that those tasks publish.
The branch is from
mainatb1c8d2cand builds on no earlier task's branch. No deployment code changed.🤖 Generated with Claude Code