Group relative-path test with the other connect_lancedb dispatch tests

This commit is contained in:
Yiorgis Gozadinos 2026-04-25 09:28:46 +03:00
parent 7828a8b05d
commit 758bd3ee72
No known key found for this signature in database
3 changed files with 20 additions and 26 deletions

View file

@ -1,6 +1,10 @@
# Changelog
## [Unreleased]
### Fixed
- **Relative `db_path` no longer trips the LanceDB cloud-URI sanitizer.** The 0.43 migration to `lancedb.connect_async` started routing the path through an async URI sanitizer that treats anything not clearly an absolute local path as a possible cloud URI, raising `ValueError: An api_key is required when connecting to LanceDb Cloud` on invocations like `haiku-rag info --db db/rag.lancedb`. The path is now made absolute before being handed to LanceDB.
## [0.43.0] - 2026-04-24
### Changed

View file

@ -1,30 +1,7 @@
import pathlib
from unittest import mock
import pytest
from haiku.rag.config import AppConfig
from haiku.rag.store import Store
from haiku.rag.store.engine import connect_lancedb, get_database_stats
@pytest.mark.asyncio
@pytest.mark.parametrize("w_relative", [False, True])
@mock.patch("lancedb.connect_async")
async def test_connect_lancedb(ldbca, w_relative):
config = AppConfig(environment="testing")
relative_db_path = pathlib.Path("path/to/lancedb")
absolute_db_path = relative_db_path.absolute()
if w_relative:
db_path = relative_db_path
else:
db_path = absolute_db_path
found = await connect_lancedb(config, db_path)
assert found is ldbca.return_value
ldbca.assert_awaited_once_with(absolute_db_path)
from haiku.rag.store.engine import get_database_stats
class TestGetDatabaseStats:

View file

@ -43,13 +43,26 @@ class TestConnectionMode:
class TestConnectLancedb:
@pytest.mark.asyncio
async def test_local_passes_db_path(self, temp_db_path):
async def test_local_passes_absolute_db_path(self, temp_db_path):
config = AppConfig(lancedb=LanceDBConfig(uri=""))
with patch(
"haiku.rag.store.engine.lancedb.connect_async", new_callable=AsyncMock
) as mock_connect:
await connect_lancedb(config, db_path=temp_db_path)
mock_connect.assert_called_once_with(temp_db_path)
mock_connect.assert_called_once_with(temp_db_path.absolute())
@pytest.mark.asyncio
async def test_local_resolves_relative_db_path(self, tmp_path, monkeypatch):
from pathlib import Path
monkeypatch.chdir(tmp_path)
relative = Path("db/rag.lancedb")
config = AppConfig(lancedb=LanceDBConfig(uri=""))
with patch(
"haiku.rag.store.engine.lancedb.connect_async", new_callable=AsyncMock
) as mock_connect:
await connect_lancedb(config, db_path=relative)
mock_connect.assert_called_once_with(relative.absolute())
@pytest.mark.asyncio
async def test_cloud_passes_uri_api_key_region(self):