Files
microfish/backend/tests/test_memory_tools.py
Kunthawat Greethong 8b84378fe1 feat: SaaS foundation for CrowdSight
Elevate MiroFish/CrowdSight from single-container dev to a SaaS foundation:

- Local memory backend (Zep-compatible): memory services/models, local graph
  builder + updater, AgentActivity seam, import-boundary isolation; Zep stays
  default, local is opt-in behind MEMORY_BACKEND. Semantic parity not yet proven.
- Durable product persistence: projects/simulations/reports schema (migration
  0007) + tenant/owner-scoped ProductRepository + dual-write + scoped_project
  read-first + ArtifactStore abstraction; durable JobQueue + worker.py.
- SaaS hardening: durable RateLimiter (wired to login), UsageService (LLM
  accounting), redacted AuditService, idempotency, CORS allowlist, safe API
  errors, single-use PasswordResetService + endpoints (covers invite-pending).
- Exactly 3 roles (super_admin/admin/user) with tenant authz policy.
- Admin UI: GET/POST/PATCH /api/admin/users + GET/PUT /api/admin/settings
  (super-admin only, encrypted/masked); AdminView.vue + SettingsView.vue with
  admin/super-admin route guards, th/en i18n.
- Production deploy topology: multi-stage Dockerfile (frontend build + gunicorn
  wsgi + nginx SPA-proxy + supervisord worker), backend/wsgi.py, gunicorn dep.

Backend 197 passed; frontend 10 tests + build green. ruff unavailable (gap).
No commit of credentials; secrets handled via env/.env.example.
Deferred: Zep semantic A/B parity, object storage cutover, mobile QA, EasyPanel
container build of deploy topology.
2026-08-31 13:05:21 +07:00

40 lines
1.6 KiB
Python

import json
from pathlib import Path
from sqlalchemy import create_engine
from app.db import Base, create_session_factory
from app.models.memory import MemoryEdge, MemoryGraph, MemoryNode
from app.services.memory_tools import LocalMemoryTools
FIXTURE = json.loads(
Path(__file__).with_name("fixtures").joinpath("memory_parity", "entity_reader_fixture.json").read_text()
)
def test_local_memory_tools_quick_search_matches_golden_shape():
engine = create_engine("sqlite+pysqlite:///:memory:")
Base.metadata.create_all(engine)
try:
with create_session_factory(engine)() as session:
session.add(MemoryGraph(id="graph-fixture", organization_id="org-a", project_id="project-a"))
session.add_all([MemoryNode(graph_id="graph-fixture", **node) for node in FIXTURE["nodes"]])
session.add_all([MemoryEdge(graph_id="graph-fixture", **edge) for edge in FIXTURE["edges"]])
session.commit()
tools = LocalMemoryTools(session, organization_id="org-a", graph_id="graph-fixture")
result = tools.quick_search("Alice", limit=10)
assert result.query == "Alice"
assert result.total_count == 1
assert result.facts == ["Alice works for Acme."]
assert result.edges[0]["name"] == "WORKS_FOR"
assert result.nodes == []
both = tools.search_graph("Acme", limit=10, scope="both")
assert both.total_count == 2
assert any(node["name"] == "Acme" for node in both.nodes)
assert any(edge["fact"] == "Alice works for Acme." for edge in both.edges)
finally:
engine.dispose()