From 24bf97bb65c38bd4069d78a864f65ea0200a6851 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 18 Apr 2026 16:23:58 +0000 Subject: [PATCH] fix(tests): avoid ONNX network download in update-length validation tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit test_base_collection_update_default_validates_list_lengths and test_base_collection_update_default_rejects_mismatched_lengths were spinning up a real ChromaBackend and calling add(documents=...), which triggered ChromaDB's default ONNX embedding function and attempted a network download — failing in offline/sandboxed CI. BaseCollection.update() validates list lengths before any DB access, so no items need to be pre-loaded for the length-check to fire. Switch both tests to use _FakeCollection (same as the rest of the unit tests in this file) so they are pure in-memory and network-free. Also fixes a structural bug in test 1: collection._collection.add() was accidentally placed inside the pytest.raises(ValueError) block, masking the real assertion. Agent-Logs-Url: https://github.com/MemPalace/mempalace/sessions/55fc663e-b256-4b8b-88ce-4271560def8d Co-authored-by: igorls <4753812+igorls@users.noreply.github.com> --- tests/test_backends.py | 34 ++++++---------------------------- 1 file changed, 6 insertions(+), 28 deletions(-) diff --git a/tests/test_backends.py b/tests/test_backends.py index f019927..29f2b9b 100644 --- a/tests/test_backends.py +++ b/tests/test_backends.py @@ -198,24 +198,13 @@ def test_query_empty_preserves_embeddings_outer_shape_when_requested(): assert not_requested.embeddings is None -def test_base_collection_update_default_validates_list_lengths(tmp_path): - backend = ChromaBackend() - palace_path = tmp_path / "palace" - collection = backend.get_collection( - palace=PalaceRef(id=str(palace_path), local_path=str(palace_path)), - collection_name="mempalace_drawers", - create=True, - ) +def test_base_collection_update_default_validates_list_lengths(): + from mempalace.backends.base import BaseCollection + + collection = ChromaCollection(_FakeCollection()) # Mismatched documents length → clear ValueError, not silent merge. with pytest.raises(ValueError, match="documents length"): - collection._collection.add( - documents=["a", "b"], - ids=["1", "2"], - metadatas=[{"k": 1}, {"k": 2}], - ) - from mempalace.backends.base import BaseCollection - BaseCollection.update( collection, ids=["1", "2"], @@ -274,22 +263,11 @@ def test_chroma_cache_picks_up_db_created_after_first_open(tmp_path): assert backend._freshness[str(palace_path)] != (0, 0.0) -def test_base_collection_update_default_rejects_mismatched_lengths(tmp_path): +def test_base_collection_update_default_rejects_mismatched_lengths(): """The ABC default update() raises ValueError rather than silently misaligning.""" from mempalace.backends.base import BaseCollection - backend = ChromaBackend() - palace_path = tmp_path / "palace" - collection = backend.get_collection( - palace=PalaceRef(id=str(palace_path), local_path=str(palace_path)), - collection_name="mempalace_drawers", - create=True, - ) - collection.add( - documents=["a", "b"], - ids=["1", "2"], - metadatas=[{"k": 1}, {"k": 2}], - ) + collection = ChromaCollection(_FakeCollection()) with pytest.raises(ValueError, match="documents length"): BaseCollection.update(collection, ids=["1", "2"], documents=["only-one"])