From f568ec00fc85eff10e61467c1b209f7013829b59 Mon Sep 17 00:00:00 2001 From: Khalim Conn-Kowlessar Date: Thu, 25 Jun 2026 20:43:31 +0000 Subject: [PATCH] =?UTF-8?q?Full-SAP=20certs=20rebaseline=20off=20the=20lod?= =?UTF-8?q?ged=20SAP-2012=20value=20(downgrade=20fix)=20=F0=9F=9F=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.8 (1M context) --- .../test_calculator_rebaseliner.py | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/tests/domain/property_baseline/test_calculator_rebaseliner.py b/tests/domain/property_baseline/test_calculator_rebaseliner.py index 000d28ef..766da437 100644 --- a/tests/domain/property_baseline/test_calculator_rebaseliner.py +++ b/tests/domain/property_baseline/test_calculator_rebaseliner.py @@ -145,3 +145,40 @@ def test_a_calculator_raise_propagates_and_aborts() -> None: # Act / Assert with pytest.raises(UnmappedSapCode): rebaseliner.rebaseline(property_id=10, effective_epc=epc, lodged=_lodged()) + + +def test_full_sap_mapped_cert_rebaselines_off_the_lodged_sap_2012_value() -> None: + # Regression for the portfolio-796 "impossible downgrade" (ADR-0037). A + # full-SAP cert lodges SAP 2012 (sap_version 9.92). The WIP mapper dropped + # sap_version, so the rebaseliner couldn't fire trigger (a) and Effective + # stayed stuck on the lodged SAP-2012 value while the plan modelled SAP-10.2. + # End-to-end: a real full-SAP fixture, once mapped, now carries sap_version + # so Effective becomes the calc output (not lodged). + import json + import os + + from datatypes.epc.domain.mapper import EpcPropertyDataMapper + from datatypes.epc.schema.sap_schema_17_1 import SapSchema17_1 + from datatypes.epc.schema.tests.helpers import from_dict + + fixtures = os.path.join( + os.path.dirname(__file__), + "../../../datatypes/epc/schema/tests/fixtures", + ) + with open(os.path.join(fixtures, "sap_17_1.json")) as f: + raw = json.load(f) + effective_epc = EpcPropertyDataMapper.from_sap_schema_17_1( + from_dict(SapSchema17_1, raw) + ) + # The mapped cert carries the lodged SAP 2012 version, gating the flip. + assert effective_epc.sap_version == 9.92 + rebaseliner = CalculatorRebaseliner(_StubCalculator(_sap_result(sap_score=70))) + + # Act + result = rebaseliner.rebaseline( + property_id=1, effective_epc=effective_epc, lodged=_lodged() + ) + + # Assert — Effective is the SAP-10.2 calc (70), NOT the lodged SAP-2012 (72). + assert result.reason == "pre_sap10" + assert result.effective.sap_score == 70