SurfSense/surfsense_backend/tests/integration/indexing_pipeline/cache/conftest.py
CREDO23 412493ae08 test(embedding-cache): add integration tests for service, repository, and store
Covers the public cache surface against real Postgres and a real local file
backend (no mocks): recall miss, remember->recall vector/text/order round-trip,
the dimension-mismatch refusal, the repository SQL behind eviction and dedup
(size sum, coldest ordering, TTL cutoff, duplicate-key no-op, reuse counter),
and the blob store save/load round-trip and delete.
2026-06-12 17:33:21 +02:00

33 lines
1.2 KiB
Python

"""Real-infra fixtures for the embedding-cache integration tests.
``cache_local_storage`` points the shared cache backend at a throwaway directory
so tests exercise the real ``LocalFileBackend`` (no cloud, no mocks); the
embedding cache reuses the ETL cache backend, hence the ``ETL_CACHE_STORAGE_*``
knobs. ``clean_embedding_cache_table`` removes rows written through the store's
own committing session, which the savepoint-rolled-back ``db_session`` cannot undo.
"""
from __future__ import annotations
import pytest
import pytest_asyncio
from sqlalchemy import text
@pytest.fixture
def cache_local_storage(tmp_path, monkeypatch):
from app.config import config
from app.etl_pipeline.cache.storage.backend import resolve_cache_backend
monkeypatch.setattr(config, "ETL_CACHE_STORAGE_BACKEND", "local")
monkeypatch.setattr(config, "ETL_CACHE_STORAGE_LOCAL_PATH", str(tmp_path))
resolve_cache_backend.cache_clear()
yield tmp_path
resolve_cache_backend.cache_clear()
@pytest_asyncio.fixture
async def clean_embedding_cache_table(async_engine):
yield
async with async_engine.begin() as conn:
await conn.execute(text("DELETE FROM embedding_cache_sets"))