From c356089eb321ad6fef3abef8ea7143d653fb97f1 Mon Sep 17 00:00:00 2001 From: Anthony Volk <14987227+anth-volk@users.noreply.github.com> Date: Thu, 19 Nov 2026 00:02:58 +0400 Subject: [PATCH 1/2] Stop requiring unlinked scale brackets in the pinned system test 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 --- ...e-tests-for-linked-parameter-parents.changed.md | 1 + policyengine_us/tests/test_pinned_tbs_sharing.py | 14 +++++++------- 2 files changed, 8 insertions(+), 7 deletions(-) create mode 100644 changelog.d/prepare-tests-for-linked-parameter-parents.changed.md diff --git a/changelog.d/prepare-tests-for-linked-parameter-parents.changed.md b/changelog.d/prepare-tests-for-linked-parameter-parents.changed.md new file mode 100644 index 00000000000..6f512b0e509 --- /dev/null +++ b/changelog.d/prepare-tests-for-linked-parameter-parents.changed.md @@ -0,0 +1 @@ +Stop the pinned tax-benefit system test requiring scale brackets without a parent, so it passes whether or not policyengine-core links a loaded tree's brackets to their scale. diff --git a/policyengine_us/tests/test_pinned_tbs_sharing.py b/policyengine_us/tests/test_pinned_tbs_sharing.py index 49fa3a0855a..be1e20f1c86 100644 --- a/policyengine_us/tests/test_pinned_tbs_sharing.py +++ b/policyengine_us/tests/test_pinned_tbs_sharing.py @@ -161,8 +161,8 @@ def parameter(value): def change_small_tree(tree, change, index, value): """Change ``tree`` in one of the ways it can change. - Only ``update`` clears a cache, and on a loaded tree it stops at a scale's - bracket, which has no parent. + Only ``update`` clears a cache. From a scale's bracket on a loaded tree, it + goes further up only if this version of core links the bracket to its scale. """ credit = tree.credit named_parent = tree.categories.group.children["parent"] @@ -543,14 +543,14 @@ def result(): def test_an_edit_to_a_loaded_tree_reaches_the_next_simulation(monkeypatch): - """A loaded tree's scale brackets have no parent, unlike a clone's. + """An edit to a scale bracket on a loaded tree reaches a pin. - So this edit clears no cache above the bracket, and a pin has to read the - parameter itself. The EITC's 2021 pin keeps this amount, so its result - moves with the edit. + Whether the edit clears the caches above the bracket depends on whether this + version of core links a loaded tree's brackets to their scale, so a pin has + to read the parameter itself. The EITC's 2021 pin keeps this amount, so its + result moves with the edit. """ loaded = CountryTaxBenefitSystem() - assert loaded.parameters.gov.irs.credits.eitc.max.brackets[1].parent is None def result(): situation = household(2021, earnings=15_000, interest=0) From d9da18c90e0549b1a93a5979295cb06db7bdbf9a Mon Sep 17 00:00:00 2001 From: Anthony Volk <14987227+anth-volk@users.noreply.github.com> Date: Thu, 19 Nov 2026 22:42:49 +0400 Subject: [PATCH 2/2] Detach the edited bracket so the loaded-tree test keeps its stale-cache 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 --- ...-tests-for-linked-parameter-parents.changed.md | 2 +- policyengine_us/tests/test_pinned_tbs_sharing.py | 15 +++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/changelog.d/prepare-tests-for-linked-parameter-parents.changed.md b/changelog.d/prepare-tests-for-linked-parameter-parents.changed.md index 6f512b0e509..61255c3735d 100644 --- a/changelog.d/prepare-tests-for-linked-parameter-parents.changed.md +++ b/changelog.d/prepare-tests-for-linked-parameter-parents.changed.md @@ -1 +1 @@ -Stop the pinned tax-benefit system test requiring scale brackets without a parent, so it passes whether or not policyengine-core links a loaded tree's brackets to their scale. +Stop `test_an_edit_to_a_loaded_tree_reaches_the_next_simulation` requiring policyengine-core to load scale brackets without a parent. The test now detaches the bracket it edits, so it checks the same case whether or not core links a loaded tree's brackets to their scale. diff --git a/policyengine_us/tests/test_pinned_tbs_sharing.py b/policyengine_us/tests/test_pinned_tbs_sharing.py index be1e20f1c86..fc193c6948f 100644 --- a/policyengine_us/tests/test_pinned_tbs_sharing.py +++ b/policyengine_us/tests/test_pinned_tbs_sharing.py @@ -545,12 +545,16 @@ def result(): def test_an_edit_to_a_loaded_tree_reaches_the_next_simulation(monkeypatch): """An edit to a scale bracket on a loaded tree reaches a pin. - Whether the edit clears the caches above the bracket depends on whether this - version of core links a loaded tree's brackets to their scale, so a pin has - to read the parameter itself. The EITC's 2021 pin keeps this amount, so its - result moves with the edit. + The test detaches the bracket from its scale before the edit, so the edit + clears no cache above the bracket on any version of core, and the source + tree's cached views stay stale. A pin has to read the parameter itself. The + EITC's 2021 pin keeps this amount, so its result moves with the edit. """ loaded = CountryTaxBenefitSystem() + edited_bracket = loaded.parameters.gov.irs.credits.eitc.max.brackets[1] + # Older versions of core load a bracket without a parent, and newer ones + # link it to its scale. Detaching it gives the same case on both. + edited_bracket.parent = None def result(): situation = household(2021, earnings=15_000, interest=0) @@ -558,8 +562,7 @@ def result(): return simulation.calculate("ny_eitc", 2021)[0] before = result() - amount = loaded.parameters.gov.irs.credits.eitc.max.brackets[1].amount - amount.update(period="year:2021:1", value=5_000) + edited_bracket.amount.update(period="year:2021:1", value=5_000) edited = result() assert edited != before