From e2e0a8dc1b8f911a9177e66e7b8669f89fd576de Mon Sep 17 00:00:00 2001 From: Yiorgis Gozadinos Date: Thu, 4 Jun 2026 12:21:47 +0300 Subject: [PATCH] Cover the Postgres queue construction paths in CI --- pyproject.toml | 4 ++++ tests/ingester/test_queue.py | 29 +++++++++++++++++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index a19e2792..bbba744a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -135,6 +135,10 @@ filterwarnings = ["error", "ignore::UserWarning", "ignore::DeprecationWarning"] [tool.coverage.run] source = ["haiku_rag_slim"] +# aiosqlite runs sqlite (and the queue's PRAGMA connect listener) off the main +# flow via a greenlet + worker thread; track both so that code isn't reported +# as uncovered. +concurrency = ["greenlet", "thread"] omit = [ "haiku_rag_slim/haiku/rag/chat/*", "haiku_rag_slim/haiku/rag/inspector/*", diff --git a/tests/ingester/test_queue.py b/tests/ingester/test_queue.py index 058b4f77..134f3289 100644 --- a/tests/ingester/test_queue.py +++ b/tests/ingester/test_queue.py @@ -5,9 +5,14 @@ import pytest import sqlalchemy as sa from haiku.rag.config import QueueConfig -from haiku.rag.ingester.queue.migrations import apply_migrations, open_queue +from haiku.rag.ingester.queue.db import jobs as jobs_table +from haiku.rag.ingester.queue.migrations import ( + apply_migrations, + make_engine, + open_queue, +) from haiku.rag.ingester.queue.models import JobOp, JobStatus, SyncRow -from haiku.rag.ingester.queue.repository import JobRepo +from haiku.rag.ingester.queue.repository import JobRepo, _insert # --- migrations / schema --- @@ -44,6 +49,26 @@ async def test_open_queue_creates_file_and_schema(tmp_path): await eng.dispose() +@pytest.mark.asyncio +async def test_make_engine_postgres_is_pre_ping(): + """The Postgres branch builds a pre-ping engine without connecting.""" + engine = make_engine(QueueConfig(dburi="postgresql+asyncpg://u:p@localhost/db")) + try: + assert engine.dialect.name == "postgresql" + assert engine.pool._pre_ping is True + finally: + await engine.dispose() + + +def test_insert_uses_dialect_specific_construct(): + """_insert dispatches to the dialect's INSERT (which exposes on_conflict_*).""" + from sqlalchemy.dialects.postgresql import Insert as PostgresInsert + from sqlalchemy.dialects.sqlite import Insert as SqliteInsert + + assert isinstance(_insert(jobs_table, "postgresql"), PostgresInsert) + assert isinstance(_insert(jobs_table, "sqlite"), SqliteInsert) + + @pytest.mark.asyncio async def test_open_queue_handles_path_with_url_chars(tmp_path): """A `?` (or `#`) is a valid POSIX filename char but has URL meaning.