import json, pytest from pathlib import Path from jof250.embeddings import INDEX_DIR def test_retrieval_relevance_and_provenance(): if not (INDEX_DIR / "units.parquet").exists(): pytest.skip("index not built") from jof250 import retrieval hits = retrieval.search("bank lending relationships and loan spreads", k=5, unit=None) assert hits and all({"doc_id", "doi", "year", "page", "sha256", "confidence"} <= set(h["provenance"]) for h in hits) assert any("loan" in h["text"].lower() or "bank" in h["text"].lower() or "lend" in h["text"].lower() for h in hits) assert all(h["provenance"]["split"] == "train" for h in hits) # held-out excluded by default assert all(len(h["text"]) <= 900 for h in hits) # short excerpts only (no full text)