"""The payload says when the collection looks like it does not cover a question (v1.1 order C, C4). `coverage.absent_terms` is the question's words the collection holds in NO form -- not as written, and not through a relative it uses (`bm25.query_groups`). `coverage.weak` is the machine-readable reading: nothing was delivered, or at least one such word exists. A reader seeing `weak` rephrases in the collection's own words, or says the collection does not cover it. """ from __future__ import annotations import sys from pathlib import Path import pytest from llm_ingestion_okf import consume TOOLS = Path(__file__).resolve().parent.parent / "tools" if str(TOOLS) not in sys.path: sys.path.insert(0, str(TOOLS)) import okf_retrieval_gate as retrieval # noqa: E402 @pytest.fixture(scope="module") def bundle(tmp_path_factory: pytest.TempPathFactory) -> Path: spec = retrieval.BundleSpec( "coverage-synthetic", ( retrieval.DocumentSpec( "cabin", "cabin.md", ( retrieval.ConceptSpec( slug="heating", title="Heating", body="The cabin is heated by a wood stove. Vinterberedskap is checked.", ), retrieval.ConceptSpec( slug="water", title="Water", body="Water comes from the well and is drained in autumn.", ), ), ), ), ) return retrieval.build_bundle(tmp_path_factory.mktemp("coverage") / "bundle", spec) def _coverage(bundle: Path, question: str) -> dict[str, object]: coverage = consume.build_payload(bundle, question=question)["coverage"] assert isinstance(coverage, dict) return coverage def test_a_covered_question_is_not_weak(bundle: Path) -> None: coverage = _coverage(bundle, "How is the cabin heated?") assert coverage["absent_terms"] == [] assert coverage["weak"] is False def test_a_word_held_in_no_form_is_named_and_makes_the_answer_weak(bundle: Path) -> None: coverage = _coverage(bundle, "How is the cabin sauna heated?") assert coverage["absent_terms"] == ["sauna"] assert coverage["weak"] is True def test_a_word_held_in_another_form_is_not_absent(bundle: Path) -> None: coverage = _coverage(bundle, "When is vinterberedskapen checked?") assert coverage["absent_terms"] == [] assert coverage["weak"] is False def test_nothing_delivered_is_weak(bundle: Path) -> None: coverage = _coverage(bundle, "zzqx") assert coverage["weak"] is True def test_the_gates_shared_reading_reads_the_signal(bundle: Path) -> None: payload = consume.build_payload(bundle, question="How is the cabin sauna heated?") assert retrieval.marked(payload) payload = consume.build_payload(bundle, question="How is the cabin heated?") assert not retrieval.marked(payload)