From 0df40278e518a703fc8e6e04a7b31d49bd1c9dce Mon Sep 17 00:00:00 2001 From: Khalim Conn-Kowlessar Date: Tue, 21 Jul 2026 10:12:33 +0000 Subject: [PATCH] =?UTF-8?q?Rank=20costed=20works=20on=20an=20already-compl?= =?UTF-8?q?iant=20dwelling=20HIGH=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) --- tests/scripts/test_audit_anomalies.py | 56 +++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/tests/scripts/test_audit_anomalies.py b/tests/scripts/test_audit_anomalies.py index dd8771500..07ba6d2bc 100644 --- a/tests/scripts/test_audit_anomalies.py +++ b/tests/scripts/test_audit_anomalies.py @@ -1,9 +1,13 @@ +import dataclasses from typing import Optional import pytest from scripts.audit.anomalies import ( + _REGISTRY, PropertyAudit, + Severity, + _already_meets_goal_with_works, _effective_lodged_divergence, _implausible_lodged_score, _plan_stops_short_of_goal, @@ -155,3 +159,55 @@ class TestPlanStopsShortOfGoal: # Assert assert result is None + + +class TestAlreadyMeetsGoalWithWorks: + """Costed works on a dwelling already in the goal band (#1652 / #1654). + + Ranked HIGH: this is the signature of the Optimiser judging the goal against + something other than the published band, and it bills real money — 630 homes + in portfolio 796 published at band C were each sold ~1 SAP point of works + toward a band they had already reached. It must not sit in the + lower-severity bucket that gets waved through as stale-plan noise. + """ + + def test_fires_when_a_dwelling_already_at_goal_is_sold_works(self) -> None: + # Arrange — published band C, scenario goal C, yet £678 of works. + audit = _make_audit(scenario_goal_band="C", cost_of_works=678.0) + audit = dataclasses.replace(audit, effective_band="C") + + # Act + result = _already_meets_goal_with_works(audit) + + # Assert + assert result is not None + assert "678" in result + + def test_silent_when_the_dwelling_is_below_the_goal_band(self) -> None: + # Arrange — published band D against a goal of C: works are warranted. + audit = _make_audit(scenario_goal_band="C", cost_of_works=678.0) + audit = dataclasses.replace(audit, effective_band="D") + + # Act + result = _already_meets_goal_with_works(audit) + + # Assert + assert result is None + + def test_silent_when_an_already_compliant_dwelling_is_sold_nothing(self) -> None: + # Arrange — already band C and a £0 plan: the correct outcome. + audit = _make_audit(scenario_goal_band="C", cost_of_works=0.0) + audit = dataclasses.replace(audit, effective_band="C") + + # Act + result = _already_meets_goal_with_works(audit) + + # Assert + assert result is None + + def test_is_registered_at_high_severity(self) -> None: + # Act — the severity the runner reports it under. + registered = {name: severity for name, severity, _ in _REGISTRY} + + # Assert + assert registered["already-meets-goal-with-works"] is Severity.HIGH