From 9711b2e5f59887c57675cb3355b16add23e67d71 Mon Sep 17 00:00:00 2001 From: Khalim Conn-Kowlessar Date: Wed, 1 Jul 2026 14:30:13 +0000 Subject: [PATCH] =?UTF-8?q?Deterministically=20guard=20the=20high-heat-ret?= =?UTF-8?q?ention=20storage=20description=20=F0=9F=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.8 (1M context) --- .../property_overrides/main_heating_guard.py | 11 +++++ tests/domain/epc/test_main_heating_guard.py | 40 +++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 domain/epc/property_overrides/main_heating_guard.py create mode 100644 tests/domain/epc/test_main_heating_guard.py diff --git a/domain/epc/property_overrides/main_heating_guard.py b/domain/epc/property_overrides/main_heating_guard.py new file mode 100644 index 000000000..fe8e54126 --- /dev/null +++ b/domain/epc/property_overrides/main_heating_guard.py @@ -0,0 +1,11 @@ +from __future__ import annotations + +from typing import Optional + +from domain.epc.property_overrides.main_heating_system_type import ( + MainHeatingSystemType, +) + + +def main_heating_guard(description: str) -> Optional[MainHeatingSystemType]: + raise NotImplementedError diff --git a/tests/domain/epc/test_main_heating_guard.py b/tests/domain/epc/test_main_heating_guard.py new file mode 100644 index 000000000..452474d61 --- /dev/null +++ b/tests/domain/epc/test_main_heating_guard.py @@ -0,0 +1,40 @@ +from __future__ import annotations + +import pytest + +from domain.epc.property_overrides.main_heating_guard import main_heating_guard +from domain.epc.property_overrides.main_heating_system_type import ( + MainHeatingSystemType, +) + + +def test_guard_resolves_high_heat_retention_storage() -> None: + # Arrange — the structured phrasing the LLM funnelled into "old storage" (401). + description = "Electric Storage Systems: High heat retention storage heaters" + + # Act + result = main_heating_guard(description) + + # Assert — HHRSH has its own archetype (SAP 409), never old storage (ADR-0044). + assert result is MainHeatingSystemType.ELECTRIC_STORAGE_HIGH_HEAT_RETENTION + + +@pytest.mark.parametrize( + "description", + [ + # Other storage subtypes the LLM already classifies correctly — the guard + # only rescues the HHRSH gap, leaving the rest to the fallback classifier. + "Electric Storage Systems: Old (large volume) storage heaters", + "Electric Storage Systems: Modern (slimline) storage heaters", + "Electric Storage Systems: Fan storage heaters", + # Unrelated / varied phrasings are the LLM's job. + "Gas boiler", + "", + ], +) +def test_guard_defers_non_hhrsh_descriptions_to_the_llm(description: str) -> None: + # Act + result = main_heating_guard(description) + + # Assert + assert result is None