Skip to content

Test policyengine-us main against the Core under test on each PR - #635

Merged
hua7450 merged 6 commits into
masterfrom
test-policyengine-us-main
Dec 2, 2026
Merged

hua7450 merged 6 commits into
masterfrom
test-policyengine-us-main

Conversation

@hua7450

@hua7450 hua7450 commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

What this fixes

Core 3.33.13 broke a policyengine-us test on main within minutes of its release, and nothing in Core's CI could have shown it first.

Time (UTC, 2026-10-27) Event
14:48 PolicyEngine/policyengine-us#10400 adds core/test_social_security_input_state_machine.py, whose backend runs Core's installed SimulationBuilder, Simulation, holder and dumper source in namespaces it builds.
16:42 #624 merges: build_default_simulation now calls operator.index, and restore_simulation calls a new _restore_count.
16:43 3.33.13 is on PyPI.
from 16:45 Every policyengine-us PR and release run fails that test with NameError: name 'operator' is not defined; policyengine-us CI installs the newest Core on every run. PolicyEngine/policyengine-us#10504 gives the backend both names.

#624 itself is correct. Core already checks itself against policyengine-us, but SmokeTestForMultipleVersions passed on #624 because it doesn't test enough to catch this:

  • It installs a pinned release, policyengine-us==2.42.13, which predates the test.
  • It runs Core's smoke tests, which check that the US and UK systems load, not any policyengine-us test.

Nothing checks again after the PR either: Publish in push.yaml has no needs.

What changes

A new PR job, PolicyEngineUSMain ("Test policyengine-us main against this Core"), sits beside the smoke job:

  1. It checks out policyengine-us main and installs it the way its own CI does: its lock, with the newest Core release.
  2. It runs the tests listed in .github/requirements/policyengine-us-main-tests.txt with that release, with a JUnit report.
  3. It installs this checkout's Core over the release, checks that direct_url.json points at the checkout (the two versions can be equal before a release bump), and runs uv pip check.
  4. It runs the same tests again with the same pytest command and Hypothesis seed, so both runs draw the same examples.
  5. .github/country_main_tests.py compare sorts the results, and report puts them on the PR.

How a break shows

A Core change can break policyengine-us on purpose, with the policyengine-us fix landing after the Core release. So a break does not fail the job. Instead:

  • A grey neutral check, policyengine-us compatibility, is titled "This Core breaks N policyengine-us test(s)" and lists them in its summary.
  • github-actions[bot] posts one comment listing the tests, with the advice to merge if the change is intended and fix policyengine-us right after the release. Later runs edit that comment rather than adding new ones; once nothing breaks, it says so.
  • Without breaks, the check is green and no comment is posted.

A break is a test that fails with this Core but did not fail with the release, or a test that passed with the release in a file this Core cannot collect. A test that fails with both Cores is policyengine-us's own failure, so it only gets a warning, as does a failure in a file the release could not collect. A test that passed with the release and is skipped with this Core, on its own or because its file skips itself, is not a break, but its coverage is lost: it gets a warning and its own list in the check.

That rule addresses why #546 pinned the smoke bundle: country-side failures kept turning Core's CI red. policyengine-us main is sometimes red for its own reasons. Release run 40544014984, the first on 3.33.13, failed this Core test and also core/test_mt_state_agi_invariants.py, a policyengine-us failure fixed by PolicyEngine/policyengine-us#10496. This job would blame Core only for the first.

When the job fails

The job fails only when its comparison cannot be trusted:

  • pytest stopped early or ran nothing (exit status 2 to 5). A run whose tests fail or whose files cannot be collected (status 1) goes on to the comparison.
  • A run wrote no JUnit report, the release's run collected no tests (only files that could not be imported or that skipped themselves while being collected), or this Core's run recorded no tests.
  • A test that passed with the release did not run with this Core, with no collection error to explain it.

The test list

The list starts with 13 fast files that drive Core internals: simulations, holders, data storage, tools, populations, parameters and reforms. It includes the state machine test. Together they took about 95 seconds in policyengine-us release run 40544965026, against 96 minutes for its whole tests/core.

  • A deselect <path>::<test> line leaves one test out. The list deselects one test in test_uprating_extensions.py that builds the default Microsimulation, downloading about 830 MB of microdata only to read parameters.
  • A listed file that policyengine-us renames or removes is skipped with a warning, so the job cannot fail for that reason.

