Skip to content

Certify a Microcosm build of either country by release and build name - #794

Merged
anth-volk merged 25 commits into
mainfrom
claude/7c-2-certify-build
Dec 4, 2026
Merged

anth-volk merged 25 commits into
mainfrom
claude/7c-2-certify-build

Conversation

@anth-volk

Copy link
Copy Markdown
Contributor

Fixes #793

What this changes

python scripts/bundle.py certify-build certifies a Microcosm build of either country by release and build name. It does in .py what Microcosm's UK-only tools/certify_uk_cut_in_policyengine_py.py does today, for the US as well, without depending on Microcosm's code.

python scripts/bundle.py certify-build --country uk|us --national-build <build>
    (--local-area-build <build> | --keep-regional-release | --drop-regional-release)
    [--national-release R] [--local-area-release R] [--national-data-commit SHA] [--local-area-data-commit SHA]
    [--model-version V] [--core-version V]
    [--in-place] [--worktree PATH] [--base-ref REF] [--output-dir DIR]
    [--push] [--open-pr] [--pr-base BRANCH] [--co-author "Name <email>"] [--pr-body-footer TEXT]
    [--skip-writer-check WHY] [--dry-run]

bundle.py hands certify-build to scripts/certify_build.py before building its own parser, so .py's country models load only when the command runs. Importing the script sets POLICYENGINE_SKIP_COUNTRY_IMPORTS only around its two policyengine.provenance imports and then restores the caller's value.

