import os import shutil import tempfile from pathlib import Path import pytest from fastapi.testclient import TestClient from app.config import DATA_DIR from app.engine import DuckDBEngine from app.git_sync import GitSyncManager from app.main import app @pytest.fixture(scope="session") def test_data_dir(): temp_root = Path(tempfile.mkdtemp()) temp_data = temp_root / "data" if DATA_DIR.is_dir(): shutil.copytree(DATA_DIR, temp_data) else: temp_data.mkdir(parents=True, exist_ok=True) yield temp_data shutil.rmtree(temp_root, ignore_errors=True) @pytest.fixture def engine(test_data_dir): return DuckDBEngine(data_dir=test_data_dir) @pytest.fixture def client(engine): app.state.engine = engine app.state.git_sync = GitSyncManager(wiki_dir=engine.data_dir.parent) with TestClient(app) as c: yield c