Skip to content

S2 — Coverage contract: assert expected cell count + log cell counts (C-34) #53

Description

@Polichinel

Epic: #51 · risk-register C-34 (Tier 2) · foundational — S4 builds on this

Problem

Nothing asserts how many cells the FAO pipeline should process. The coverage decision lives in views-models (config_queryset.py:REGION), the cell-set in views-datafactory, and the consequences here — but unfao.py has no counterpart check. A wrong or upstream-changed region delivers partial coverage to FAO with no signal.

Context

  • _validate (unfao.py:147-172) checks only null-ness of the 9 metadata columns; never row/cell counts.
  • The enricher already computes + logs the unmapped count (enrichment.py:117-125) — but there is no expected total to compare against, and nothing is asserted.
  • Current REGION = "africa_me_legacy" (~13,110 cells); the land_gaul switch (~64,736) is imminent (views-models#127).

Work

  • Establish an expected-cell-count source keyed by region (config value or a small region→count map) so the manager knows the contract for the configured region.
  • In _read and _validate: log cell/row counts (historical + forecast) — fetched, enriched, unmapped.
  • In _validate (or a new _validate_coverage): assert completeness — distinct enriched cells == expected for the region; raise loud on under/over.
  • Keep the existing null-gate; this adds a count-gate alongside it.

Acceptance criteria

  • The configured region's expected cell count is available to the manager (no inline magic numbers).
  • _read/_validate log cell counts; expected≠actual raises ValueError with a clear message.
  • Unit tests: correct count passes; under-coverage and over-coverage each raise.

Implementation notes

  • Surface the enricher's unmapped accounting (return value/attribute) so _validate can assert on it, not just log.
  • Keep the count source declarative so S4 can pin land_gaul = 64,736.

Files

views_postprocessing/unfao/managers/unfao.py (_read, _validate); possibly gaul_schema.py / a region-count config; tests/.

Metadata

Metadata

Assignees

No one assigned

    Labels

    implementationCode implementation workstoryA single reviewable unit of an epic

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions