Full-SAP certs rebaseline off the lodged SAP-2012 value (downgrade fix) 🟩

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Khalim Conn-Kowlessar 2026-06-25 20:43:31 +00:00
parent 5149400f96
commit f568ec00fc

View file

@ -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