Files
microfish/backend/tests/test_profile_memory_mode.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

61 lines
2.0 KiB
Python

from types import SimpleNamespace
from app.config import Config
from app.services.memory_entity_reader import LocalEntityNode
from app.services.oasis_profile_generator import OasisProfileGenerator
def test_profile_generator_can_disable_zep_context_for_local_memory(monkeypatch):
monkeypatch.setattr(Config, "LLM_API_KEY", "test-key")
monkeypatch.setattr(Config, "ZEP_API_KEY", "zep-key-that-must-not-be-used")
generator = OasisProfileGenerator(
graph_id="graph-local",
use_zep_context=False,
)
assert generator.zep_api_key is None
assert generator.zep_client is None
def test_profile_generator_never_constructs_zep_in_local_backend(monkeypatch):
monkeypatch.setattr(Config, "MEMORY_BACKEND", "local")
monkeypatch.setattr(Config, "LLM_API_KEY", "test-key")
monkeypatch.setattr(Config, "ZEP_API_KEY", "zep-key-that-must-not-be-used")
generator = OasisProfileGenerator(graph_id="graph-local")
assert generator.zep_api_key is None
assert generator.zep_client is None
def test_profile_generator_uses_local_memory_context_without_zep(monkeypatch):
monkeypatch.setattr(Config, "LLM_API_KEY", "test-key")
class FakeLocalMemoryTools:
def search_graph(self, query, *, limit=10, scope="both"):
assert query == "Alice"
assert limit == 30
assert scope == "both"
return SimpleNamespace(
facts=["Alice founded Orbit"],
nodes=[{"name": "Orbit", "summary": "A local project"}],
)
generator = OasisProfileGenerator(
graph_id="graph-local",
use_zep_context=False,
local_memory_tools=FakeLocalMemoryTools(),
)
entity = LocalEntityNode(
uuid="node-alice",
name="Alice",
labels=["Entity", "person"],
summary="A founder",
attributes={},
)
context = generator._build_entity_context(entity)
assert "Alice founded Orbit" in context
assert "Orbit" in context
assert generator.zep_client is None