check_source_accessible narrowed its handler to ValueError, but Path.exists re-raises errno values outside its ignored set (EACCES, ENAMETOOLONG). Those were swallowed before and now escaped into the rebuild sweep the guard exists to protect. Catch OSError too. Restore the arity guard in _common_path_prefix: without it an empty list raises from min() and a single label yields a prefix covering the whole path. Two tests would have hung rather than failed on regression (the vacuum skip and the protected-wait cancellation); both are now bounded. The import vacuum test raced against the done-callback that discards the task, and now spies on the call instead, with a negative control. Replace assertions that could not fail: blank-query search against an empty corpus, a batch flush counted against an empty table, a picture description asserting its own input state, and an FS scheme check with nothing on disk to resolve. The get_model matrix asserted only the returned type across 26 cases and now pins the per-provider settings. The three batching tests now count flushes, which revealed embed-only writes through chunks_table.add rather than _flush_rebuild_batch.
72 lines
2.3 KiB
Python
72 lines
2.3 KiB
Python
import pytest
|
|
|
|
from haiku.rag.client import HaikuRAG
|
|
from haiku.rag.config import AppConfig
|
|
|
|
|
|
async def test_database_not_created_without_create_flag(tmp_path):
|
|
"""Test that database is not created without create=True."""
|
|
db_path = tmp_path / "test.lancedb"
|
|
|
|
config = AppConfig()
|
|
|
|
with pytest.raises(FileNotFoundError, match="Database does not exist"):
|
|
async with HaikuRAG(db_path=db_path, config=config):
|
|
pass
|
|
|
|
|
|
async def test_database_created_with_create_flag(tmp_path):
|
|
"""Test that database is created with create=True."""
|
|
db_path = tmp_path / "test.lancedb"
|
|
|
|
config = AppConfig()
|
|
|
|
async with HaikuRAG(db_path=db_path, config=config, create=True):
|
|
assert db_path.exists()
|
|
|
|
|
|
@pytest.mark.vcr()
|
|
async def test_operations_work_after_database_created(tmp_path):
|
|
"""Test that operations work after DB is created."""
|
|
db_path = tmp_path / "test.lancedb"
|
|
|
|
config = AppConfig()
|
|
|
|
# First, create DB with create=True and add document
|
|
async with HaikuRAG(db_path=db_path, config=config, create=True) as client:
|
|
await client.create_document("Test content", uri="test://doc1")
|
|
|
|
# Re-open without create flag and verify we can read the document
|
|
async with HaikuRAG(db_path=db_path, config=config) as client:
|
|
docs = await client.list_documents()
|
|
assert len(docs) == 1
|
|
doc = await client.get_document_by_id(docs[0].id)
|
|
assert doc is not None
|
|
assert doc.content == "Test content"
|
|
|
|
|
|
def test_default_db_path_comes_from_storage_data_dir(tmp_path):
|
|
"""Omitting db_path places the database under the configured data dir."""
|
|
from haiku.rag.client import HaikuRAG
|
|
from haiku.rag.config import AppConfig
|
|
|
|
config = AppConfig()
|
|
config.storage.data_dir = tmp_path
|
|
|
|
client = HaikuRAG(config=config)
|
|
|
|
assert client._db_path == tmp_path / "haiku.rag.lancedb"
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_vacuum_is_callable_on_the_client(temp_db_path):
|
|
"""The public vacuum() delegates to the store."""
|
|
from unittest.mock import AsyncMock, patch
|
|
|
|
from haiku.rag.client import HaikuRAG
|
|
|
|
async with HaikuRAG(temp_db_path, create=True) as client:
|
|
with patch.object(client.store, "vacuum", new=AsyncMock()) as store_vacuum:
|
|
await client.vacuum()
|
|
|
|
store_vacuum.assert_awaited_once()
|