Test vacuum against real table state

This commit is contained in:
Yiorgis Gozadinos 2026-07-27 12:11:01 +03:00
parent f96a428ef1
commit a602e0fbf5
No known key found for this signature in database

View file

@ -59,14 +59,20 @@ def test_default_db_path_comes_from_storage_data_dir(tmp_path):
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_vacuum_is_callable_on_the_client(temp_db_path): async def test_vacuum_optimizes_tables_without_losing_rows(temp_db_path):
"""The public vacuum() delegates to the store.""" """The public vacuum() runs the store's optimize pass over real rows."""
from unittest.mock import AsyncMock, patch from haiku.rag.store.models.document import Document
from haiku.rag.store.repositories.document import DocumentRepository
from haiku.rag.client import HaikuRAG
async with HaikuRAG(temp_db_path, create=True) as client: async with HaikuRAG(temp_db_path, create=True) as client:
with patch.object(client.store, "vacuum", new=AsyncMock()) as store_vacuum: repo = DocumentRepository(client.store)
await client.vacuum() for i in range(3):
await repo.create(Document(content=f"body {i}", uri=f"test://doc{i}"))
before = len(await client.store.documents_table.list_versions())
store_vacuum.assert_awaited_once() await client.vacuum()
# Optimize compacts the per-document fragments into new versions; an
# unchanged count would mean nothing reached the tables.
assert len(await client.store.documents_table.list_versions()) > before
assert await client.count_documents() == 3