Graph-Native Infrastructure for Context and Accountable AI Systems
Python agent-memoryaiai-governanceai-infrastructureartificial-intelligencecontext-engineeringcontext-graphsdata-engineeringdecision-intelligencedeveloper-toolsexplainable-aigenerative-aigraph-ragknowledge-graphllmontologyprovenancepythonreasoningsemantic-search
test(vector_store): make contract xfails reachable and cover the backend roster
Zohaib Hassnain73b14c00ba41
diff --git a/tests/vector_store/test_backend_facade_contract.py b/tests/vector_store/test_backend_facade_contract.pyindex 7dd74425..eb853581 100644--- a/tests/vector_store/test_backend_facade_contract.py+++ b/tests/vector_store/test_backend_facade_contract.py@@ -1,31 +1,28 @@"""Facade-level contract tests for the cloud vector store backends.-Every other test in this directory either mocks a backend's internals or-injects a fake directly into ``VectorStore._backend_store``. Both bypass-``_init_backend_store``, which is where the qdrant/pinecone/milvus/weaviate-adapters are actually constructed, so a backend can look fully covered while-being unusable through the public facade.--These tests construct each backend through the real facade path and assert on-the two capabilities ``store migrate`` depends on: an established connection,-and a write path the facade can dispatch to.--Gaps are recorded as strict xfail rather than as assertions that the gap-exists. When the wiring lands these turn into XPASS, which strict mode reports-as a failure, so whoever fixes it is told to remove the marker instead of the-pin silently rotting.--Related: #1265 (enumeration), #1019 (backend conformance).+Other tests here either mock a backend's internals or inject a fake into+``VectorStore._backend_store``. Both skip ``_init_backend_store``, which is+where the qdrant/pinecone/milvus/weaviate adapters are built, and that is how+#1316 shipped green while a qdrant-backed store could neither read nor write.++Gaps are recorded as strict xfail so they turn into XPASS once the wiring+lands, failing the suite until the stale marker is removed.++Related: #1265, #1019."""-from unittest.mock import patch+from contextlib import ExitStack+from unittest.mock import MagicMock, patchimport numpy as npimport pytestfrom semantica.vector_store import VectorStore-# Backends whose adapters need a network connection established before use.+# Availability flag per backend, plus every symbol its connect/select path+# calls. The clients must be patched too: without the real SDK installed they+# are None, so a fixed _init_backend_store would still fail and these could+# never reach XPASS. Extend these if the wiring touches more symbols._AVAILABILITY_FLAG = {"qdrant": "semantica.vector_store.qdrant_store.QDRANT_AVAILABLE","pinecone": "semantica.vector_store.pinecone_store.PINECONE_AVAILABLE",@@ -33,22 +30,49 @@ _AVAILABILITY_FLAG = {"weaviate": "semantica.vector_store.weaviate_store.WEAVIATE_AVAILABLE",}+_CLIENT_SYMBOLS = {+ "qdrant": ("semantica.vector_store.qdrant_store.QdrantClientLib",),+ "pinecone": ("semantica.vector_store.pinecone_store.PineconeClientLib",),+ "milvus": (+ "semantica.vector_store.milvus_store.connections",+ "semantica.vector_store.milvus_store.Collection",+ "semantica.vector_store.milvus_store.utility",+ ),+ "weaviate": ("semantica.vector_store.weaviate_store.weaviate",),+}++# Pinecone refuses to connect without a key, so supply a dummy one rather than+# letting a missing credential masquerade as the wiring gap.+_EXTRA_CONFIG = {"pinecone": {"api_key": "test-key"}}+CLOUD_BACKENDS = sorted(_AVAILABILITY_FLAG)+# Backends that store locally and need no connection step.+_LOCAL_BACKENDS = {"inmemory", "faiss", "sqlite", "pgvector"}+# The facade dispatches store_vectors() to `add` or `add_vectors`. Milvus-# happens to expose add_vectors, so it already resolves; the other three name-# their write method differently and fall through to NotImplementedError.+# exposes add_vectors so it already resolves; the other three name their write+# method differently and fall through to NotImplementedError._NO_WRITE_DISPATCH = {"qdrant", "pinecone", "weaviate"}def _construct(backend):"""Build a VectorStore through the real _init_backend_store path."""- with patch(_AVAILABILITY_FLAG[backend], True):- return VectorStore(backend=backend, config={"dimension": 3})+ config = {"dimension": 3, **_EXTRA_CONFIG.get(backend, {})}+ with ExitStack() as stack:+ stack.enter_context(patch(_AVAILABILITY_FLAG[backend], True))+ for symbol in _CLIENT_SYMBOLS[backend]:+ stack.enter_context(patch(symbol, MagicMock()))+ return VectorStore(backend=backend, config=config)def _live_handle(backend_store):- """The attribute each adapter uses to hold its connected resource."""+ """The attribute each adapter holds its connected resource in.++ Reaching into the adapter rather than asserting through the facade is+ deliberate: the facade's read methods are exactly what is broken, so there+ is no public call that distinguishes "not connected" from the other gaps.+ """for name in ("collection", "index"):if hasattr(backend_store, name):return getattr(backend_store, name)@@ -60,9 +84,13 @@ def _param(backend, broken_for, reason):return pytest.param(backend, marks=marks)+def test_roster_covers_every_supported_backend():+ """A new backend must be classified here rather than silently uncovered."""+ assert set(CLOUD_BACKENDS) | _LOCAL_BACKENDS == VectorStore.SUPPORTED_BACKENDS++@pytest.mark.parametrize("backend", CLOUD_BACKENDS)def test_facade_constructs_an_adapter(backend):- """The adapter object itself is built. This part already works."""store = _construct(backend)assert store._backend_store is not None@@ -78,11 +106,7 @@ def test_facade_constructs_an_adapter(backend):)def test_backend_is_connected_after_construction(backend):"""A constructed store should be usable without the caller reaching past- the facade to call connect() and get_collection() itself.-- Today _init_backend_store constructs the adapter and stops, so every read- path raises "Collection not initialized" / "Index not initialized".- """+ the facade to call connect() and get_collection() itself."""store = _construct(backend)assert _live_handle(store._backend_store) is not None@@ -96,12 +120,7 @@ def test_backend_is_connected_after_construction(backend):],)def test_store_vectors_dispatch_resolves(backend):- """store_vectors() should reach the backend's write method.-- This isolates dispatch from connectivity on purpose: any error other than- NotImplementedError means the facade found a method and the failure came- from further down, which is the connection gap covered above.- """+ """store_vectors() should reach the backend's write method."""store = _construct(backend)try:@@ -109,16 +128,15 @@ def test_store_vectors_dispatch_resolves(backend):except NotImplementedError as exc:pytest.fail(f"no write dispatch for {backend}: {exc}")except Exception:+ # Any other error means the facade found a write method and the failure+ # came from below it, which is the connection gap the test above pins.+ # Whether the write succeeds needs a live server, not this test.passdef test_milvus_write_dispatch_already_resolves():- """Guards the assumption behind _NO_WRITE_DISPATCH.-- Milvus is the control case: it exposes add_vectors, which the existing- dispatch chain already matches. If this ever stops holding, the xfail list- above is wrong rather than the feature being broken.- """+ """Control for _NO_WRITE_DISPATCH: if milvus changes, the xfail list is+ wrong rather than the feature being broken."""store = _construct("milvus")assert hasattr(store._backend_store, "add_vectors")