diff --git a/changelog.d/us-feed-cut-on-split-pin.changed.md b/changelog.d/us-feed-cut-on-split-pin.changed.md new file mode 100644 index 0000000000..175ee1343b --- /dev/null +++ b/changelog.d/us-feed-cut-on-split-pin.changed.md @@ -0,0 +1 @@ +The US county-pin guard allows one named main-feed cut on the split pin `41b2fb2` (today `60266a3`, for microcosm#880) while the county pin names `3e9d3a0`; once the county pin moves, the guard accepts only matching pins. diff --git a/docs/us-chronicle-feed-repin.md b/docs/us-chronicle-feed-repin.md index 0f04cb794b..f3f08c0adf 100644 --- a/docs/us-chronicle-feed-repin.md +++ b/docs/us-chronicle-feed-repin.md @@ -21,8 +21,10 @@ PEP county population vintage 2024, and the ACS 2020-2024 5-year county tables B01003, B11001, B19001, B19013, B19025, B19051 and B19061. They have their own pin, `us/chronicle_county_facts.json`, with scope `us/chronicle_county_facts_scope.json` (scope name `us_county_facts`), beside -the main pin. No fiscal compile reads them, and the main feed, its scope and -the target-parity resources do not move when they do. +the main pin. No fiscal compile reads them. When microcosm#922 gave them their +own pin, the main feed, its scope and the target-parity resources stayed as +they were. From then on, the county pin moves only with the main pin (see the +joint re-pin rule, "The two pins move together", below). They are separate because of size. The ACS county rows keep both estimate and margin-of-error rows in one record set, about 5.2 KB per row, and the eight @@ -38,7 +40,8 @@ machine on 2026-11-13; the run notes are not in this repository. - **Commit.** Chronicle main `3e9d3a0694e8ca7e31ed5319c3ceb1bde92b12e0` (merged 2026-11-12), which carries every county package. It is on main, so - it needs no branch or tag; the next main re-pin starts at or after it. + it needs no branch or tag. The combined re-pin (below) moves both pins to + one Chronicle main commit at or after it. The rows are on the `chronicle.consumer_fact.v5` contract (schema digest `acd33a09…`); the main pin stays on v3. - **Pairs.** 10 (record set, period) pairs from nine packages, built at their @@ -105,11 +108,138 @@ machine on 2026-11-13; the run notes are not in this repository. A later main re-pin can fold these pairs into the main scope only by retiring the county pin in the same change. -The two pins move together. The main feed is pinned at `41b2fb2` and the -county facts at `3e9d3a0`; the next main re-pin starts at or after -`3e9d3a0`. From then on, a change that re-pins the main feed at a Chronicle -commit also rebuilds the county facts at that commit and re-pins them, so a -US build reads one Chronicle base. +The two pins move together. When microcosm#922 pinned the county facts at +`3e9d3a0`, the main pin named `41b2fb2` (the split pin). While the county pin +names `3e9d3a0`, the main pin may stay at the split pin or name one feed cut on +it that the US feed owner allowed; `test_us_chronicle_county_facts.py` names +that cut until the owner allows a later cut in its place. Once the county pin +moves, both exceptions end and the main pin names the county pin's commit. Any +other main re-pin starts at or after `3e9d3a0` and rebuilds and re-pins the +county facts at the same commit, so a US build reads one Chronicle base. + +An operator builds a cut from the split pin, or the cut before it, plus whole +Chronicle packages whose git trees equal Chronicle main's, using `41b2fb2`'s +Chronicle code with changes only to `SOURCE_PACKAGE_ALIASES`. The cut's re-pin +report keeps every earlier row byte for byte, or the operator brings a reviewed +check of the rows the cut changes. Either way, the cut adds, removes or changes +no target that the ACS local lane selects from the main feed, in any +`--soi-mode` the lane accepts: `state`, `totals`, `full`, `state_cd` and +`state_county`. In each mode, `state_admin_surface` with SNAP, Medicaid and +SOI selects the same targets from both feeds, equal in every `TargetSpec` field +and in the same order, with the same SOI receipt and substitution records. +`acs_local_ssi_medicaid_take_up_targets`, which takes no mode, returns the same +SSI age-band counts, Medicaid enrollment table and substitution records from +both. While `soi_surface_predicate` maps `state_county` to `state` and +`state_admin_surface` branches only on `state_cd`, those two modes select the +same main-feed targets, so one comparison covers both. + +The operator compiles the cut and the main feed it replaces on the tree that +will merge (the merge tree). The operator first merges main into the change +that pins the cut, then compiles both feeds at the change's new head, the +tested commit. The operator runs both compiles from one clean checkout of the +tested commit, in the environment its `uv.lock` resolves: +`uv sync --all-packages --locked --extra us` builds it, and +`docs/agent-guide.md` lists that command under Commands as the US engine +environment. + +The operator compiles each feed with a script (the runner) that calls +`state_admin_surface` in each mode and `acs_local_ssi_medicaid_take_up_targets` +on that feed and writes what each call returns to a file. A second script (the +comparator) reads the runner's files for both feeds. It reports each target +that the cut adds to or removes from the lane's selection or changes in any +`TargetSpec` field, and any change in the targets' order. It also reports any +difference in the SOI receipt, the substitution records, the SSI age-band +counts or the Medicaid enrollment table. The repository holds neither script, +so the operator records each one's sha256 in a receipt. The operator keeps the +receipt and both scripts with the evidence, outside the repository, and links +to them or quotes them in the change's pull request. + +In the receipt, the operator also records the tested commit, the interpreter +version, the resolved versions of the packages the compile imports and both +feeds' digests. The operator records where the compile imported the lane's +tool, each workspace package and each overridden package from, and the output +of `git status --porcelain` at compile time. The operator lists each way the +run departs from that checkout or environment, such as a package they swapped +in by hand. The change's reviewer checks the two digests against the main pin +the cut replaces and the pin the change sets. The reviewer also checks that +`git status` printed nothing. They check that the compile imported the tool +and each workspace package from the checkout, and each overridden package from +a path the operator listed as a departure. + +After the compiles, the operator may add commits that record the result. Each +changes nothing but the changelog and the paragraph below that starts "Today +the US feed owner allows", and reports a result from the runner, the +comparator and the inputs the receipt names. The operator compiles both feeds +again if main moves after the compiles or the change gains any other commit. +The change's reviewer can skip that rerun on finding that the tested commit +and the merge tree share their compile inputs and dependency configuration. +The two match when no file differs under `tools/` or `packages/*/src`, or in +`uv.lock`, the workspace `pyproject.toml` or any package's `pyproject.toml`. +GitHub does not refresh its test merge, `refs/pull//merge`, while the +change conflicts with main. So just before the merge, the reviewer builds the +merge tree from main's tip and runs the check: + +```bash +git fetch origin +refs/heads/main:refs/remotes/origin/main pull//head +git rev-parse origin/main +git merge-tree --write-tree
+git diff --exit-code --stat -- ':(top)tools' ':(top)uv.lock' ':(top)pyproject.toml' ':(top)packages/*/src/**' ':(top)packages/*/pyproject.toml' +``` + +The reviewer stops if `git fetch` fails, since `origin/main` may then name an +older main. The fetch names `refs/remotes/origin/main` as its destination, so +it updates `origin/main` even in a clone whose fetch configuration leaves main +out. The reviewer writes each commit as its full sha: main's from +`git rev-parse origin/main`, and the change's head from +`gh pr view --json headRefOid`. `git merge-tree` prints the merge +tree's id on its first line. If the change conflicts with main, it exits with +status 1 and still prints a tree id, but that tree holds conflict markers. So +the reviewer goes on only when `git merge-tree` exits with 0. The `:(top)` +prefix makes git read each path from the repository root, so the `git diff` +checks the same files from any directory. The two match only when `git diff` +exits with status 0 and prints nothing; it exits with 1 when they differ and +with 128 on an error, such as an unknown commit. If main's tip or the change's +head moves before the merge, the reviewer runs the check again. Keep the +trailing `/**`: without it, git's `packages/*/src` pathspec matches no file, +so the command misses every change under `packages/*/src`. + +The lane's county rung (`--soi-mode state_county`) is the only build path that +consumes both feeds. It loads the county facts the county pin names and checks +their digest, and it checks the main feed against the operator's +`--feed-sha256` (see Tool flags above). The country-spec loader reads both pin +declarations as package resources, but no feed rows. From the main feed, the +lane selects state SNAP, state Medicaid enrollment, the IRS SOI targets its +`--soi-mode` selects and the SSI age bands (`state_admin_surface` and +`acs_local_ssi_medicaid_take_up_targets` in +`tools/build_us_acs_local_release.py`). In `state` and `state_county` the SOI +targets are state targets, the state HT2 child tax credit cells among them; +`totals`, `full` and `state_cd` can also select congressional-district +targets. The county rung splits the selected state IRS SOI parents into county +targets using the county facts. So a cut that meets the rule leaves the lane's +selected calibration inputs equal. A build on the cut still records the cut's +feed digest in its run identity, so its receipts change. + +Today the US feed owner allows `60266a3`, the cut that microcosm#1610 pins for +microcosm#880, though its evidence is not yet complete. In `state_county` mode, +and so in `state`, the lane selects the same 4,380 targets on it as on +`41b2fb2` (102 SNAP, 51 Medicaid enrollment and 4,227 IRS SOI), with the same +SSI age bands and Medicaid enrollment table. Compiles of both feeds at main +`5499382` on 17 November 2026 showed this, before microcosm#1610's compiler +changes. No run yet covers `totals`, `full` or `state_cd`, or any mode at +microcosm#1610's head. Before it merges, microcosm#1610 owes the comparison in +every mode, on the merge tree and with the receipt the rule above names. The +change that runs the comparison replaces this paragraph with the result and a +link to its evidence. The guard compares commit ids only, so it cannot check +this evidence. + +The combined re-pin moves both pins to one Chronicle main commit at or after +chronicle#430's merge `b428468d`, rebuilds both feeds and retires the allowed +cut in the same change. It brings the 20 main-scope packages that differ +between `41b2fb2` and `3e9d3a0`, the v5 row contract, and a scope rebuild for +the ten pairs Chronicle main no longer emits (see the TY2023 state AGI bands +re-pin below), so it needs its own decisions. The US feed owner owns it and +starts it once the next certified build's commit is fixed; target merge +11 December 2026. ## A re-pin onto a newer row contract diff --git a/packages/microcosm-build/tests/engine_free/us/test_us_chronicle_county_facts.py b/packages/microcosm-build/tests/engine_free/us/test_us_chronicle_county_facts.py index 715846ac2a..7afe13ab0c 100644 --- a/packages/microcosm-build/tests/engine_free/us/test_us_chronicle_county_facts.py +++ b/packages/microcosm-build/tests/engine_free/us/test_us_chronicle_county_facts.py @@ -1,7 +1,8 @@ """The US county facts pin and its loader (microcosm#922). -The county facts sit in their own pin beside the main US feed pin, so the main -feed, its scope and the parity resources do not move when county facts do. +The county facts sit in their own pin beside the main US feed pin. Giving them +their own pin left the main feed, its scope and the parity resources as they +were; the pin guards below refuse a county pin that moves without the main pin. """ from __future__ import annotations @@ -129,24 +130,234 @@ def test_the_county_pin_is_not_the_main_pin() -> None: #: their own, at 3e9d3a0 (docs/us-chronicle-feed-repin.md). _MAIN_PIN_WHEN_THE_COUNTY_PIN_SPLIT = "41b2fb2b864a28c0eda03322b77a97ef147dfa3c" +#: The county pin's own commit when it split from the main pin (microcosm#922). +#: Both exceptions below hold only while the county pin names this commit. +#: Once the county pin moves, the main pin names the county pin's commit. +_COUNTY_PIN_AT_THE_SPLIT = "3e9d3a0694e8ca7e31ed5319c3ceb1bde92b12e0" + +#: The one feed cut on the split pin that the US feed owner allows while the +#: county pin names 3e9d3a0 ("The two pins move together" in +#: docs/us-chronicle-feed-repin.md says what a cut may be and the evidence it +#: owes). A later cut replaces it, so the main pin cannot drift back to an older +#: cut. 60266a3 is 41b2fb2 plus chronicle#430's five packages, for microcosm#880 +#: (microcosm#1610; branch feed/us-41b2fb2-household-880, tag +#: microcosm-us-feed-880-v1). +_FEED_CUT_ON_THE_SPLIT_PIN: str | None = "60266a3088319c909cf7fc89c9d00d3b055dc6e1" + def test_the_county_pin_moves_with_the_next_main_pin() -> None: - """The two pins move together. The main feed may stay at the commit it - had when the county facts were pinned separately; once a change re-pins it - anywhere else, the same change re-pins the county facts to that commit, so - a US build reads one Chronicle base.""" + """The two pins move together. While the county pin stays at its split + commit 3e9d3a0, the main feed may stay at the commit it had when the county + facts were pinned separately, or name the one allowed feed cut on it. Any + other main pin, and every main pin once the county pin moves, names the + county pin's commit, so a US build reads one Chronicle base.""" + + main = load_us_chronicle_feed() + county = load_us_chronicle_county_facts_pin() + allowed = {county.source_commit} + if county.source_commit == _COUNTY_PIN_AT_THE_SPLIT: + allowed.add(_MAIN_PIN_WHEN_THE_COUNTY_PIN_SPLIT) + if _FEED_CUT_ON_THE_SPLIT_PIN is not None: + allowed.add(_FEED_CUT_ON_THE_SPLIT_PIN) + assert main.source_commit in allowed, ( + f"The main Chronicle feed pin names {main.source_commit} and the county " + f"pin {county.source_commit}. Only while the county pin names 3e9d3a0 " + "may the main pin stay at the split pin 41b2fb2 or name the allowed feed " + "cut on it; otherwise re-pin both to one commit in the same change." + ) + + +def test_the_combined_repin_retires_the_feed_cut() -> None: + """Once both pins name one Chronicle commit, or the county pin leaves + 3e9d3a0, no feed cut stays allowed.""" main = load_us_chronicle_feed() county = load_us_chronicle_county_facts_pin() - assert main.source_commit in ( + if ( + main.source_commit == county.source_commit + or county.source_commit != _COUNTY_PIN_AT_THE_SPLIT + ): + assert _FEED_CUT_ON_THE_SPLIT_PIN is None, ( + "Both pins name one Chronicle commit or the county pin has left " + "3e9d3a0; set _FEED_CUT_ON_THE_SPLIT_PIN to None in the same change." + ) + + +def test_the_feed_cut_is_a_full_commit_id_other_than_the_pins() -> None: + """When set, the allowed cut is a string holding a full commit id of 40 + lowercase hex characters, distinct from both pins. ``None`` is valid too, and + the combined re-pin requires it.""" + + if _FEED_CUT_ON_THE_SPLIT_PIN is None: + return + county = load_us_chronicle_county_facts_pin() + assert isinstance(_FEED_CUT_ON_THE_SPLIT_PIN, str) + assert len(_FEED_CUT_ON_THE_SPLIT_PIN) == 40 + assert set(_FEED_CUT_ON_THE_SPLIT_PIN) <= set("0123456789abcdef") + assert _FEED_CUT_ON_THE_SPLIT_PIN not in ( _MAIN_PIN_WHEN_THE_COUNTY_PIN_SPLIT, county.source_commit, - ), ( - f"The main Chronicle feed pin moved to {main.source_commit}; re-pin the " - "county facts to the same commit in the same change." ) +_PIN_GUARDS = ( + test_the_county_pin_moves_with_the_next_main_pin, + test_the_combined_repin_retires_the_feed_cut, + test_the_feed_cut_is_a_full_commit_id_other_than_the_pins, +) + + +def _pin_guards_refusing(monkeypatch, *, main, county, cut) -> tuple[str, ...]: + """Run the three pin guards on these commits as data, without editing a pin, + and name the guards that refuse them, in ``_PIN_GUARDS`` order.""" + + main_pin = dataclasses.replace(load_us_chronicle_feed(), source_commit=main) + county_pin = dataclasses.replace( + load_us_chronicle_county_facts_pin(), source_commit=county + ) + namespace = globals() + monkeypatch.setitem(namespace, "load_us_chronicle_feed", lambda: main_pin) + monkeypatch.setitem( + namespace, "load_us_chronicle_county_facts_pin", lambda: county_pin + ) + monkeypatch.setitem(namespace, "_FEED_CUT_ON_THE_SPLIT_PIN", cut) + refusing = [] + for guard in _PIN_GUARDS: + try: + guard() + except AssertionError: + refusing.append(guard.__name__) + return tuple(refusing) + + +_MOVES = test_the_county_pin_moves_with_the_next_main_pin.__name__ +_RETIRES = test_the_combined_repin_retires_the_feed_cut.__name__ +_FULL_ID = test_the_feed_cut_is_a_full_commit_id_other_than_the_pins.__name__ +_SPLIT = _MAIN_PIN_WHEN_THE_COUNTY_PIN_SPLIT +_COUNTY = _COUNTY_PIN_AT_THE_SPLIT +#: A feed cut on the split pin (60266a3, the first allowed cut). +_CUT = "60266a3088319c909cf7fc89c9d00d3b055dc6e1" +#: A later Chronicle main commit: chronicle#430's merge b428468d, the earliest +#: commit the combined re-pin may name (docs/us-chronicle-feed-repin.md). +_LATER = "b428468dc8a1fad6d21fd4d703b822d5cb687e09" +#: Another later commit, as a made-up full commit id. +_ANOTHER_LATER = "e1" * 20 +#: A made-up full commit id that matches the cut in all but its last character, +#: so a first guard that compares prefixes of any shorter length accepts it. +_CUT_PREFIX_TWIN = _CUT[:39] + "0" + + +@pytest.mark.parametrize( + ("main", "county", "cut", "refusing"), + [ + # While the county pin names 3e9d3a0. + (_SPLIT, _COUNTY, _CUT, ()), + (_CUT, _COUNTY, _CUT, ()), + (_SPLIT, _COUNTY, None, ()), + (_COUNTY, _COUNTY, None, ()), + (_CUT, _COUNTY, None, (_MOVES,)), + (_LATER, _COUNTY, _CUT, (_MOVES,)), + (_COUNTY, _COUNTY, _CUT, (_RETIRES,)), + (_SPLIT, _COUNTY, _SPLIT, (_FULL_ID,)), + (_CUT_PREFIX_TWIN, _COUNTY, _CUT, (_MOVES,)), + # Once the combined re-pin has moved the county pin. + (_LATER, _LATER, None, ()), + (_LATER, _LATER, _CUT, (_RETIRES,)), + (_SPLIT, _LATER, None, (_MOVES,)), + (_SPLIT, _LATER, _CUT, (_MOVES, _RETIRES)), + (_CUT, _LATER, _CUT, (_MOVES, _RETIRES)), + (_LATER, _LATER, _LATER, (_RETIRES, _FULL_ID)), + (_LATER, _ANOTHER_LATER, None, (_MOVES,)), + ], + ids=[ + "split-pin", + "cut", + "split-pin-no-cut", + "both-at-3e9d3a0", + "cut-withdrawn", + "main-moves-alone", + "both-at-3e9d3a0-cut-kept", + "cut-names-the-split-pin", + "main-shares-the-cut-prefix", + "combined-repin", + "combined-repin-cut-kept", + "back-to-the-split-pin", + "back-to-the-split-pin-cut-kept", + "county-moves-alone-main-keeps-the-cut", + "combined-repin-cut-names-the-new-pin", + "pins-at-two-later-commits", + ], +) +def test_the_split_exceptions_end_when_the_county_pin_moves( + monkeypatch, main, county, cut, refusing +) -> None: + """Review r2 P2-1: the split pin and the cut stay allowed only while the + county pin names 3e9d3a0. Once the county pin moves, the main pin can + neither return to the split pin nor keep the cut. Each case names the + guards that refuse it, so it fails if any guard starts or stops refusing. + Review r4 P2-4 added two states that only the first guard refuses: a main + pin that matches the cut in all but its last character, and main and county + pins at two different later commits with no cut.""" + + refused_by = _pin_guards_refusing(monkeypatch, main=main, county=county, cut=cut) + assert refused_by == refusing + + +#: A later feed cut on the split pin, as a made-up full commit id. When the US +#: feed owner allows one, it takes 60266a3's place. +_NEXT_CUT = "0f" * 20 + + +@pytest.mark.parametrize( + ("main", "refusing"), + [(_NEXT_CUT, ()), (_CUT, (_MOVES,))], + ids=["next-cut", "first-cut-after-the-next-cut"], +) +def test_a_later_cut_replaces_the_first(monkeypatch, main, refusing) -> None: + """Review r3 P2-2: once the allowance names a later cut, the main pin may + name that cut and can no longer name 60266a3.""" + + refused_by = _pin_guards_refusing( + monkeypatch, main=main, county=_COUNTY, cut=_NEXT_CUT + ) + assert refused_by == refusing + + +@pytest.mark.parametrize( + "cut", + [ + _CUT[:7], + _CUT + "0", + _CUT[:39] + "g", + _CUT.upper(), + _COUNTY, + tuple(_CUT), + _CUT.encode(), + ], + ids=[ + "short-cut", + "long-cut", + "non-hex-cut", + "upper-case-cut", + "cut-names-the-county-commit", + "tuple-cut", + "bytes-cut", + ], +) +def test_a_cut_that_is_not_a_full_id_other_than_the_pins_is_refused( + monkeypatch, cut +) -> None: + """Review r3 P2-2 and r4 P2-3: the full-id guard alone refuses each of these + cuts. A 7- or 41-character id fails the length check, a 'g' or upper-case + letters fail the lowercase-hex check, and the county commit fails the + distinct-id check. A tuple of the cut's 40 characters and the cut's bytes + fail the string check. The main pin stays at the split pin, which every + other guard accepts.""" + + refused_by = _pin_guards_refusing(monkeypatch, main=_SPLIT, county=_COUNTY, cut=cut) + assert refused_by == (_FULL_ID,) + + def test_the_feed_builder_accepts_the_county_scope() -> None: scope = _builder().load_scope( _US_PACKAGE / US_CHRONICLE_COUNTY_FACTS_SCOPE_RESOURCE