fix(tests): avoid ONNX network download in update-length validation tests
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>
This commit is contained in:
committed by
GitHub
parent
42b940d263
commit
24bf97bb65
+6
-28
@@ -198,24 +198,13 @@ def test_query_empty_preserves_embeddings_outer_shape_when_requested():
|
|||||||
assert not_requested.embeddings is None
|
assert not_requested.embeddings is None
|
||||||
|
|
||||||
|
|
||||||
def test_base_collection_update_default_validates_list_lengths(tmp_path):
|
def test_base_collection_update_default_validates_list_lengths():
|
||||||
backend = ChromaBackend()
|
from mempalace.backends.base import BaseCollection
|
||||||
palace_path = tmp_path / "palace"
|
|
||||||
collection = backend.get_collection(
|
collection = ChromaCollection(_FakeCollection())
|
||||||
palace=PalaceRef(id=str(palace_path), local_path=str(palace_path)),
|
|
||||||
collection_name="mempalace_drawers",
|
|
||||||
create=True,
|
|
||||||
)
|
|
||||||
|
|
||||||
# Mismatched documents length → clear ValueError, not silent merge.
|
# Mismatched documents length → clear ValueError, not silent merge.
|
||||||
with pytest.raises(ValueError, match="documents length"):
|
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(
|
BaseCollection.update(
|
||||||
collection,
|
collection,
|
||||||
ids=["1", "2"],
|
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)
|
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."""
|
"""The ABC default update() raises ValueError rather than silently misaligning."""
|
||||||
from mempalace.backends.base import BaseCollection
|
from mempalace.backends.base import BaseCollection
|
||||||
|
|
||||||
backend = ChromaBackend()
|
collection = ChromaCollection(_FakeCollection())
|
||||||
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}],
|
|
||||||
)
|
|
||||||
|
|
||||||
with pytest.raises(ValueError, match="documents length"):
|
with pytest.raises(ValueError, match="documents length"):
|
||||||
BaseCollection.update(collection, ids=["1", "2"], documents=["only-one"])
|
BaseCollection.update(collection, ids=["1", "2"], documents=["only-one"])
|
||||||
|
|||||||
Reference in New Issue
Block a user