Skip to content

Stop requiring unlinked scale brackets in the pinned system test - #11126

Merged
anth-volk merged 2 commits into
mainfrom
prepare-tests-for-linked-parameter-parents
Nov 19, 2026
Merged

anth-volk merged 2 commits into
mainfrom
prepare-tests-for-linked-parameter-parents

Conversation

@anth-volk

@anth-volk anth-volk commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

What and why

This prepares policyengine-us for PolicyEngine/policyengine-core#660, which makes every loaded parameter tree link each scale bracket to the scale holding it.

test_an_edit_to_a_loaded_tree_reaches_the_next_simulation asserted brackets[1].parent is None before doing its real work. CI's test jobs run uv lock --upgrade-package policyengine-core before installing, so this assertion would fail on every PR and on main as soon as a policyengine-core release containing #660 is published. policyengine-core publishes a release automatically when a PR merges to master, so merge this PR before #660.

  • Removes that assertion.
  • Sets the edited bracket's parent to None before the edit. On core 3.36.0 the bracket already has no parent, so this changes nothing there. With Verify if HUD adjusted income can be negative #660 it keeps the case the test was written for: the edit clears no cache above the bracket, so the source tree's cached views stay stale, and the pin still has to read the parameter itself. The test's other assertions are unchanged: the next simulation's ny_eitc changes, and a fresh clone of the pinned system gives the same result.
  • Corrects the docstrings of that test and of change_small_tree, which described loaded brackets as having no parent, so they are true on both policyengine-core versions.

uv.lock and pyproject.toml are unchanged.

Test plan

At commit d9da18c, I ran only policyengine_us/tests/test_pinned_tbs_sharing.py::test_an_edit_to_a_loaded_tree_reaches_the_next_simulation, selected by node ID, in two separate environments. It passed in both:

policyengine-core Source New scale bracket linked to its scale Result
3.36.0 uv.lock No Passed
3.36.1 plus #660, commit 84e4d33e5d56da6b6425cbaadcb25185faf787cc Branch link-parameter-parents Yes Passed

To check that setting the parent to None keeps the stale-cache case, a separate script loaded CountryTaxBenefitSystem, read the 2021 EITC maximum for one qualifying child through the root tree's cached view (parameters("2021-01-01")), set the bracket's amount to 5,000, and read the view again:

policyengine-core Bracket parent at the edit Root view before Root view after Root view stale
3.36.0 None (as loaded) 3,618 3,618 Yes
#660 The scale (as loaded) 3,618 5,000 No
#660 None (set by the test) 3,618 3,618 Yes

The other tests in this file were not run locally on either version.

  • For policy changes: not applicable, test-only change.
  • Source conflict register: not applicable, test-only change.
  • make format (the same ruff format . and ruff check . commands, run without syncing the environment)
  • Changelog fragment in changelog.d/

axiom: n/a: test-only change

🤖 Generated with Claude Code

PolicyEngine/policyengine-core#660 links every scale bracket on a loaded
parameter tree to its scale, so the `parent is None` assertion would fail
in the PR that moves uv.lock to a core release containing it. Remove the
assertion and correct the docstrings that described loaded brackets as
having no parent.

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

DTrim99 commented Nov 19, 2026

Copy link
Copy Markdown
Collaborator

Program Review

Source Documents

No source documents apply: this PR changes one test and adds a changelog fragment, so the PDF audit was skipped.

  • Scope: PR changes only

Branch Status

PR branch is 4 commits behind main. Consider rebasing before merging. This review was scoped to the PR's actual changes, so the staleness did not affect the findings.

Critical (Must Fix)

None.

Should Address

1. Merge this PR before a policyengine-core release contains #660, and correct the trigger in the PR description

Where: PR description, "What and why" section; .github/workflows/python-tests.yaml:97-100; .github/workflows/push.yaml:427-430; pyproject.toml:26

Problem: The PR description says "CI installs with uv sync --locked, so that assertion would fail in whichever PR moves uv.lock". The job that runs this test upgrades core first. It runs uv lock --upgrade-package policyengine-core (python-tests.yaml:98) and then uv sync --locked (python-tests.yaml:100). pyproject.toml:26 sets only a floor, policyengine-core>=3.36.0, so the job installs the newest release on PyPI.

This PR's own CI shows the upgrade. uv.lock:1789 locks core 3.36.0, but Rest shard 9 (job 135094677098) logged Updated policyengine-core v3.36.0 -> v3.36.1.

Failure scenario if a release containing #660 is published first:

  1. Verify if HUD adjusted income can be negative #660 merges to policyengine-core master, and that repository's push workflow publishes a new version to PyPI.
  2. The next policyengine-us run resolves that version, on pull requests (python-tests.yaml:98) and on main (push.yaml:428).
  3. The core-heavy group (Makefile:69-72, Makefile:341-342) runs policyengine_us/tests/test_pinned_tbs_sharing.py.
  4. The assertion this PR removes, brackets[1].parent is None at line 553 on main, fails because Verify if HUD adjusted income can be negative #660 sets bracket.parent = self (policyengine_core/parameters/parameter_scale.py:56 at Verify if HUD adjusted income can be negative #660 head 84e4d33).
  5. main and open PRs stay red until this PR lands, and no uv.lock change is involved.

Current state: #660 was still open and PyPI's latest core release was 3.36.1 when this review was prepared, so this failure has not occurred.

Fix: Merge this PR before #660, and replace the quoted sentence with:

