From 758bd3ee72c57e7154aa566a8e051fb820ba5f88 Mon Sep 17 00:00:00 2001 From: Yiorgis Gozadinos Date: Sat, 25 Apr 2026 09:28:46 +0300 Subject: [PATCH] Group relative-path test with the other connect_lancedb dispatch tests --- CHANGELOG.md | 4 ++++ tests/store/test_engine.py | 25 +------------------------ tests/test_lancedb_connection.py | 17 +++++++++++++++-- 3 files changed, 20 insertions(+), 26 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 356a7d7a..c129e3c1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/tests/store/test_engine.py b/tests/store/test_engine.py index 86577393..73737fd4 100644 --- a/tests/store/test_engine.py +++ b/tests/store/test_engine.py @@ -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: diff --git a/tests/test_lancedb_connection.py b/tests/test_lancedb_connection.py index 39301411..ffc49e52 100644 --- a/tests/test_lancedb_connection.py +++ b/tests/test_lancedb_connection.py @@ -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):