Point the S3 integration tests back at S3

They opened a client on `tmp_path / "unused"` with the bucket in the
configuration. An explicit path now selects the database, so the client
tests ran against the local disk and the two app tests failed. Nothing names
a path any more, and both helpers assert the connection is remote before
yielding, so a later precedence change cannot quietly localize them again.
This commit is contained in:
Yiorgis Gozadinos 2026-08-26 12:53:52 +03:00
parent 59e05d2c22
commit de8075fcd1
No known key found for this signature in database

View file

@ -3,6 +3,7 @@
# Stop after: # Stop after:
# docker compose -f tests/docker/docker-compose.yml down -v # docker compose -f tests/docker/docker-compose.yml down -v
from contextlib import asynccontextmanager
from uuid import uuid4 from uuid import uuid4
import obstore import obstore
@ -10,10 +11,10 @@ import pytest
from haiku.rag.app import HaikuRAGApp from haiku.rag.app import HaikuRAGApp
from haiku.rag.client import HaikuRAG from haiku.rag.client import HaikuRAG
from haiku.rag.client.scope import DatabaseScope
from haiku.rag.config.models import AppConfig, LanceDBConfig from haiku.rag.config.models import AppConfig, LanceDBConfig
from haiku.rag.s3 import make_s3_store from haiku.rag.s3 import make_s3_store
from haiku.rag.store.engine import Store from haiku.rag.store.engine import ConnectionMode, Store
from tests.conftest import for_path
from tests.services import reachable from tests.services import reachable
S3_ENDPOINT = "http://localhost:8333" S3_ENDPOINT = "http://localhost:8333"
@ -64,6 +65,27 @@ def config():
obstore.delete(store, paths) obstore.delete(store, paths)
def _remote_scope(config: AppConfig) -> DatabaseScope:
"""The configured S3 database.
These tests name no path, so the scope must resolve to the URI. A precedence
change that let a path win would otherwise move them to the local disk and
leave them passing against nothing.
"""
scope = DatabaseScope.resolve(config)
[ref] = scope.databases
assert ref.db_path is None and ref.uri.startswith("s3://")
return scope
@asynccontextmanager
async def _remote_client(config: AppConfig):
"""A client on the configured S3 database, asserting it went there."""
async with HaikuRAG(config=config, create=True) as rag:
assert rag.store._connection_mode is ConnectionMode.OBJECT_STORAGE
yield rag
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_store_connect_and_create(tmp_path, config): async def test_store_connect_and_create(tmp_path, config):
from haiku.rag.store.info import get_database_stats from haiku.rag.store.info import get_database_stats
@ -94,8 +116,8 @@ async def test_store_add_document(tmp_path, config):
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_client_create_document(tmp_path, config): async def test_client_create_document(config):
async with HaikuRAG(tmp_path / "unused", config=config, create=True) as rag: async with _remote_client(config) as rag:
doc = await rag.create_document( doc = await rag.create_document(
"Python is a programming language.", uri="test://python" "Python is a programming language.", uri="test://python"
) )
@ -104,8 +126,8 @@ async def test_client_create_document(tmp_path, config):
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_client_list_documents(tmp_path, config): async def test_client_list_documents(config):
async with HaikuRAG(tmp_path / "unused", config=config, create=True) as rag: async with _remote_client(config) as rag:
await rag.create_document("First document.", uri="test://first") await rag.create_document("First document.", uri="test://first")
await rag.create_document("Second document.", uri="test://second") await rag.create_document("Second document.", uri="test://second")
@ -114,8 +136,8 @@ async def test_client_list_documents(tmp_path, config):
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_client_search(tmp_path, config): async def test_client_search(config):
async with HaikuRAG(tmp_path / "unused", config=config, create=True) as rag: async with _remote_client(config) as rag:
await rag.create_document( await rag.create_document(
"The Eiffel Tower is located in Paris, France.", uri="test://eiffel" "The Eiffel Tower is located in Paris, France.", uri="test://eiffel"
) )
@ -125,8 +147,8 @@ async def test_client_search(tmp_path, config):
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_client_delete_document(tmp_path, config): async def test_client_delete_document(config):
async with HaikuRAG(tmp_path / "unused", config=config, create=True) as rag: async with _remote_client(config) as rag:
doc = await rag.create_document("Temporary document.", uri="test://temp") doc = await rag.create_document("Temporary document.", uri="test://temp")
await rag.delete_document(doc.id) await rag.delete_document(doc.id)
docs = await rag.list_documents() docs = await rag.list_documents()
@ -134,11 +156,11 @@ async def test_client_delete_document(tmp_path, config):
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_app_info(tmp_path, capsys, config): async def test_app_info(capsys, config):
async with HaikuRAG(tmp_path / "unused", config=config, create=True) as rag: async with _remote_client(config) as rag:
await rag.create_document("Info test document.", uri="test://info") await rag.create_document("Info test document.", uri="test://info")
app = HaikuRAGApp(scope=for_path(tmp_path / "unused", config), config=config) app = HaikuRAGApp(scope=_remote_scope(config), config=config)
await app.info() await app.info()
out = capsys.readouterr().out out = capsys.readouterr().out
@ -148,8 +170,8 @@ async def test_app_info(tmp_path, capsys, config):
@pytest.mark.asyncio @pytest.mark.asyncio
async def test_app_info_empty_db(tmp_path, capsys, config): async def test_app_info_empty_db(capsys, config):
app = HaikuRAGApp(scope=for_path(tmp_path / "unused", config), config=config) app = HaikuRAGApp(scope=_remote_scope(config), config=config)
await app.info() await app.info()
out = capsys.readouterr().out out = capsys.readouterr().out