CI's test jobs run uv lock --upgrade-package policyengine-core before installing, so this assertion would fail on every PR and on main as soon as a policyengine-core release containing #660 is published. Merge this PR before #660.

Evidence: The workflow steps were read and the version upgrade appears in the CI log. The failure sequence was traced through code, not run.

2. Once core links brackets, this test no longer builds the stale-cache case

Where: policyengine_us/tests/test_pinned_tbs_sharing.py:553-562

Problem: The removed assertion guaranteed that the edit at line 562 stopped at the bracket and left every cached view above it stale. With #660, the same edit clears caches up to the root. The test still proves that an edit reaches a rebuilt pin, but it no longer proves that the EITC pin ignores a stale view held by its source.

Concrete failure scenario: Suppose a later change makes _pin_pre_arpa_eitc take its 2021 amounts from the source system's cached view instead of from each bracket (policyengine_us/tools/pinned_tbs.py:73-76). The current code does not do this, and the change would also have to pass the source system to the pin function (pinned_tbs.py:52).

Core What the edit at line 562 does Amount the pin restores Test result
3.36.0 (unlinked) Clears caches through the bracket only, so the root view keeps $3,618 $3,618 Fails at line 565, because edited == before
#660 (linked) Clears caches up to the root $5,000 Passes lines 565 and 567, so the regression goes unseen

The regression would still produce wrong results on a linked core after a write that clears no cache, such as interpolation. test_a_pin_reads_past_a_view_its_source_has_left_stale (line 570) covers that kind of write, but only through ny_ctc, which never runs _pin_pre_arpa_eitc. The other tests that reference the EITC pin check its rebuild and branch period (policyengine_us/tests/core/test_spm_simulation_isolation.py:412-430, policyengine_us/tests/core/test_multi_year_simulation.py:292-302).

What the test still catches on both core versions: a pin that is reused without being rebuilt, and removal of the restore loop at pinned_tbs.py:84-86.

Priority: The test review rates this as should address. The logic review records the same narrowing and treats it as an expected result of #660. The gap has no effect until a core release contains #660. It stays in this section because the scenario is concrete and one line preserves the coverage. It does not block merge.

Fix: State the premise in the test, where the assertion used to be:

loaded = CountryTaxBenefitSystem()
# The edit below then clears no cache above the bracket, on any core.
loaded.parameters.gov.irs.credits.eitc.max.brackets[1].parent = None

This line changes nothing on core 3.36.0, where the parent is already None. loaded is private to this test. The pin relinks its own copy (policyengine_us/spm.py:726-728, policyengine_us/spm.py:739), and a full clone relinks its brackets (policyengine_core/parameters/parameter_scale.py:124 in core 3.36.0).

If maintainers prefer to retire the scenario after #660, remove "so a pin has to read the parameter itself" from the docstring at lines 549-550.

Evidence: The table and the fix were traced through the core 3.36.0 source and the #660 source. Neither the hypothetical regression nor the fix was run.

Suggestions

1. Name the changed test in the changelog fragment

Where: changelog.d/prepare-tests-for-linked-parameter-parents.changed.md:1

Problem: "The pinned tax-benefit system test" reads as the whole module. CHANGELOG.md:1719 already uses "the pinned-system test" for this module, which has 27 test functions. The PR description says the author ran one test on each core version and that "the other tests in this file were not run locally on either version".

Fix:

Stop test_an_edit_to_a_loaded_tree_reaches_the_next_simulation requiring scale brackets without a parent, so it passes whether or not policyengine-core links a loaded tree's brackets to their scale.

Validation Summary

Check Result Details
Regulatory Accuracy Skipped The PR changes no policy logic or parameter values.
Reference Quality Skipped The PR adds no parameters or references.
Compatibility with policyengine-core#660 Compatible, 1 should-address finding Both rewritten docstrings hold on core 3.36.0 and #660. No other policyengine-us code was found to depend on an unlinked bracket. Merge order matters (finding 1).
Code Patterns 0 critical, 0 should address, 1 suggestion The changelog fragment's path and type are valid, and the removed assertion left no unused code.
Test Coverage 0 critical, 1 should-address finding The test keeps both behavioral assertions, but it loses the stale-cache case on a linked core (finding 2).
PDF Value Audit Skipped The PR has no source documents.
CI Status Passing All 38 checks pass on c356089

What was run and what was traced:

Review Severity: COMMENT

The PR has no critical issues, and the test change is correct on both core versions by code trace. The two should-address findings do not block merge, but finding 1 sets the order in which this PR and #660 should land.

Next Steps

  1. Merge this PR before any policyengine-core release contains Verify if HUD adjusted income can be negative #660.
  2. Replace the CI sentence in the PR description with the wording in finding 1.
  3. Decide whether to keep the stale-cache case with the one-line change in finding 2 or retire it and narrow the docstring.
  4. Optionally, name the changed test in the changelog fragment.

@DTrim99 DTrim99 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

No blocking findings, and all 38 checks pass on c356089. Please merge this before a policyengine-core release contains #660; the review comment above explains why.

…he case

With policyengine-core#660, a loaded tree's scale brackets are linked to
their scale, so an edit to a bracket clears the cached views above it.
The test then no longer checked that a pin reads past a stale view held
by its source. Setting the edited bracket's parent to None gives the same
case on core versions with and without linked brackets.

Also name the changed test in the changelog fragment.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@anth-volk
anth-volk merged commit cc685ee into main Nov 19, 2026
39 checks passed
@anth-volk
anth-volk deleted the prepare-tests-for-linked-parameter-parents branch November 19, 2026 20:10
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