From abeb6089e56e3fa70698f0613e41847ac3b94219 Mon Sep 17 00:00:00 2001 From: pyr0ball Date: Mon, 4 May 2026 17:13:50 -0700 Subject: [PATCH] fix(config): handle /v1 suffix in PAGEPIPER_OLLAMA_URL; add DATA_DIR mkdir guard --- app/config.py | 5 ++++- tests/test_db_migrate.py | 12 +++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/app/config.py b/app/config.py index 2938887..9459f42 100644 --- a/app/config.py +++ b/app/config.py @@ -6,6 +6,7 @@ import os from pathlib import Path DATA_DIR = Path(os.environ.get("PAGEPIPER_DATA_DIR", "data")) +DATA_DIR.mkdir(parents=True, exist_ok=True) DB_PATH = str(DATA_DIR / "pagepiper.db") VEC_DB_PATH = str(DATA_DIR / "pagepiper_vecs.db") WATCH_DIR = Path(os.environ.get("PAGEPIPER_WATCH_DIR", "books")) @@ -16,12 +17,14 @@ def get_llm_config() -> dict | None: url = os.environ.get("PAGEPIPER_OLLAMA_URL", "").strip() if not url: return None + _clean = url.rstrip("/") + _base_url = _clean if _clean.endswith("/v1") else _clean + "/v1" return { "fallback_order": ["ollama"], "backends": { "ollama": { "type": "openai_compat", - "base_url": url.rstrip("/") + "/v1", + "base_url": _base_url, "model": os.environ.get("PAGEPIPER_CHAT_MODEL", "mistral:7b"), "embedding_model": os.environ.get( "PAGEPIPER_EMBED_MODEL", "nomic-embed-text" diff --git a/tests/test_db_migrate.py b/tests/test_db_migrate.py index 445969e..3e1128f 100644 --- a/tests/test_db_migrate.py +++ b/tests/test_db_migrate.py @@ -10,7 +10,9 @@ import pytest def test_migration_creates_documents_table(tmp_path): db_path = str(tmp_path / "test.db") - schema = Path("migrations/001_initial_schema.sql").read_text() + schema = ( + Path(__file__).parent.parent / "migrations/001_initial_schema.sql" + ).read_text() conn = sqlite3.connect(db_path) conn.executescript(schema) @@ -28,7 +30,9 @@ def test_migration_creates_documents_table(tmp_path): def test_documents_table_has_required_columns(tmp_path): db_path = str(tmp_path / "test.db") - schema = Path("migrations/001_initial_schema.sql").read_text() + schema = ( + Path(__file__).parent.parent / "migrations/001_initial_schema.sql" + ).read_text() conn = sqlite3.connect(db_path) conn.executescript(schema) @@ -47,7 +51,9 @@ def test_documents_table_has_required_columns(tmp_path): def test_page_chunks_foreign_key_cascades(tmp_path): db_path = str(tmp_path / "test.db") - schema = Path("migrations/001_initial_schema.sql").read_text() + schema = ( + Path(__file__).parent.parent / "migrations/001_initial_schema.sql" + ).read_text() conn = sqlite3.connect(db_path) conn.executescript(schema)