File size: 3,098 Bytes
aad7814
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Interference level routing and LLM composition paths."""

from __future__ import annotations

from backend.core import maximum_compose, medium_expand
from backend.core.interference import resolve_interference_level
from backend.llm import openai_client
from backend.models.schema import TemplateSchema


def test_survey_level_maps_to_interference():
    assert resolve_interference_level(None, 3) == "maximum"
    assert resolve_interference_level(None, 2) == "medium"
    assert resolve_interference_level(None, 1) == "minimum"
    assert resolve_interference_level("medium", 3) == "medium"


def test_maximum_compose_calls_llm_with_schema_guided_prompt(monkeypatch):
    captured: list[list[dict]] = []

    def fake_chat(messages, **kwargs):
        captured.append(messages)
        return (
            "The roof coverings were inspected from ground level using binoculars. "
            "The main roof covering comprises natural slate tiles laid to pitched "
            "timber rafters. A slate tile was noted slipped on the south elevation slope."
        )

    monkeypatch.setattr(openai_client, "is_available", lambda: True)
    monkeypatch.setattr(openai_client, "chat_text", fake_chat)

    refs = [
        (
            "The roof coverings were inspected from ground level using binoculars. "
            "The main roof covering comprises natural slate tiles laid to pitched "
            "timber rafters with underfelt and counter battens."
        ),
    ]
    schema = TemplateSchema()
    out = maximum_compose.compose_maximum_ai(
        ["slate tile slipped south slope"],
        refs,
        section_title="Roof Coverings",
        schema=schema,
    )
    assert captured
    assert "INPUT 2: CURRENT INSPECTION NOTES" in captured[0][1]["content"]
    assert (
        "INTEGRATED NARRATIVE DRAFTING" in captured[0][0]["content"]
        or "INPUT 1: STYLE EXAMPLES" in captured[0][1]["content"]
    )
    assert "south" in out.lower()


def test_medium_expand_calls_llm_with_section_context(monkeypatch):
    captured: list[list[dict]] = []

    def fake_chat(messages, **kwargs):
        captured.append(messages)
        return (
            "The roof covering comprised slate tiles laid to pitched timber rafters. "
            "Inspection was limited to ground level using binoculars. "
            "A slate tile was noted slipped on the south elevation slope."
        )

    monkeypatch.setattr(openai_client, "is_available", lambda: True)
    monkeypatch.setattr(openai_client, "chat_text", fake_chat)

    reference = (
        "The roof covering comprised slate tiles laid to pitched timber rafters. "
        "Inspection was limited to ground level using binoculars."
    )
    out = medium_expand.expand_medium_ai(
        ["slate tile slipped south slope"],
        reference,
        schema=TemplateSchema(),
        section_title="Roof Coverings",
    )
    assert captured
    assert "ABSOLUTE HISTORICAL GROUNDING" in captured[0][0]["content"]
    assert "* slate tile slipped south slope" in captured[0][1]["content"]
    assert "south" in out.lower()