In order, the command:

  1. Reads each build. It checks that releases.json lists the build and has not withdrawn it, then reads the build's folder (releases/<release>/<build>/) at the Hugging Face commit that last changed it, or at --national-data-commit / --local-area-data-commit, which must be in main's history. The manifest must name the release and build and record the model and core it was made with. Release names default to the releases the bundle pins now.
  2. Chooses the model and core. The model defaults to the national build's own; the core to the bundle's pin. --core-version binds the certificate to that core and moves the pin.
  3. Checks only builds made with another model version. Each such build goes through bundle.py check-compatibility (Check one Microcosm build against one model version and certify on the result #789), and its record is passed to certify-data (--compatibility-record / --regional-compatibility-record). A build made with the target model is certified on that basis with no check, and the PR body says so. Because a record binds the certificate to the checked core, a build without a record that this core does not cover is refused before anything is written. One free-disk check before the first download is sized from the checked builds' folders.
  4. Refuses duplicate work. It refuses when an open pull request or an origin branch already certifies this national build (and local-area build, when given) for this model version, or when the certification branch already exists in the clone.
  5. Certifies. In a new worktree on certify/<country>/<national build>/<local-area build>/<model package>-<version> (the local-area part is left out without a local-area build; the same format as Check each country's newest model release on Tuesdays and Fridays #792), it runs uv sync, the compatibility checks from step 3, certify-data, uv lock, the lock and provenance regeneration (release_lock.py, generate), moves the test constants that name the old build, commit, model and basis in five test modules, runs ruff format on the modules it changed, regenerates the snapshots, and runs bundle.py check --published-spm --include-tros --strict-tros. For the UK it also runs the Universal Credit floor and adds a checklist item when it fails.
  6. Commits only certification files and writes a PR body: the builds and commits, the model and core, the core binding the new certificate records, each build's check result or the reason it had none, and a checklist of what it left to a person (constants it could not move on their own, values the other country also certifies, an old value that now stands for two new ones, a basis assertion it could not find, the Universal Credit floor).
  7. Publishes, with --push and --open-pr; otherwise it prints the commands that push the branch and open the pull request.

--in-place makes the same changes in the current checkout without committing, and writes the body and a sorted list of changed paths (<output dir>/<checkout name>.changed-paths.txt) for the scheduled workflow in #792. --dry-run prints the plan.

Failures are refusals with exit 2, never tracebacks. A failure before the commit names the commands that remove the worktree and branch; a failure after the commit names the commands that push the branch and open the pull request instead. A leftover branch from an earlier run is refused with both: how to push it if that run finished, and how to remove it otherwise.

Tests

tests/test_certify_build.py (new), with stand-ins for the Hugging Face Hub and for every command except git (which runs for real, apart from git push). Each set was committed before its change and run by node ID with -o addopts= --noconftest (the repository's conftest.py imports country models). No other test was run locally.

Tests commit Result before the change Change commit Result after
060288b (36 tests) 36 fail on assertions (34: the script is missing; 2: bundle.py exits 2 and does not list certify-build) c6f2992, 79d5d6a (typing) 36 pass
ef4da45 (16, review round 1) 16 fail on assertions ff8ee12 16 pass
c9ccf8b (7, check only other-model builds) 7 fail on assertions 60f62c0 7 pass
45a6962 (6, review round 2) 5 fail on assertions; the sixth, a stale core expectation fixed in that commit, fails at 60f62c0 42b0149 6 pass
db30f3c (1, ruff format step) fails on its assertion f317337 passes
d4bf6fb (2, branch name) 2 fail on assertions f6d1e3f 2 pass
8e9c1ee (5, review round 3) 5 fail on assertions d4d36f5 5 pass

Earlier tests were not re-run after later changes; CI runs them all. The basis rewrite was also checked by hand on a copy of the real tests/test_release_manifests.py: it changes lines 288 (US) and 319 and 1055 (UK) only. ruff format, ruff check and mypy pass on the changed files.

Review rounds

Three rounds of adversarial review, each by a fresh reviewer.

Round 1 (at 79d5d6a): 1 high, 2 medium, 2 low.

  • High: the command ran the compatibility check on builds made with the target model, which Check one Microcosm build against one model version and certify on the result #789's check refuses, so the default run always failed. Fixed (c9ccf8b, 60f62c0) by checking only builds made with another model version.
  • Medium: a US certification left the US region tests and the US model pin on the old builds. Fixed: the rewrite covers tests/test_us_regions.py and tests/test_spm_bundle_tooling.py.
  • Medium: a record binds the certificate to a core, which the command neither reported nor planned for. Fixed: the body reports the binding the certificate records, and a build without a record outside that core is refused first.
  • Low: a failed run left its worktree and branch, and several failures ended in a traceback. Fixed: a leftover branch is refused, cleanup commands are named, program failures and non-JSON Hub answers are refusals.
  • Low: the constant rewrite could move constants it should leave. Fixed: a kept local-area build on the old national commit, and values the other country also certifies, are left to a person with a checklist item.

Round 2 (at 60f62c0): all round 1 fixes confirmed; 2 medium, 1 low.

  • Medium: after the commit, a failed push named commands that delete the finished certification. Fixed: after the commit it names the push and pull-request commands.
  • Medium: the rewrite left the certificate's basis unchanged and could set the built-with version to the target model. Fixed: the basis moves in the tests that assert it, and an old value that now stands for two new ones is left to a person.
  • Low: a test from the round 1 fixes expected the wrong core. Fixed.
  • Also found while checking: a rewritten basis line can exceed the line width, so the command now runs ruff format on the modules it changed (CI runs ruff format --check).

Round 3 (at f317337): all round 2 fixes confirmed; 1 medium, 1 low.

  • Medium: a second UK test (test__given_manifest_certification__then_release_bundle_exposes_it) asserts the packaged basis and was not rewritten. Fixed: each country lists every test that asserts its packaged basis.
  • Low: a finished run without --push printed no command to publish it, and a re-run told the operator to delete it. Fixed: it prints the push and pull-request commands, and the leftover-branch refusal says how to push a finished run.
  • Code quality, fixed: every recovery command names the clone with git -C, the refusal gives the real worktree path, and the shared local-area commit item and certify() docstring describe what the code does.

Not covered by a review round: the branch-name change (d4bf6fb, f6d1e3f, from #792's format), the round 3 fixes (8e9c1ee, d4d36f5), a test docstring and the changelog entry, all made after round 3's commit.

Left, none of them a bug in a run today:

  • The format step uses the ruff the lock pins (0.12.11), while CI installs the newest ruff unpinned. They format the five modules identically today; a later ruff style change could make them differ.
  • The full-run tests do not reach the ambiguity rule, the model rewrite or the second UK basis test through the whole command; unit tests cover each.
  • The US pinning test's comment ("Built with 2.2.1; certified for 2.2.2 …") stays as it is when the rewrite moves the values below it.
  • pr_body and shell_factory are loosely typed.
  • A Hub answer that is JSON but not a list would raise AttributeError in two places; the Hub does not send one.
  • "exists; choose another --worktree" leads a retry with another folder into the leftover-branch refusal (which now also says how to push).

What the merge waits for

This branch starts from #789's branch, so until #789 merges, this PR's diff also shows #789's commits.

No deployment code is changed.

🤖 Generated with Claude Code

anth-volk and others added 25 commits December 3, 2026 22:33
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>
Tests for a `bundle.py certify-build` command that certifies a build of
either country, named by release and build: it reads each build at the
commit that published it, runs the compatibility check, certifies, and
regenerates the lock and provenance files on a new branch or in place.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`scripts/bundle.py certify-build` takes a build of either country by
release and build name and does what Microcosm's UK-only certification
script did, for both countries:

- reads each build at the commit on `main` that published its folder,
  after checking `releases.json` lists it and has not withdrawn it;
- runs the compatibility check on the national build and on the
  local-area build, and certifies on the check's record when a build was
  made with another model version;
- runs `certify-data`, relocks, regenerates the provenance files and the
  household snapshots, and runs `bundle.py check` with the TRO files;
- for the UK, runs the Universal Credit floor and leaves a failure to a
  person in the pull request body;
- commits only certification files on a new branch in a new worktree,
  and optionally pushes it and opens a draft pull request.

`--in-place` changes the current checkout instead, for a workflow that
commits the result itself, and lists the changed paths in the output
directory.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Tests for: the US region and model pins a US certification must move;
a kept local-area build on the old national commit; values the other
country also certifies; the core a compatibility record binds the
certificate to, and a build without a record outside it; a branch left
by a failed run; command failures and Hub answers that are not JSON as
refusals; relative paths; --pr-base; and importing the script without
the country models.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- A US run now rewrites the US region test pins and the bundle tooling
  test's model version, not only the UK script's three test files.
- A compatibility record binds the certificate to the core the check
  ran, as certify-data does: the plan and body now report that binding,
  read from the new certificate, and a build without a record that was
  not made with that core and does not claim it is refused before any
  worktree or download, naming --core-version.
- A kept local-area build on the old national commit, and any value the
  other country also certifies, is left to a person in the body instead
  of being rewritten.
- A branch left by an earlier run is refused before the worktree, a
  failed run names the commands that remove what it made, and failures
  of the programs it runs, and Hub answers that are not JSON, are
  refusals (exit 2) instead of tracebacks.
- Relative --worktree and --output-dir paths are read where the command
  runs; --pr-base is back from the UK script; importing the script no
  longer loads the country models.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The compatibility check refuses a build made with the model version it
is asked about, and the fake check now does the same. A build made with
the target model is certified on that basis without a check, and the
free-disk check counts only the builds the check downloads.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The compatibility check refuses a build made with the model version it
is asked about, so a default run (the national build's own model) always
failed at its first check. Each build made with another model version is
checked and certified on its record; a build made with the target model
is certified on that basis, and the pull request body says it needed no
check. The free-disk check counts only the builds the check downloads.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Tests for: the fake builds' core in the pinning test; the compatibility
basis assertion in the test that pins the country's certificate; an old
value that stands for two new ones (the UK's model and built-with
version); keeping a committed certification when the push or the pull
request fails; and the order of the cleanup commands for a leftover
branch. The fake certify-data now records the basis it would.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- The compatibility basis assertion moves with the certificate, in the
  one test that pins the country's certificate only, since the same
  literals name other bases and fixture keys elsewhere in that file; a
  missing test or literal is left to a person in the body.
- An old value that now stands for two new values (the UK's model and
  built-with version, certified for a new model on the same build) is
  left to a person instead of being rewritten to one of them.
- A failure after the commit keeps the certification: the refusal says
  how to push it and open the pull request, not to remove it.
- A leftover branch's cleanup removes its worktree first; other errors
  after the worktree exists print what the run left.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A rewritten literal can change a line's length, and the pull request's
CI checks the format, so the command runs ruff format on the files it
rewrote before regenerating the household snapshots.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The scheduled workflow names both builds in its branches; a hand-run
certification must use the same name, and another local-area build
must not count as the same certification.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Branches are now certify/<country>/<national>/<local area>/<package>-<version>,
the name the scheduled workflow gives its own, so a hand-run
certification and the workflow find each other's pull requests, and a
model version is certified again once a new local-area build is pinned.
The open-pull-request check also matches on the local-area build.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Tests for: the UK release-bundle test's basis assertion, which reads
the packaged bundle too; how to push a finished run made without
--push, and a leftover branch from such a run; and recovery commands
that name the clone with git -C. The fake certify-data now takes the
national basis from the national record alone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Rewrite the basis literal in every test that asserts a country's
  packaged basis, which for the UK includes the release-bundle test.
- Name the clone with `git -C` in every recovery command, and give the
  real path of a leftover branch's worktree.
- When an earlier run's branch exists, say how to push it if that run
  finished, before saying how to remove it.
- After a run without --push, or with --push but without --open-pr,
  print the commands that push the branch and open the pull request.
- Describe the shared local-area commit box and the certify() docstring
  as the code behaves.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
anth-volk added a commit that referenced this pull request Dec 3, 2026
The workflow runs scripts/bundle.py certify-build --in-place, which
#794 adds. Merging its reviewed branch lets this branch test that
certify-build accepts every option the workflow passes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
anth-volk added a commit that referenced this pull request Dec 3, 2026
With #794 merged in, the certification step's command, filled in from a
planned entry, parses as certify-build's own arguments and reaches them
unchanged, for both countries. certify-build's branch_name also gives the
branch the plan computes, so a pull request opened by either one stops
the other from opening a second for the same check.

These cover how the two scripts fit together, so they passed when first
run; no code changed to make them pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
anth-volk added a commit that referenced this pull request Dec 3, 2026
GitHub reported the pull request as conflicting after #789 (7c · 1)
merged into main. This branch already held #789's changes through #794's
branch, and git merges main without a conflict; the merge commit's
files are the same as the branch head's. It gives the two branches one
merge base again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@anth-volk
anth-volk marked this pull request as ready for review December 3, 2026 23:59
@anth-volk
anth-volk merged commit dba9b97 into main Dec 4, 2026
16 checks passed
anth-volk added a commit that referenced this pull request Dec 4, 2026
GitHub marked the pull request as conflicting after #794 merged,
because the branch and main had two merge bases. git merges main
without a conflict, and the result's files are the same as the
previous head's.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
anth-volk added a commit that referenced this pull request Dec 4, 2026
certify-build (#794) and the compatibility workflow name the local-area
build in the certification branch, check the disk only for the builds the
compatibility check downloads, and certify-build gains --pr-base. The
workflow queues waiting runs, still checks one country when the other can't
be planned, and fails a certification step after 270 minutes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

Certify a Microcosm build of either country by release and build name with one command

1 participant