Permissions

The job gets checks: write and pull-requests: write to post the check and the comment; no secrets or setup are needed. The job summary also keeps the full result. On a PR from a fork the token is read-only, so the report step warns and the job still passes, with the result in the job summary.

Tests

  • tests/core/test_country_main_tests.py, 29 tests, covering:

    • the comparison: breaks, files this Core cannot collect, failures with both Cores, newly skipped tests and files, missing tests, missing reports, files the release could not collect, and a release run that collected nothing;
    • the PR report, against a recorded fake GitHub API: a new comment, an updated comment, no comment without breaks, the update once fixed, and other authors' comments left alone;
    • the warning without write access;
    • run against real pytest exits: passing, failing, a collection error, no tests and interrupted;
    • file selection, the list's format, and the job's steps and permissions.
  • These tests were not run locally after the last four commits; CI runs them. They passed with the rest of this PR's checks (21 of 21) on 17a9e69, including ruff format --check and actionlint. a08b130 adds the release-baseline check, the newly skipped list and the job summary; d45823a treats files that skip themselves during collection as not collected.

  • Live check on 2026-12-02, on this PR and on a throwaway test PR, Test only, do not merge: check the policyengine-us break report #680 (now closed). Test only, do not merge: check the policyengine-us break report #680 was this branch plus a new module-level name used in build_default_simulation, the kind of change 3.33.13 made:

    Run Job policyengine-us compatibility check Bot comment
    This PR at 17a9e69 passed green, "No policyengine-us test breaks": 492 passed with the release and with this Core none
    Test only, do not merge: check the policyengine-us break report #680 with the change passed grey, "This Core breaks 1 policyengine-us test": TestSocialSecurityInputStateMachine::runTest one comment listing it
    Test only, do not merge: check the policyengine-us break report #680 after reverting the change passed green the same comment, edited to "No policyengine-us test breaks with this Core any more"
  • An earlier local replay against Restore simulations with no persons or empty groups, and refuse non-integer default counts #624's merge commit (bb7660e), with 3.33.12 as the release, found the state machine test as the one break. With 3.33.13 as the release and master as the candidate, it found no break, since the test failed with both.

Open question for review: should the list move to policyengine-us, so the people writing those tests maintain it?

🤖 Generated with Claude Code

Core 3.33.13 broke policyengine-us main's state machine test within
minutes of release, while the country smoke job passed: it installs a
pinned policyengine-us release and only checks that systems load. The new
PolicyEngineUSMain job runs a list of fast policyengine-us tests that drive
Core internals, with the Core release and then with this checkout, and
fails only on tests that fail with this Core alone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@MaxGhenis MaxGhenis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agent review for Max, written by Claude Code for Max Ghenis.

The new job can go green without running the policyengine-us tests, and that needs a fix before its result can be relied on (00167396 reviewed; the PR has no earlier reviews or comments).

P1. Green result after an incomplete run. pr.yaml:167 and 175 end in || true, so pytest's exit status is lost. compare then looks only at tests present in the candidate report. A test that passed with the release and is missing from the candidate report counts for nothing. I ran country_main_tests.py compare at this head on hand-written JUnit files:

Release report Candidate report Expected Actual
2 passed empty (pytest exit 5) fail exit 0, "0 tests ran with this Core [...] Every test passes with this Core."
2 passed 1 passed, the other missing (pytest exit 2) fail exit 0, "Every test passes with this Core."
1 collection error the same collection error fail or inconclusive exit 0, with one warning
1 collection error 1 passed, 1 failed inconclusive exit 1, "This Core breaks t::b"

pytest writes the JUnit file in all these cases: wrap_session calls pytest_sessionfinish after an interrupt too, and exit 5 means no tests were collected. Two runs of the workflow's own command, one with an empty test file and one with a KeyboardInterrupt in a test, also ended green (reported, not rerun here).

The third row is the likely one. Without --continue-on-collection-errors, pytest stops before the first test when any file fails to collect, and neither the command here nor policyengine-us's configuration sets that flag. If policyengine-us main has one listed file that does not import, both runs stop, no test in the other 12 files runs, and any Core break in them passes. That is the state the job is designed to tolerate (the script's docstring: "policyengine-us main is sometimes red for its own reasons"). The fourth row is the reverse: if this Core fixes the collection error, tests that were already failing in the other files are blamed on it.

