Files
mempalace/tests/test_backend_conformance.py
T
Igor Lins e Silva 94a41ee217 fix(hermes): stop second Chroma client racing the filing worker
MemoryStack/Layer1 opened a second PersistentClient on the same palace
while the Hermes provider already held one for live filing. Concurrent
access corrupted local Chroma SQLite (disk I/O / Failed to get segments)
and failed CI on develop after #1915.

Wake-up L1 now scans the long-lived collection under the collection lock,
and filing holds that lock for the full upsert. Also rewrite the RFC 001
section-4.4 docstring to avoid the internal §N jargon guard.
2026-08-11 08:13:19 -03:00

61 lines
2.3 KiB
Python

"""Backend isolation conformance suite (RFC 001 isolation contract).
Runs the shared isolation assertions from ``_backend_conformance`` against the
built-in local backends. Server-mode backends (qdrant) run the same assertions
under their own fake/live client in ``test_qdrant_backend.py``.
"""
import pytest
from _backend_conformance import assert_partition_isolation
from mempalace.backends import PalaceRef
from mempalace.backends.chroma import ChromaBackend
from mempalace.backends.sqlite_exact import SQLiteExactBackend
_LOCAL_BACKENDS = [
pytest.param(ChromaBackend, id="chroma"),
pytest.param(SQLiteExactBackend, id="sqlite_exact"),
]
@pytest.mark.parametrize("backend_cls", _LOCAL_BACKENDS)
def test_cross_palace_isolation(backend_cls, tmp_path):
"""One backend instance must isolate two distinct palaces (PalaceRef.id)."""
backend = backend_cls()
try:
cols = []
for label in ("alpha", "beta"):
path = tmp_path / label
ref = PalaceRef(id=str(path), local_path=str(path))
cols.append(
backend.get_collection(palace=ref, collection_name="mempalace_drawers", create=True)
)
assert_partition_isolation(backend, cols[0], cols[1])
finally:
backend.close()
def test_local_backends_do_not_claim_namespace_isolation():
"""Local backends isolate by on-disk path, not namespace; they must not
advertise the namespace-isolation capability (RFC 001 isolation contract)."""
assert "supports_namespace_isolation" not in ChromaBackend.capabilities
assert "supports_namespace_isolation" not in SQLiteExactBackend.capabilities
@pytest.mark.parametrize("backend_cls", _LOCAL_BACKENDS)
def test_local_backends_reject_populated_namespace(backend_cls, tmp_path):
"""RFC 001 section 4.4 no-silent-drop: non-advertising backends MUST raise when
PalaceRef.namespace is set rather than accept-and-ignore."""
from mempalace.backends.base import UnsupportedCapabilityError
backend = backend_cls()
try:
path = tmp_path / "palace"
path.mkdir()
ref = PalaceRef(id=str(path), local_path=str(path), namespace="tenant-a")
with pytest.raises(UnsupportedCapabilityError):
backend.get_collection(palace=ref, collection_name="mempalace_drawers", create=True)
finally:
backend.close()