""" tests/conftest.py ================= Shared pytest fixtures for all VoiceVault tests. Fixtures: tmp_db — temporary SQLite database (auto-destroyed after each test) tmp_data_dir — temporary data directory tree sample_chunk — a DocumentChunk instance for retrieval tests sample_citation — a Citation instance for generation tests """ from __future__ import annotations import os from pathlib import Path # Force CPU for all tests — avoids CUDA compatibility issues on unsupported GPUs # (e.g. RTX 5070 / sm_120 not yet supported by packaged PyTorch builds). # "-1" hides all CUDA devices from PyTorch (unlike "", which is ignored on Windows). os.environ["CUDA_VISIBLE_DEVICES"] = "-1" import pytest from voicevault.models import Citation, DocumentChunk from voicevault.storage.sqlite_store import initialize_database @pytest.fixture def tmp_db(tmp_path: Path): """ Provide a fresh, initialized SQLite database in a temp directory. Database is automatically deleted when the test completes. """ db_path = tmp_path / "voicevault.db" initialize_database(db_path) return db_path @pytest.fixture def tmp_data_dir(tmp_path: Path) -> Path: """ Provide a temporary data directory structure mirroring the runtime layout. """ data_dir = tmp_path / "data" (data_dir / "uploads").mkdir(parents=True) (data_dir / "test_kb" / "chroma").mkdir(parents=True) return data_dir @pytest.fixture def sample_chunk() -> DocumentChunk: """Return a minimal valid DocumentChunk for use in retrieval tests.""" return DocumentChunk( kb_name="test_kb", source_file="sample.pdf", page_number=1, section="Introduction", chunk_index=0, text="VoiceVault uses hybrid BM25 and vector search to retrieve relevant document chunks.", text_hash="abc123", token_count=16, language="en", ) @pytest.fixture def sample_citation() -> Citation: """Return a minimal valid Citation for use in generation tests.""" return Citation( source_file="sample.pdf", page_number=1, section="Introduction", excerpt="VoiceVault uses hybrid BM25 and vector search.", relevance_score=0.92, )