Files
python-sdk/pkg/hanzo-memory/test_minimal_sqlite.py
T
zooqueenandHanzo Dev b144973bfc fix(lint): resolve all ruff + black errors across all packages
Fix 35 ruff errors (E722, F841, B904, B905, B007, E741, S202, S310,
S306, S110, TID251, UP042, F401) and run black on 526 files.

Co-authored-by: Hanzo Dev <[email protected]>
2026-02-21 23:32:32 -08:00

84 lines
2.6 KiB
Python

"""Test to verify SQLite backend works with minimal dependencies."""
import asyncio
import tempfile
from pathlib import Path
from hanzo_memory.memory import memory
from hanzo_memory.models.memory import MemoryCreate
async def test_minimal_sqlite_backend():
"""Test that SQLite backend works with minimal dependencies."""
print("Testing minimal SQLite backend functionality...")
# Create a temporary database file for testing
with tempfile.NamedTemporaryFile(suffix=".db", delete=False) as tmp_file:
tmp_path = Path(tmp_file.name)
try:
# Get SQLite backend
print("Getting SQLite backend...")
sqlite_backend = memory["sqlite"]
# Initialize with temporary path
sqlite_backend._client = None # Reset client
sqlite_backend.config = {"db_path": tmp_path}
# Initialize the backend
print("Initializing SQLite backend...")
await sqlite_backend.initialize()
print("✅ SQLite backend initialized successfully!")
# Test creating a simple memory (without relying on embedding service)
print("Testing memory creation...")
from hanzo_memory.db.sqlite_client import SQLiteMemoryClient
client = SQLiteMemoryClient(db_path=tmp_path)
# Create a memory directly using the client
import uuid
from datetime import datetime
import json
memory_id = str(uuid.uuid4())
user_id = "test-user"
project_id = "test-project"
content = "This is a test memory for SQLite backend"
# Add memory without embedding to avoid dependency on embedding service
result = client.add_memory(
memory_id=memory_id,
user_id=user_id,
project_id=project_id,
content=content,
embedding=[], # Empty embedding to avoid embedding service dependency
metadata={"source": "test"},
importance=0.8,
)
print(f"✅ Memory created with ID: {result['memory_id']}")
# Test retrieving the memory
print("Testing memory retrieval...")
projects = client.get_user_projects(user_id)
print(f"✅ Found {len(projects)} projects")
# Close the client
client.close()
print("🎉 Minimal SQLite backend test completed successfully!")
print(
"✅ SQLite backend works with just plaintext files and minimal dependencies"
)
finally:
# Clean up temporary file
if tmp_path.exists():
tmp_path.unlink()
if __name__ == "__main__":
asyncio.run(test_minimal_sqlite_backend())