Suggested fix:

  • Pass --continue-on-collection-errors in both runs. Assertion and collection failures then end in exit 1 and still go to compare.
  • Run pytest without xargs (for example, mapfile -t files < ../selected.txt), because GNU xargs turns any pytest status from 1 to 125 into 123. Then capture the status in place of || true, and fail the step when it is above 1.
  • In compare, fail when the candidate report has no tests, or lacks a test that passed with the release.

The job's test at test_country_main_tests.py:137-169 compares the command strings and does not drive these exits.

P2. One listed file downloads the default microdata. policyengine-us-main-tests.txt:25 selects test_uprating_extensions.py, where one test calls Microsimulation() only to read parameters. With no dataset, that resolves to a Hugging Face download of a file that policyengine-us puts at about 830 MB. Each job on a fresh runner would download it, and both runs would build that simulation. I read this path and did not run it. Core's smoke job avoids this today: RUN_SMOKE_TESTS is "0", and test_country_init.py says its tests "don't need a dataset". Deselect that test, or have policyengine-us read system.parameters there.

P2. The summary says more than the reports show. country_main_tests.py:97-98 prints "Every test passes with this Core." when a candidate test was skipped (2 passed, then 1 passed and 1 skipped: exit 0, that line), and when none ran. Line 95 calls shared failures "policyengine-us's own". Your second replay row shows otherwise: the test fails with 3.33.13 and with master because a Core release changed, and it passed with 3.33.12. Say "failing with both Cores", and count skips.

P3. The install step (pr.yaml:171-172) has no uv pip check. The smoke job runs one (pr.yaml:115-116), and this job is where a Core bound that conflicts with policyengine-us main would show.

Until the P1 is fixed, green does not mean the tests ran, which bears on your first open question (block merging, or only report).

hua7450 and others added 3 commits November 30, 2026 10:56
Address review: `|| true` hid pytest's status, and compare looked only at
tests in the candidate report, so an empty or cut-short run went green.

- Run both passes through `country_main_tests.py run`, with
  --continue-on-collection-errors, and fail on any pytest status but 0 or 1.
- compare fails when this Core's run recorded no tests, a report is missing,
  or a test that passed with the release did not run. A failure in a file
  the release could not collect is a warning, not a break.
- The summary counts skips and says "failing with both Cores".
- Deselect the uprating test that downloads the default microdata.
- Check the installed dependencies after installing this Core.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A Core change can need a policyengine-us fix after its release, so a test
this Core breaks no longer fails the job. compare writes its result, and
the new report step posts a neutral "policyengine-us compatibility" check
listing the breaks (successful when there are none) and one bot comment,
updated on later runs. A file this Core cannot collect counts as a break.
The job still fails when the comparison cannot be trusted: a run wrote no
report or no tests, or a test that passed with the release did not run for
any reason the reports show.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
hua7450 and others added 2 commits December 2, 2026 13:43
…ummary

- compare fails when the Core release's run collected no tests (only
  collection errors), instead of calling every entry a failure with both
  Cores and reporting no breaks.
- A test that passed with the release and is skipped with this Core is a
  warning and listed in the check summary.
- The compare step appends its result to the job summary, which the PR
  comment and the no-write-access warning point to.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- The release-baseline check ignores modules that skipped themselves while
  being collected, as it ignores modules that failed to import, so a release
  run with only those entries fails the job instead of reporting no breaks.
- Tests in a module this Core skips while collecting are newly skipped (a
  warning, listed in the check) rather than missing (a job failure).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

hua7450 commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

Codex reviewed d45823a4 and recommends approval. Both findings are resolved. The comparison rejects baselines that collect zero tests and reports candidate skips as advisory warnings.

All 29 focused tests passed locally, and all 21 checks passed on this commit, including the policyengine-us compatibility job. CI run

@hua7450
hua7450 merged commit ee180c6 into master Dec 2, 2026
21 checks passed
@hua7450
hua7450 deleted the test-policyengine-us-main branch December 2, 2026 19:57
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.

2 participants