Next-level improvements: 15 items across backend, frontend, and testing
Backend: - SQLiteStateBackend: persistent task/trace storage with SQLite - InMemoryStateBackend: in-memory impl of StateBackend interface - Redis cache backend (CacheBackend ABC + MemoryCacheBackend + RedisCacheBackend) - OpenAI adapter: async acomplete() with retry logic - Per-tenant + per-IP rate limiting in middleware Frontend: - State management: useStore + useAppState (zero-dep, context + reducer) - React Router integration: URL-based navigation (usePageNavigation) - WebSocket streaming: sendPrompt + StreamCallbacks for token-by-token updates - File preview: inline image/text/binary preview with expand/collapse - Sparkline charts + MetricCard + BarChart for dashboard visualization - Push notifications hook (useNotifications) with browser Notification API - i18n system: 6 locales (en, es, fr, de, ja, zh) with interpolation - 6 new Storybook stories (ChatMessage, Skeleton, Markdown, SearchFilter, Toast, FilePreview) Testing: - Playwright E2E config + 6 browser specs (desktop + mobile) - 18 new Python tests (SQLiteStateBackend, InMemoryStateBackend, cache backends) 570 Python tests + 45 frontend tests = 615 total, 0 ruff errors. Co-Authored-By: Nakamoto, S <defi@defi-oracle.io>
This commit is contained in:
48
tests/test_cache_backends.py
Normal file
48
tests/test_cache_backends.py
Normal file
@@ -0,0 +1,48 @@
|
||||
"""Tests for ResponseCache with pluggable backends."""
|
||||
|
||||
from fusionagi.api.cache import MemoryCacheBackend, ResponseCache
|
||||
|
||||
|
||||
def test_memory_backend_basic():
|
||||
backend = MemoryCacheBackend(max_size=10, default_ttl=60.0)
|
||||
backend.set("k1", {"data": "value"})
|
||||
assert backend.get("k1") == {"data": "value"}
|
||||
|
||||
|
||||
def test_memory_backend_delete():
|
||||
backend = MemoryCacheBackend()
|
||||
backend.set("k2", "val")
|
||||
assert backend.delete("k2") is True
|
||||
assert backend.get("k2") is None
|
||||
|
||||
|
||||
def test_memory_backend_clear():
|
||||
backend = MemoryCacheBackend()
|
||||
backend.set("a", 1)
|
||||
backend.set("b", 2)
|
||||
assert backend.clear() == 2
|
||||
assert backend.get("a") is None
|
||||
|
||||
|
||||
def test_memory_backend_stats():
|
||||
backend = MemoryCacheBackend(max_size=100)
|
||||
backend.set("s1", "v1")
|
||||
stats = backend.stats()
|
||||
assert stats["backend"] == "memory"
|
||||
assert stats["total"] == 1
|
||||
|
||||
|
||||
def test_response_cache_with_backend():
|
||||
backend = MemoryCacheBackend(max_size=50, default_ttl=120.0)
|
||||
cache = ResponseCache(backend=backend)
|
||||
cache.set("hello", "session-1", {"answer": "world"})
|
||||
assert cache.get("hello", "session-1") == {"answer": "world"}
|
||||
assert cache.get("hello", "session-2") is None # different session
|
||||
|
||||
|
||||
def test_response_cache_tenant_isolation():
|
||||
cache = ResponseCache()
|
||||
cache.set("prompt", "s1", "result-a", tenant_id="tenant-1")
|
||||
cache.set("prompt", "s1", "result-b", tenant_id="tenant-2")
|
||||
assert cache.get("prompt", "s1", "tenant-1") == "result-a"
|
||||
assert cache.get("prompt", "s1", "tenant-2") == "result-b"
|
||||
Reference in New Issue
Block a user