from pathlib import Path from gamemaster_copilot.ingest import build_index from gamemaster_copilot.index_store import VectorIndex from gamemaster_copilot.embeddings import HashingEmbeddingBackend def test_build_index_from_owned_local_source(tmp_path: Path) -> None: docs_dir = tmp_path / "docs" docs_dir.mkdir() source_doc = docs_dir / "notes.md" source_doc.write_text( "Combat balance depends on readable tradeoffs. " "A stamina mechanic should expose cost, recovery, pressure, and a clear fail state.", encoding="utf-8", ) registry_path = tmp_path / "sources.yaml" registry_path.write_text( """ sources: - id: owned_notes title: Owned Notes path: docs/notes.md license: owned permission: owned attribution: Test Author tags: [balance, mechanics] """, encoding="utf-8", ) index_dir = tmp_path / "index" manifest = build_index( sources_path=registry_path, index_dir=index_dir, embedding_backend="hash", embedding_model="unused", embedding_dimensions=384, chunk_words=24, overlap_words=4, ) assert manifest["chunk_count"] == 1 assert manifest["ingested_source_ids"] == ["owned_notes"] index = VectorIndex(index_dir, HashingEmbeddingBackend()) results = index.search("stamina balance cost recovery", k=3, min_score=0.0) assert len(results) == 1 assert results[0].chunk.source_id == "owned_notes" assert results[0].chunk.license == "owned"