From 2325f187b538713e4110477a9f8556c0004014cd Mon Sep 17 00:00:00 2001 From: Yiorgis Gozadinos Date: Fri, 28 Aug 2026 13:29:16 +0300 Subject: [PATCH] Fix a client's coverage when it is first entered `_resolve_scope` returned a scope without keeping it, so a client re-entered after its configuration was edited covered whatever the configuration then said. Resolving once is what the rest of the design rests on: the scope is what names results, citations and errors. A configuration is still free to change before first entry. --- haiku_rag_slim/haiku/rag/client/__init__.py | 1 + tests/multi_db/test_lifecycle.py | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/haiku_rag_slim/haiku/rag/client/__init__.py b/haiku_rag_slim/haiku/rag/client/__init__.py index 1289d8c1..160ec134 100644 --- a/haiku_rag_slim/haiku/rag/client/__init__.py +++ b/haiku_rag_slim/haiku/rag/client/__init__.py @@ -314,6 +314,7 @@ class HaikuRAG: ) if self._requested_sources is not None and self._requested_db_path is None: scope = scope.select(self._requested_sources) + self._scope = scope return scope async def __aenter__(self): diff --git a/tests/multi_db/test_lifecycle.py b/tests/multi_db/test_lifecycle.py index 2f7e65bc..6dbe6781 100644 --- a/tests/multi_db/test_lifecycle.py +++ b/tests/multi_db/test_lifecycle.py @@ -94,6 +94,23 @@ class TestOpeningDatabases: assert not alpha.store.db.is_open() + @pytest.mark.asyncio + async def test_a_client_keeps_the_databases_it_first_covered(self, tmp_path): + """Resolution happens once, so a configuration edited afterwards does not + change what an already-entered client covers.""" + config = _config(tmp_path, ["alpha", "beta"]) + await _seed(config, "alpha", ["alpha document about cats"]) + await _seed(config, "beta", ["beta document about cats"]) + + rag = HaikuRAG(config=config) + async with rag: + assert rag.source_names == ("alpha", "beta") + + config.lancedb.databases = {"gamma": str(tmp_path / "gamma.lancedb")} + + async with rag: + assert rag.source_names == ("alpha", "beta") + @pytest.mark.asyncio async def test_a_failing_read_leaves_no_sibling_reading( self, tmp_path, monkeypatch