Files
OpenJarvis/tests/tools/test_storage_stubs.py
T
Jon Saad-FalconandClaude Opus 4.6 852259f18b Restructure codebase into 5-pillar architecture with MCP tool management, composition layer, and structured learning
Phase 1: Move RoutingContext to core/types.py, add RouterPolicy and QueryAnalyzer ABCs to intelligence/_stubs.py
Phase 2: Move memory backends to tools/storage/, convert memory/ to backward-compat shims
Phase 3: Add MCPToolAdapter, storage MCP tools, upgrade MCP server to spec 2025-11-25
Phase 4: Add SystemBuilder + JarvisSystem composition layer (system.py)
Phase 5: Add InstrumentedEngine for opt-in telemetry, simplify all agents
Phase 6: Add LearningPolicy ABC taxonomy with SFTPolicy, AgentAdvisorPolicy, ICLUpdaterPolicy
Phase 7: Update config schema (ToolsConfig, MCPConfig, TracesConfig, per-pillar learning policies)

Also: update all docs, README (DSPy-inspired), CLAUDE.md, and add logo assets.
1391 tests pass, 32 skipped. Zero new lint errors. Full backward compatibility via shims.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-22 05:57:13 +00:00

83 lines
2.7 KiB
Python

"""Tests for tools/storage — canonical location for memory backends."""
from __future__ import annotations
import pytest
from openjarvis.tools.storage._stubs import MemoryBackend, RetrievalResult
class _DummyStorage(MemoryBackend):
backend_id = "dummy"
def __init__(self):
self._data = {}
self._counter = 0
def store(self, content, *, source="", metadata=None):
self._counter += 1
doc_id = f"doc-{self._counter}"
self._data[doc_id] = {"content": content, "source": source}
return doc_id
def retrieve(self, query, *, top_k=5, **kwargs):
results = []
for doc_id, doc in self._data.items():
if query.lower() in doc["content"].lower():
results.append(RetrievalResult(
content=doc["content"],
score=1.0,
source=doc["source"],
))
return results[:top_k]
def delete(self, doc_id):
if doc_id in self._data:
del self._data[doc_id]
return True
return False
def clear(self):
self._data.clear()
class TestStorageStubs:
def test_abc_cannot_instantiate(self) -> None:
with pytest.raises(TypeError):
MemoryBackend() # type: ignore[abstract]
def test_concrete_implementation(self) -> None:
storage = _DummyStorage()
doc_id = storage.store("hello world", source="test")
assert doc_id == "doc-1"
def test_retrieve(self) -> None:
storage = _DummyStorage()
storage.store("hello world", source="test")
results = storage.retrieve("hello")
assert len(results) == 1
assert results[0].content == "hello world"
def test_retrieval_result(self) -> None:
r = RetrievalResult(content="test", score=0.95, source="src")
assert r.content == "test"
assert r.score == 0.95
def test_backward_compat_import(self) -> None:
"""Memory imports should still work via shim."""
from openjarvis.memory._stubs import MemoryBackend as MB
from openjarvis.memory._stubs import RetrievalResult as RR
assert MB is MemoryBackend
assert RR is RetrievalResult
def test_canonical_import(self) -> None:
"""Canonical import from tools.storage should work."""
from openjarvis.tools.storage._stubs import MemoryBackend as MB
assert MB is MemoryBackend
def test_sqlite_backward_compat(self) -> None:
"""SQLiteMemory should be importable from both locations."""
from openjarvis.memory.sqlite import SQLiteMemory as S2
from openjarvis.tools.storage.sqlite import SQLiteMemory as S1
assert S1 is S2