Drop dead .polity_bridge() and mock the crosswalk the aggregator uses - #770
Open
lbm364dl wants to merge 1 commit into
Open
Drop dead .polity_bridge() and mock the crosswalk the aggregator uses#770lbm364dl wants to merge 1 commit into
lbm364dl wants to merge 1 commit into
Conversation
…walk `.polity_bridge()` in R/read_raw_inputs.R memoised an area -> polity bridge that nothing called: `.aggregate_to_polities()` resolves areas through `.add_polity_columns_dt()` -> `.polity_crosswalk()`, because it needs the year-aware lookup, while `.polity_bridge()` wrapped the year-blind `.current_area_lookup()`. Verified against the loaded namespace, not by grep, so a call assembled as a string would also have shown. Two tests in test_read_raw_inputs.R mocked it and read as though the fixture controlled what the aggregator resolved. It did not: they passed because the shipped crosswalk resolves area 203 to Spain / bucket 203 anyway, so the tests silently depended on package data the fixture appeared to rule out. Delete the helper, and route the two tests through a `.local_aggregator_crosswalk()` helper that mocks `.polity_crosswalk()` -- the binding the aggregator actually reaches -- with a deliberately non-shipped `Testland` / `TST-1900-2025` fixture, plus a new test asserting the aggregator carries those values out. That assertion fails when the mock is inert (it sees `Spain` / `ESP-1800-2025`), so the mock can no longer be mistaken for live. No published value changes: the deleted helper had no callers. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What was wrong (mechanism)
.polity_bridge()(R/read_raw_inputs.R) memoised an area → polity bridge thatnothing called. Confirmed against the loaded namespace rather than by grep,
so a call assembled as a string would also have shown:
.aggregate_to_polities(), the only plausible caller, resolves through.add_polity_columns_dt()→.polity_crosswalk()instead, because it needs theyear-aware lookup;
.polity_bridge()wrapped the year-blind.current_area_lookup()(one row perarea_code).The cost was in the tests: two blocks in
test_read_raw_inputs.Rmocked.polity_bridge()and read as though the fixture controlled what the aggregatorresolved. It did not. They passed because the shipped crosswalk resolves area
203 to
ESP-1800-2025/ "Spain" / bucket 203 on its own — so they were not thehermetic unit tests they looked like, and a reader reasoned from a fixture that
was never in play.
What changed
.polity_bridge().local_mocked_bindings(.polity_bridge = …)blocks witha
.local_aggregator_crosswalk()helper that mocks.polity_crosswalk()—the binding the aggregator actually reaches — mirroring what
test_polity_folds.R's.local_fold_crosswalk()already does. Its fixture isdeliberately not a shipped value (
Testland/TST-1900-2025).polity code out, so an inert mock cannot pass again.
Classification: mechanical — dead-code removal plus a test-fidelity fix. No
published value changes; the deleted helper had no callers.
Verification
The new assertion fails whenever the mock is inert. Probe run on the unfixed
code (
git stashof the source change), mocking.polity_bridge()with the sameTestlandfixture:The shipped Spain values leaking through the fixture are the defect. With the
fix, the same assertions routed through the mocked
.polity_crosswalk()pass:air format .clean;lintrclean on both changed files (no lints). No roxygenchange (the helper was undocumented), so no
man/or_pkgdown.ymlupdate.Closes #590.
🤖 Generated with Claude Code