Repository navigation
Description
Context
test_mapping.py::TestEnrichDataframe::test_enrichment_adds_expected_columns currently checks 5 of 9 filter_cols:
expected_cols = ["country_iso_a3", "admin1_gaul1_code", "admin1_gaul1_name",
"admin2_gaul2_code", "admin2_gaul2_name"]The manager's _append_metadata (unfao.py:146-157) actually requires 9 columns:
filter_cols = [
"pg_xcoord", "pg_ycoord", "country_iso_a3",
"admin1_gaul1_code", "admin1_gaul1_name",
"admin1_gaul0_code", "admin1_gaul0_name",
"admin2_gaul2_code", "admin2_gaul2_name",
]The 4 missing columns (pg_xcoord, pg_ycoord, admin1_gaul0_code, admin1_gaul0_name) have zero schema drift protection. If any of them is renamed or dropped from the mapper's enrichment output, no test fails — but production breaks when _append_metadata tries to select them.
This was identified by the falsification campaign (Claim 4.3, CONTESTED).
Why now
ADR-011 will replace the mapper's enrichment with a Parquet lookup table. The Parquet schema will be the new source of truth for column names. If the precomputed table misses a column, this test must catch it.
Requirements
Modification: test_enrichment_adds_expected_columns
Update the expected_cols list to include all 9 metadata columns:
expected_cols = [
"pg_xcoord", "pg_ycoord", "country_iso_a3",
"admin1_gaul1_code", "admin1_gaul1_name",
"admin1_gaul0_code", "admin1_gaul0_name",
"admin2_gaul2_code", "admin2_gaul2_name",
]Assert each is present in the enriched DataFrame.
New test: test_enrichment_metadata_columns_match_manager_filter_cols
Write a test that explicitly imports or hardcodes the filter_cols list from unfao.py and asserts every column in that list (excluding index columns month_id and priogrid_gid) appears in the mapper's enrichment output. This creates a single point of failure if the two sides diverge.
Acceptance criteria
-
test_enrichment_adds_expected_columnschecks all 9 columns - New test
test_enrichment_metadata_columns_match_manager_filter_colsexists - Both tests pass against synthetic shapefiles
- A column rename on either side (mapper or manager) would fail at least one test
References
- Falsification campaign Claim 4.3 (CONTESTED):
docs/falsification_campaign.md - Test stub:
tests/test_falsification_campaign_4_3.py - Risk register: C-17 (implicit column naming), C-24 (FAO schema divergence)
- Source:
unfao.py:146-157(filter_cols),mapping.py:2709-2714(_process_pg_batch prefix logic)
Activity