Spaces:
Runtime error
Runtime error
| """Guard for CONSTANT 2.1 relocation (see backend/docs/RICS_CONSTANT_INVENTORY.md). | |
| ``pii_scrubber._STATUS_TERMS`` previously inlined the RICS rating label | |
| "condition rating". Post-refactor the rating term is derived from the canonical | |
| ``DEFAULT_RATING_SYSTEM_NAME`` (rics_canonical_l3.py) and the remaining terms | |
| live in ``_BASE_STATUS_TERMS``. The effective whitelist must stay byte-identical | |
| as a set — zero terms added or removed — and the relocated term must still be | |
| protected from redaction. | |
| Pre-refactor this module FAILS at import (``_BASE_STATUS_TERMS`` does not exist); | |
| post-refactor it PASSES. | |
| """ | |
| from __future__ import annotations | |
| from backend.core import pii_scrubber | |
| from backend.core.pii_scrubber import ( | |
| _BASE_STATUS_TERMS, | |
| _STATUS_TERMS, | |
| PROPTECH_SAFE_WHITELIST, | |
| ) | |
| from backend.core.rics_canonical_l3 import DEFAULT_RATING_SYSTEM_NAME | |
| # Exactly the terms enumerated in the inventory for 2.1 — no more, no less. | |
| _EXPECTED_STATUS_TERMS = frozenset( | |
| { | |
| "condition rating", | |
| "defect", | |
| "satisfactory", | |
| "serviceable", | |
| "deflection", | |
| "distortion", | |
| "cracking", | |
| "spalled", | |
| "damp", | |
| "moisture", | |
| "insulation", | |
| } | |
| ) | |
| def test_status_terms_exactly_match_inventory(): | |
| assert _STATUS_TERMS == _EXPECTED_STATUS_TERMS # no terms added or removed | |
| def test_rating_term_is_canonical_derived_not_inlined(): | |
| rating_term = DEFAULT_RATING_SYSTEM_NAME.lower() | |
| assert rating_term == "condition rating" | |
| assert rating_term in _STATUS_TERMS | |
| # The rating term must come from the canonical seed, not the inlined base set. | |
| assert rating_term not in _BASE_STATUS_TERMS | |
| assert _STATUS_TERMS == _BASE_STATUS_TERMS | frozenset({rating_term}) | |
| def test_status_terms_remain_in_global_whitelist(): | |
| assert _STATUS_TERMS <= PROPTECH_SAFE_WHITELIST | |
| def test_relocated_rating_phrase_still_survives_scrub(): | |
| # PII boundary must not shift: the protected phrase stays unredacted. | |
| text = "The survey records a condition rating against the roof covering." | |
| result = pii_scrubber.scrub(text) | |
| assert "condition rating" in result.text.lower() | |
| assert result.total == 0 | |