mrme77/dfars-assistant
0
1"""Tests for loading and querying persisted section records."""2 3import json4from pathlib import Path5 6from src.retrieval.section_store import SectionStore, load_sections7 8 9def test_load_sections_reads_jsonl(tmp_path: Path) -> None:10 """It loads section records from JSONL."""11 index_path = tmp_path / "sections.jsonl"12 index_path.write_text(13 json.dumps(14 {15 "section_id": "204.7302",16 "title": "Policy.",17 "page_start": 1,18 "page_end": 2,19 "original_text": "204.7302 Policy.",20 }21 )22 + "\n",23 encoding="utf-8",24 )25 26 sections = load_sections(index_path)27 28 assert sections[0].section_id == "204.7302"29 30 31def test_section_store_exact_lookup_is_case_insensitive(tmp_path: Path) -> None:32 """It returns exact section matches regardless of identifier casing."""33 sections = load_sections(_write_test_index(tmp_path))34 store = SectionStore(sections)35 36 matches = store.exact_lookup("252.204-7012")37 38 assert len(matches) == 139 assert matches[0].title == "Safeguarding Covered Defense Information."40 41 42def _write_test_index(tmp_path: Path) -> Path:43 """Write a small section index for tests."""44 index_path = tmp_path / "sections.jsonl"45 index_path.write_text(46 json.dumps(47 {48 "section_id": "252.204-7012",49 "title": "Safeguarding Covered Defense Information.",50 "page_start": 10,51 "page_end": 12,52 "original_text": "252.204-7012 Safeguarding Covered Defense Information.",53 }54 )55 + "\n",56 encoding="utf-8",57 )58 return index_path59 60 