Spaces:
Runtime error
Runtime error
| """Notes-bounded baseline reduction (verbatim/passthrough path). | |
| When the surveyor's notes do not map onto the retrieved past-report section, the | |
| system must not reproduce that DIFFERENT property's section as-is. These tests pin | |
| the value-level rule: generic principles survive, foreign specifics the notes never | |
| recorded are dropped, page furniture is stripped — independent of any one example. | |
| """ | |
| from __future__ import annotations | |
| from backend.core.paragraph_merge import bound_baseline_to_notes | |
| def _out(baseline: str, notes: list[str]) -> str: | |
| return bound_baseline_to_notes(baseline, notes).lower() | |
| def test_material_contradiction_dropped_when_notes_say_otherwise(): | |
| # Notes say slate; the other property's baseline says concrete — concrete must go. | |
| baseline = ( | |
| "The pitched roof covering appears to be of plain concrete tiles. " | |
| "Roof coverings of this type should be inspected periodically." | |
| ) | |
| out = _out(baseline, ["imitation slate covering to main roof"]) | |
| assert "concrete" not in out | |
| assert "inspected periodically" in out # generic principle kept | |
| def test_note_corroborated_material_is_kept(): | |
| baseline = "The covering is formed of concrete interlocking tiles." | |
| out = _out(baseline, ["concrete tiles, some slipped"]) | |
| assert "concrete" in out # notes confirm the material → retained | |
| def test_fabricated_photo_methodology_dropped(): | |
| baseline = ( | |
| "We were able to take a selection of photographs and videos using a camera " | |
| "secured to a 3-metre extendable pole. " | |
| "Flat roofs of this kind have a finite service life and will need renewal." | |
| ) | |
| out = _out(baseline, ["dormer flat roof felt looks aged"]) | |
| assert "photographs" not in out | |
| assert "extendable pole" not in out | |
| assert "3-metre" not in out | |
| assert "finite service life" in out # general principle kept | |
| def test_existence_finding_dropped_when_notes_silent(): | |
| baseline = ( | |
| "There were hip irons present to provide support for the hip tiles. " | |
| "Hip irons help prevent hip tiles from slipping should the mortar fail." | |
| ) | |
| out = _out(baseline, ["ridge line looks straight"]) | |
| assert "there were hip irons present" not in out | |
| def test_no_hip_irons_existence_claim_dropped(): | |
| baseline = "No hip irons were present to provide support to the hip tiles." | |
| out = _out(baseline, ["roof covering generally sound"]) | |
| assert out.strip() == "" # the only sentence was a foreign existence claim | |
| def test_position_dropped_unless_in_notes(): | |
| baseline = "The single-storey addition to the rear is of mono-pitched construction." | |
| assert "rear" not in _out(baseline, ["addition roof mono pitch"]) | |
| assert "rear" in _out(baseline, ["rear addition roof, tiles cracked"]) | |
| def test_count_finding_dropped_when_notes_silent_kept_when_present(): | |
| baseline = "One ridge tile is broken and requires replacement." | |
| assert "one ridge tile" not in _out(baseline, ["chimney pots sound"]) | |
| kept = _out(baseline, ["one ridge tile broken, needs replacing"]) | |
| assert "ridge tile" in kept | |
| def test_page_furniture_stripped(): | |
| baseline = "Condition Rating 2. 27" | |
| out = bound_baseline_to_notes(baseline, ["covering worn"]) | |
| assert "27" not in out | |
| # A standalone page-number sentence is removed entirely. | |
| assert bound_baseline_to_notes("28.", ["covering worn"]).strip() == "" | |
| def test_generic_regulatory_boilerplate_kept(): | |
| baseline = ( | |
| "Building Regulations require that any new roof meets specified thermal " | |
| "insulation standards for energy efficiency." | |
| ) | |
| out = _out(baseline, ["nothing relevant to regs in notes"]) | |
| assert "building regulations require" in out | |
| def test_general_principle_kept_when_notes_silent(): | |
| baseline = ( | |
| "Moss and lichen can inhibit the roof's efficiency by trapping moisture, " | |
| "which can lead to deterioration of roof materials over time." | |
| ) | |
| out = _out(baseline, ["gutters clear"]) | |
| assert "moss and lichen can inhibit" in out | |
| def test_whole_foreign_section_not_reproduced_verbatim(): | |
| """A dense foreign section with sparse unrelated notes must shrink, not pass through.""" | |
| baseline = ( | |
| "The pitched roof covering appears to be of plain concrete tiles. " | |
| "The dormer is of flat roof construction finished with bituminised felt. " | |
| "There were hip irons present to support the hip tiles. " | |
| "We inspected the roof using binoculars from ground level. " | |
| "Roofs of this type should be maintained periodically to preserve weatherproofing." | |
| ) | |
| out = bound_baseline_to_notes(baseline, ["loft hatch stiff"]) | |
| # Foreign fabric/existence/method claims gone … | |
| assert "concrete" not in out.lower() | |
| assert "bituminised" not in out.lower() | |
| assert "hip irons present" not in out.lower() | |
| assert "binoculars" not in out.lower() | |
| # … only the general maintenance principle remains. | |
| assert "maintained periodically" in out.lower() | |
| assert len(out) < len(baseline) | |
| def test_empty_when_all_specifics_lets_caller_author_from_notes(): | |
| baseline = ( | |
| "The covering is of concrete tiles. " | |
| "There were hip irons present. " | |
| "We took photographs using an extendable pole." | |
| ) | |
| assert bound_baseline_to_notes(baseline, ["roof felt perished"]).strip() == "" | |