From 92b1185f26189cf16f8847c72eecfaa5ea37683f Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Wed, 4 Nov 2026 13:05:41 -0500 Subject: [PATCH 1/3] Test low counts and digests, and anchors listed second, in later reports A third review of #1506, at 212dd72, found six changes to _follow_later_repin_report that left every later-report test passing. Two make an anchor check read only the first record set: in the changed fields, or among the added rows. Four compare with <= in place of ==: the old feed's digest, the old row count, the listing's digest and the new row count. Each anchor case held one record set, and each refusing count or digest sorted above the expected one. The anchor-label and anchor-record-set cases now list a record set outside the anchors first and the anchor second. Four cases join them, each below the expected value: an old feed digest and a listing digest that sort first, an old feed one row short with a new count that still adds up, and a new row count one short. The helper stays the same, so every case passes at once. Each of the six changes now fails one of these cases, under pytest's assertion rewriting and with --assert=plain. Using >= in place of == already fails the cases above the expected value, and each of the 18 changes the earlier cases catch still fails at least one case. Co-Authored-By: Claude Opus 5.5 --- .../engine_free/us/test_us_esi_premiums.py | 47 ++++++++++++++++--- 1 file changed, 40 insertions(+), 7 deletions(-) diff --git a/packages/microcosm-build/tests/engine_free/us/test_us_esi_premiums.py b/packages/microcosm-build/tests/engine_free/us/test_us_esi_premiums.py index 5522393d95..549cc847ab 100644 --- a/packages/microcosm-build/tests/engine_free/us/test_us_esi_premiums.py +++ b/packages/microcosm-build/tests/engine_free/us/test_us_esi_premiums.py @@ -1385,10 +1385,13 @@ def test_a_later_report_may_add_rows_from_its_declared_source(self) -> None: "added keys differ", ), # A declared row in a B4923C anchor record set, which also sits - # outside the declared namespace. + # outside the declared namespace, after a row that sits inside it. ( - ["k1"], - [("k1", "ed_fsa", "bea_nipa.cy2024.private_group_health_insurance")], + ["k1", "k2"], + [ + ("k1", "ed_fsa", "ed_fsa.a"), + ("k2", "ed_fsa", "bea_nipa.cy2024.private_group_health_insurance"), + ], "ed_fsa", "ed_fsa.", "an added row in a B4923C record set", @@ -1464,10 +1467,19 @@ def test_a_later_report_refuses_rows_added_outside_its_declaration( lambda a: a["new_feed"].update(sha256="other"), "a listing of another feed", ), + # A listing whose digest sorts before the report's new feed. + ( + lambda a: a["new_feed"].update(sha256="aaa"), + "a listing of another feed", + ), # A listing that names one added key twice. (lambda a: a["rows"].append(dict(a["rows"][0])), "an added key twice"), ], - ids=["listing-other-feed", "listing-repeats-key"], + ids=[ + "listing-other-feed", + "listing-other-feed-sorts-first", + "listing-repeats-key", + ], ) def test_a_later_report_refuses_a_listing_it_cannot_follow( self, mutate, refusal @@ -1493,6 +1505,12 @@ def test_a_later_report_refuses_a_listing_it_cannot_follow( lambda r: r["rows"].update(new_rows=r["rows"]["new_rows"] + 1), "a new row count that does not add up", ), + # A new row count one short. Each count and digest a check compares + # has a case above the expected value and one below it. + ( + lambda r: r["rows"].update(new_rows=r["rows"]["new_rows"] - 1), + "a new row count that does not add up", + ), ( lambda r: r["rows"]["changed_fields"].update( value={"rows": 1, "by_record_set": {"x": 1}} @@ -1503,19 +1521,31 @@ def test_a_later_report_refuses_a_listing_it_cannot_follow( lambda r: r["feeds"]["old"].update(sha256="other"), "starts from another feed", ), + # An old feed whose digest sorts before the expected one. + ( + lambda r: r["feeds"]["old"].update(sha256="aaa"), + "starts from another feed", + ), # An old feed of another size, with a new count that still adds up. ( lambda r: r["rows"].update(old_rows=11, new_rows=12), "an old feed of another size", ), - # A label change in a B4923C record set. + # An old feed one row short, with a new count that still adds up. + ( + lambda r: r["rows"].update(old_rows=9, new_rows=10), + "an old feed of another size", + ), + # A label change in a B4923C record set, after a record set outside + # the anchors. ( lambda r: r["rows"]["changed_fields"].update( { "layout/groupby_value_label": { - "rows": 1, + "rows": 2, "by_record_set": { - "bea_nipa.cy2024.private_group_health_insurance": 1 + "x": 1, + "bea_nipa.cy2024.private_group_health_insurance": 1, }, } } @@ -1526,9 +1556,12 @@ def test_a_later_report_refuses_a_listing_it_cannot_follow( ids=[ "dropped-row", "row-count", + "row-count-short", "value-change", "wrong-base", + "wrong-base-sorts-first", "old-row-count", + "old-row-count-short", "anchor-label", ], ) From 4b84fbfdd004083e3b2ea520a53e8eb64bf81edb Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Wed, 4 Nov 2026 13:41:35 -0500 Subject: [PATCH 2/3] Test later reports with each bad entry between two good ones A review of 92b1185 found that every later-report case still passed when an anchor check read only the last record set or row, since each anchor case put the anchor last. Other checks that read a list or a mapping had the same gap. Of 23 changes that make such a check read only its first entry or only its last, or pass when any entry passes, 17 left every case passing at 92b1185. Four of them read one of the three anchor record sets that the pin test gives the helper, while the cases gave it only one. Each case for such a check now puts its one bad entry between two good ones. Among the added rows, the row from another source, the row in an anchor record set and the row outside the namespace each come second of three. Among the changed fields, the value change comes second of three. The label change in an anchor record set sits in the second of three fields, where the anchor comes second of three record sets. The cases now give the helper the pin test's three B4923C record sets and touch cy2024, which sorts between the other two. The helper stays the same, and every case passes with it. Each of the 23 changes now fails a case, under pytest's assertion rewriting and with --assert=plain, and each earlier change still fails the cases it failed before. The new row count comment said every count and digest a check compares had a case on each side of the expected value, as this branch's first commit message did. The check that a listing names each key once compares its key count with its row count, and the key count can't exceed the row count. The comment now names the four checks of a feed's digest or row count. Co-Authored-By: Claude Opus 5.5 --- .../engine_free/us/test_us_esi_premiums.py | 76 ++++++++++++++----- 1 file changed, 59 insertions(+), 17 deletions(-) diff --git a/packages/microcosm-build/tests/engine_free/us/test_us_esi_premiums.py b/packages/microcosm-build/tests/engine_free/us/test_us_esi_premiums.py index 549cc847ab..06765537cc 100644 --- a/packages/microcosm-build/tests/engine_free/us/test_us_esi_premiums.py +++ b/packages/microcosm-build/tests/engine_free/us/test_us_esi_premiums.py @@ -1325,7 +1325,14 @@ def _added(rows: list[tuple[str, str, str]]) -> dict: ], } - _ANCHORS = {"bea_nipa.cy2024.private_group_health_insurance"} + #: The pin test's three B4923C record sets, one for each year of the + #: banked series. The cases below touch cy2024, which sorts between the + #: other two. + _ANCHORS = { + "bea_nipa.cy2023.private_group_health_insurance", + "bea_nipa.cy2024.private_group_health_insurance", + "bea_nipa.cy2025.private_group_health_insurance", + } def test_a_later_report_may_add_rows_from_its_declared_source(self) -> None: later = self._later_report( @@ -1348,7 +1355,10 @@ def test_a_later_report_may_add_rows_from_its_declared_source(self) -> None: ) == ("new", 12) # Each refusing case below names the check that must refuse it, so a check - # moved ahead of another fails the case it takes over. + # moved ahead of another fails the case it takes over. A case for a check + # that reads a list or a mapping puts its one bad entry between two good + # ones, so a check that reads only the first entry, or only the last, + # lets the case through. @pytest.mark.parametrize( ( "added_keys", @@ -1360,10 +1370,15 @@ def test_a_later_report_may_add_rows_from_its_declared_source(self) -> None: [ # Rows added with no declaration. (["k1"], None, None, None, "adds rows without declaring them"), - # A row from a source the re-pin did not declare. + # A row from a source the re-pin did not declare, between two rows + # from the declared source. ( - ["k1", "k2"], - [("k1", "ed_fsa", "ed_fsa.a"), ("k2", "irs_soi", "x")], + ["k1", "k2", "k3"], + [ + ("k1", "ed_fsa", "ed_fsa.a"), + ("k2", "irs_soi", "x"), + ("k3", "ed_fsa", "ed_fsa.b"), + ], "ed_fsa", "ed_fsa.", "an added row from another source", @@ -1385,12 +1400,14 @@ def test_a_later_report_may_add_rows_from_its_declared_source(self) -> None: "added keys differ", ), # A declared row in a B4923C anchor record set, which also sits - # outside the declared namespace, after a row that sits inside it. + # outside the declared namespace, between two rows that sit inside + # it. ( - ["k1", "k2"], + ["k1", "k2", "k3"], [ ("k1", "ed_fsa", "ed_fsa.a"), ("k2", "ed_fsa", "bea_nipa.cy2024.private_group_health_insurance"), + ("k3", "ed_fsa", "ed_fsa.b"), ], "ed_fsa", "ed_fsa.", @@ -1405,10 +1422,14 @@ def test_a_later_report_may_add_rows_from_its_declared_source(self) -> None: "declares added rows without a source", ), # A row the listing labels with the declared source, in a record - # set outside the declared namespace. + # set outside the declared namespace, between two rows inside it. ( - ["k1"], - [("k1", "ed_fsa", "irs_soi.ty2023.table_1_4")], + ["k1", "k2", "k3"], + [ + ("k1", "ed_fsa", "ed_fsa.a"), + ("k2", "ed_fsa", "irs_soi.ty2023.table_1_4"), + ("k3", "ed_fsa", "ed_fsa.b"), + ], "ed_fsa", "ed_fsa.", "an added row outside the namespace", @@ -1505,15 +1526,27 @@ def test_a_later_report_refuses_a_listing_it_cannot_follow( lambda r: r["rows"].update(new_rows=r["rows"]["new_rows"] + 1), "a new row count that does not add up", ), - # A new row count one short. Each count and digest a check compares - # has a case above the expected value and one below it. + # A new row count one short. The four checks of a feed's digest or + # row count each have a case above the expected value and one below + # it. ( lambda r: r["rows"].update(new_rows=r["rows"]["new_rows"] - 1), "a new row count that does not add up", ), + # A value change, between a hash change and a label change. ( lambda r: r["rows"]["changed_fields"].update( - value={"rows": 1, "by_record_set": {"x": 1}} + { + "layout/record_set_spec_hash": { + "rows": 1, + "by_record_set": {"x": 1}, + }, + "value": {"rows": 1, "by_record_set": {"x": 1}}, + "dimension_value_labels/age/85_plus": { + "rows": 1, + "by_record_set": {"x": 1}, + }, + } ), "changes more than labels", ), @@ -1536,18 +1569,27 @@ def test_a_later_report_refuses_a_listing_it_cannot_follow( lambda r: r["rows"].update(old_rows=9, new_rows=10), "an old feed of another size", ), - # A label change in a B4923C record set, after a record set outside - # the anchors. + # A label change in a B4923C record set, between two record sets + # outside the anchors, in the second of three changed fields. ( lambda r: r["rows"]["changed_fields"].update( { + "layout/record_set_spec_hash": { + "rows": 1, + "by_record_set": {"x": 1}, + }, "layout/groupby_value_label": { - "rows": 2, + "rows": 3, "by_record_set": { "x": 1, "bea_nipa.cy2024.private_group_health_insurance": 1, + "z": 1, }, - } + }, + "dimension_value_labels/age/85_plus": { + "rows": 1, + "by_record_set": {"z": 1}, + }, } ), "changes a B4923C record set", From 0997c5068c5ee2d3f7ebc80f4b1b3df6fc4f8452 Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Wed, 4 Nov 2026 14:28:16 -0500 Subject: [PATCH 3/3] Test every anchor year and a report that only relabels rows A review of 4b84fbf found that the comment above the refusing cases claimed more than they show. It said each case for a check that reads a list or a mapping puts its one bad entry between two good ones, but namespace-not-leading holds a single row. The comment now says a check that reads only the first entry, or only the last, lets through each case whose own comment puts its bad entry between two good ones. The review also found two gaps in the cases. Both cases that touch an anchor record set used only cy2024, so an anchor check that read cy2024 alone, or with one of the other two record sets, let every case through. And no case passed a report that adds no row or changes a dimension value label, so every case still passed with a helper that refused either kind. Only the pin test, which runs the helper over the committed report of microcosm#1343, caught such a helper. Both anchor cases now run once for each of the three B4923C record sets, and a new case passes a report that relabels rows and adds none, as #1343's re-pin did. The helper stays the same, and all 27 later-report cases pass with it. Of 68 changes to the helper, 3 leave every case passing here, against 11 at 4b84fbf, 28 at 92b1185 and 36 on main. Both pytest modes, assertion rewriting and --assert=plain, give the same results. Each case that caught a change at an earlier commit still catches it. As at 4b84fbf, <= in the source check and >= in the key-count check leave every case passing. So does a label check that matches the two layout fields exactly rather than as prefixes, and it accepts both committed reports, which name those fields exactly. Co-Authored-By: Claude Opus 5.5 --- .../engine_free/us/test_us_esi_premiums.py | 111 +++++++++++------- 1 file changed, 70 insertions(+), 41 deletions(-) diff --git a/packages/microcosm-build/tests/engine_free/us/test_us_esi_premiums.py b/packages/microcosm-build/tests/engine_free/us/test_us_esi_premiums.py index 06765537cc..0e08461e8f 100644 --- a/packages/microcosm-build/tests/engine_free/us/test_us_esi_premiums.py +++ b/packages/microcosm-build/tests/engine_free/us/test_us_esi_premiums.py @@ -1326,8 +1326,9 @@ def _added(rows: list[tuple[str, str, str]]) -> dict: } #: The pin test's three B4923C record sets, one for each year of the - #: banked series. The cases below touch cy2024, which sorts between the - #: other two. + #: banked series. Each anchor case below runs once for each of them, so a + #: check that reads only some of the three lets one of those cases + #: through. _ANCHORS = { "bea_nipa.cy2023.private_group_health_insurance", "bea_nipa.cy2024.private_group_health_insurance", @@ -1354,11 +1355,32 @@ def test_a_later_report_may_add_rows_from_its_declared_source(self) -> None: declared_namespace="ed_fsa.", ) == ("new", 12) + def test_a_later_report_may_relabel_rows_and_add_none(self) -> None: + # As microcosm#1343's re-pin did: label changes, the record-set hash + # that covers them, and no added row. + later = self._later_report( + added_keys=[], + changed_fields={ + "dimension_value_labels/age/85_plus": { + "rows": 1, + "by_record_set": {"x": 1}, + }, + "layout/groupby_value_label": {"rows": 1, "by_record_set": {"x": 1}}, + "layout/record_set_spec_hash": {"rows": 2, "by_record_set": {"x": 2}}, + }, + ) + assert _follow_later_repin_report( + later, + feed_sha256="old", + feed_rows=10, + anchor_record_sets=self._ANCHORS, + ) == ("new", 10) + # Each refusing case below names the check that must refuse it, so a check - # moved ahead of another fails the case it takes over. A case for a check - # that reads a list or a mapping puts its one bad entry between two good - # ones, so a check that reads only the first entry, or only the last, - # lets the case through. + # moved ahead of another fails the case it takes over. A check that reads + # only the first entry of a list or a mapping, or only the last, lets + # through each case whose comment puts its bad entry between two good + # ones. @pytest.mark.parametrize( ( "added_keys", @@ -1401,17 +1423,20 @@ def test_a_later_report_may_add_rows_from_its_declared_source(self) -> None: ), # A declared row in a B4923C anchor record set, which also sits # outside the declared namespace, between two rows that sit inside - # it. - ( - ["k1", "k2", "k3"], - [ - ("k1", "ed_fsa", "ed_fsa.a"), - ("k2", "ed_fsa", "bea_nipa.cy2024.private_group_health_insurance"), - ("k3", "ed_fsa", "ed_fsa.b"), - ], - "ed_fsa", - "ed_fsa.", - "an added row in a B4923C record set", + # it: one case for each anchor. + *( + ( + ["k1", "k2", "k3"], + [ + ("k1", "ed_fsa", "ed_fsa.a"), + ("k2", "ed_fsa", anchor), + ("k3", "ed_fsa", "ed_fsa.b"), + ], + "ed_fsa", + "ed_fsa.", + "an added row in a B4923C record set", + ) + for anchor in sorted(_ANCHORS) ), # A listing with no declared source. ( @@ -1457,7 +1482,9 @@ def test_a_later_report_may_add_rows_from_its_declared_source(self) -> None: "other-source", "listing-short", "listing-extra", - "anchor-record-set", + "anchor-record-set-cy2023", + "anchor-record-set-cy2024", + "anchor-record-set-cy2025", "no-source", "outside-namespace", "namespace-not-leading", @@ -1570,29 +1597,29 @@ def test_a_later_report_refuses_a_listing_it_cannot_follow( "an old feed of another size", ), # A label change in a B4923C record set, between two record sets - # outside the anchors, in the second of three changed fields. - ( - lambda r: r["rows"]["changed_fields"].update( - { - "layout/record_set_spec_hash": { - "rows": 1, - "by_record_set": {"x": 1}, - }, - "layout/groupby_value_label": { - "rows": 3, - "by_record_set": { - "x": 1, - "bea_nipa.cy2024.private_group_health_insurance": 1, - "z": 1, + # outside the anchors, in the second of three changed fields: one + # case for each anchor, which the default argument binds. + *( + ( + lambda r, anchor=anchor: r["rows"]["changed_fields"].update( + { + "layout/record_set_spec_hash": { + "rows": 1, + "by_record_set": {"x": 1}, }, - }, - "dimension_value_labels/age/85_plus": { - "rows": 1, - "by_record_set": {"z": 1}, - }, - } - ), - "changes a B4923C record set", + "layout/groupby_value_label": { + "rows": 3, + "by_record_set": {"x": 1, anchor: 1, "z": 1}, + }, + "dimension_value_labels/age/85_plus": { + "rows": 1, + "by_record_set": {"z": 1}, + }, + } + ), + "changes a B4923C record set", + ) + for anchor in sorted(_ANCHORS) ), ], ids=[ @@ -1604,7 +1631,9 @@ def test_a_later_report_refuses_a_listing_it_cannot_follow( "wrong-base-sorts-first", "old-row-count", "old-row-count-short", - "anchor-label", + "anchor-label-cy2023", + "anchor-label-cy2024", + "anchor-label-cy2025", ], ) def test_a_later_report_still_refuses_dropped_or_changed_rows(