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