Model/backend/documents_parser/tests
Khalim Conn-Kowlessar ea4728c6f6 Slice S0380.170: Community heating mapper unblock (Table 12 dispatch)
Closes the 5 community-heating variants in the heating-systems corpus
(community heating 1/2/3/4/6 on property 001431). Pre-slice the
mapper returned `MainHeatingDetail.main_fuel_type=''` for every
community-heating cert because §14.0 lodges no Fuel Type — only EES
'COM' + a Table 4a heat-network SAP code (301/302/304). The cascade
strict-raised `MissingMainFuelType` per S0380.132. The actual fuel
that bills the cascade lives in the §14.1 Community Heating/Heat
Network block, which the extractor was skipping entirely.

SAP 10.2 Table 12 (PDF p.189) defines the heat-network fuel codes:

  Boilers + Mains Gas        → 51 (heat from boilers — mains gas)
  Boilers + Mineral oil      → 53 (heat from boilers — oil)
  Boilers + Coal             → 54 (heat from boilers — coal)
  Boilers + Biomass          → 43 (heat from boilers — biomass)
  Combined Heat and Power    → 48 (heat from CHP; fuel-agnostic)
  Heat pump + Electricity    → 41 (heat from electric heat pump)

Per spec text the upstream fuel determines the boiler-side code; CHP
is fuel-agnostic at the Table 12 cost / CO2 / PE level.

Three layers wired:

1. Survey schema — new `CommunityHeating` dataclass alongside
   `MainHeating2` carrying the §14.1 fields (heating_type,
   community_heat_source, community_fuel_type, heating_controls_ees,
   heating_controls_sap, chp_fuel_factor). Mutually exclusive with
   `main_heating_2` at the §14.1 level. Attached as
   `MainHeating.community_heating: Optional[CommunityHeating] = None`.

2. Extractor — new `_extract_community_heating()` method bracketed by
   "14.1 Community Heating/Heat Network" / "14.2 Meters". Returns
   None on individually-heated dwellings (no Community Heat Source
   lodged). Wired into `_extract_main_heating()`.

3. Mapper — new `_resolve_community_heating_fuel_code(heat_source,
   fuel)` dispatch helper + `_ELMHURST_COMMUNITY_BOILER_FUEL_TO_TABLE_12`
   constant for the boiler upstream-fuel split. Wired in
   `_map_elmhurst_sap_heating` after the EES-code-to-fuel dispatch
   and before the strict-raise on absent SAP code.

Per the standard slice workflow + [[feedback-aaa-test-convention]]:

- 5 new AAA tests in `test_community_heating_mapper_resolves_table_12_
  fuel_code` parametrized over the 5 corpus variants, asserting the
  mapper resolves the expected Table 12 code per variant.

- The existing parametrized residual-pin test in
  `test_heating_systems_corpus_residual_matches_pin` picks up the
  5 community-heating variants with cascade-side residuals pinned as
  forcing functions for follow-up slices:

      variant            dSAP    dcost     dCO2     dPE
      CH1 (Boilers/Gas)  +0.59   -£14    -787    -3827
      CH2 (CHP/Gas)      +4.50  -£104   -1430    +1506
      CH3 (HP/Elec)      +0.59   -£14   +1614   +11879
      CH4 (CHP/Oil)      +4.50  -£104   -4397     +495
      CH6 (CHP/Coal)     -3.52   +£81   -2935    +7865

  These reflect open cascade-side work (SAP 10.2 Appendix C CHP/
  boiler heat-fraction split missing — cascade treats CHP+Boilers as
  100% CHP; community-HP COP cascade missing — cascade doesn't divide
  delivered heat by COP for Table 12 code 41; heat-network overall
  CO2/PE blended-factor cascade missing — cascade doesn't compute
  worksheet rows (386)/(486)). Pinned per [[feedback-zero-error-strict]];
  follow-up slices close gaps and re-pin smaller residuals.

- `_BLOCKED_BY_MISSING_MAIN_FUEL_TYPE` tuple now empty; the
  blocked-tier test pytest-skipped via `pytest.mark.skipif` with a
  reason naming this slice.

Test baseline at HEAD: 921 pass + 1 skipped (was 916 + 0 at
predecessor 7e08e7af). Pyright net-zero on affected files
(elmhurst_site_notes.py, elmhurst_extractor.py, mapper.py,
test_heating_systems_corpus.py): 32 → 32.

Per [[feedback-spec-citation-in-commits]] the dispatch is grounded
in SAP 10.2 Table 12 (PDF p.189). Per
[[feedback-bigger-slices-for-uniform-work]] all 5 variants land in
one slice — the work is uniform (single Elmhurst label dict + single
dispatch helper) and the per-variant residuals surface together
because of cascade-side gaps, not mapper-side variation.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-04 15:40:25 +00:00
..
fixtures Slice S0380.52: cert 000565 Elmhurst-only mapper-driven cascade pin + glazing-label coverage 2026-05-28 22:03:52 +00:00
__init__.py Map to RdSapSiteNotes from site notes JSON 🟥 2026-04-16 13:54:03 +00:00
test_elmhurst_end_to_end.py Slice S0380.17: map Elmhurst §11 glazing-type labels to SAP10 codes 2026-05-27 23:05:52 +00:00
test_elmhurst_extractor.py extract window frame details from elmhurst site notes 🟥 2026-04-27 15:50:25 +00:00
test_end_to_end.py P6.1 follow-on: unbox BuildingPartIdentifier at backend boundaries 2026-05-20 09:58:23 +00:00
test_extractor.py Handle wall thickness "Unmeasurable" 🟩 2026-04-30 16:41:16 +00:00
test_heating_systems_corpus.py Slice S0380.170: Community heating mapper unblock (Table 12 dispatch) 2026-06-04 15:40:25 +00:00
test_pdf.py rename example site notes to PasHub_ and add Elmhurst example 2026-04-24 13:01:51 +00:00
test_summary_pdf_mapper_chain.py Slice S0380.143: RdSAP 10 §10.11 Table 29 — derive cylinder insulation defaults from construction age band when §15.1 lodges "No Access" 2026-05-31 21:03:10 +00:00