File size: 5,389 Bytes
cf158e8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
"""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() == ""