diff --git a/app/api/library.py b/app/api/library.py index 2f10834..40fa525 100644 --- a/app/api/library.py +++ b/app/api/library.py @@ -30,12 +30,17 @@ def _dispatch_ingest( background_tasks: BackgroundTasks, ) -> str: """Dispatch an ingest task. Tries cf-orch; falls back to BackgroundTasks.""" + import os as _os + from pathlib import Path as _Path + + # Read lazily so test fixtures (monkeypatch.setenv) take effect + _data_dir = _Path(_os.environ.get("PAGEPIPER_DATA_DIR", "data")) task_id = str(uuid.uuid4()) args = { "doc_id": doc_id, "file_path": file_path, - "db_path": DB_PATH, - "vec_db_path": VEC_DB_PATH, + "db_path": str(_data_dir / "pagepiper.db"), + "vec_db_path": str(_data_dir / "pagepiper_vecs.db"), } try: @@ -52,7 +57,7 @@ def _dispatch_ingest( return task_id -def _run_ingest_background(run_fn, args: dict, task_id: str) -> None: +def _run_ingest_background(run_fn: Callable[..., None], args: dict, task_id: str) -> None: from app.api.ingest import _task_registry _task_registry[task_id] = {"status": "running", "progress": 0} try: @@ -61,6 +66,7 @@ def _run_ingest_background(run_fn, args: dict, task_id: str) -> None: if _mark_bm25_dirty: _mark_bm25_dirty() except Exception as exc: + logger.exception("Ingest task %s failed", task_id) _task_registry[task_id] = {"status": "error", "error": str(exc)} diff --git a/tests/conftest.py b/tests/conftest.py index c204030..3acd092 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -26,9 +26,13 @@ def client(test_db, tmp_path, monkeypatch): monkeypatch.setenv("PAGEPIPER_WATCH_DIR", str(tmp_path / "books")) (tmp_path / "books").mkdir(exist_ok=True) + import app.main as _main_module from app.main import app, _bm25 from app.deps import get_db + # Suppress migrations during tests — test_db fixture already applies the schema + monkeypatch.setattr(_main_module, "_apply_migrations", lambda: None) + def override_db(): conn = sqlite3.connect(test_db) conn.execute("PRAGMA foreign_keys = ON")