"""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()