Frontend (items 1-10):
- WebSocket streaming integration with useWebSocket hook
- Admin Dashboard UI (status, voices, agents, governance tabs)
- Voice playback UI (TTS/STT integration)
- Settings/Preferences page (conversation style, sliders)
- Responsive/mobile layout (breakpoints at 480px, 768px)
- Dark/light theme with CSS variables and localStorage
- Error handling & loading states (retry, empty state, disabled input)
- Authentication UI (login page, Bearer token, logout)
- Head visualization improvements (active/speaking states, animations)
- Consequence/Ethics dashboard (lessons, consequences, insights tabs)
Backend stubs (items 11-21):
- Tool connectors: DocsConnector (text/md/PDF), DBConnector (SQLite/Postgres), CodeRunnerConnector (Python/JS/Bash/Ruby sandboxed)
- STT adapter: WhisperSTTAdapter, AzureSTTAdapter
- Multi-modal interface adapters: Visual, Haptic, Gesture, Biometric
- SSE streaming endpoint (/v1/sessions/{id}/stream/sse)
- Multi-tenant support (X-Tenant-ID header, tenant CRUD)
- Plugin marketplace/registry (register, install, list)
- Backup/restore endpoints
- Versioned API negotiation (Accept-Version header, deprecation)
Infrastructure (items 22-26):
- docker-compose.yml (API + Postgres + Redis + frontend)
- .env.example with all configurable vars
- gunicorn.conf.py production ASGI config
- Prometheus metrics collector and /metrics endpoint
- Structured JSON logging configuration
Documentation (items 27-29):
- Architecture docs with module layout and subsystem descriptions
- Quickstart guide with setup, API tour, and test instructions
Tests (items 30-32):
- Integration tests: 25 end-to-end API tests
- Frontend tests: 10 Vitest tests for hooks (useTheme, useAuth)
- Load/performance tests: latency and throughput benchmarks
- Connector tests: 16 tests for Docs, DB, CodeRunner
- Multi-modal adapter tests: 9 tests
- Metrics collector tests: 5 tests
- STT adapter tests: 2 tests
511 Python tests passing, 10 frontend tests passing, 0 ruff errors.
Co-Authored-By: Nakamoto, S <defi@defi-oracle.io>
200 lines
6.1 KiB
Python
200 lines
6.1 KiB
Python
"""End-to-end integration tests for the FusionAGI API."""
|
|
|
|
from __future__ import annotations
|
|
|
|
starlette = __import__("pytest").importorskip("starlette")
|
|
fastapi = __import__("pytest").importorskip("fastapi")
|
|
|
|
from starlette.testclient import TestClient # noqa: E402
|
|
|
|
from fusionagi.api.app import create_app # noqa: E402
|
|
|
|
|
|
def _client() -> TestClient:
|
|
app = create_app(cors_origins=["*"])
|
|
return TestClient(app)
|
|
|
|
|
|
class TestSessionLifecycle:
|
|
"""Test the full session lifecycle: create → prompt → response."""
|
|
|
|
def test_create_session(self) -> None:
|
|
c = _client()
|
|
resp = c.post("/v1/sessions", json={"user_id": "test-user"})
|
|
assert resp.status_code == 200
|
|
data = resp.json()
|
|
assert "session_id" in data
|
|
|
|
def test_prompt_requires_session(self) -> None:
|
|
c = _client()
|
|
resp = c.post("/v1/sessions", json={"user_id": "test-user"})
|
|
sid = resp.json()["session_id"]
|
|
resp = c.post(f"/v1/sessions/{sid}/prompt", json={"prompt": "Hello"})
|
|
assert resp.status_code == 200
|
|
|
|
def test_unknown_session_returns_error(self) -> None:
|
|
c = _client()
|
|
resp = c.post("/v1/sessions/nonexistent/prompt", json={"prompt": "Hello"})
|
|
assert resp.status_code in (404, 422, 500)
|
|
|
|
|
|
class TestAdminEndpoints:
|
|
"""Test admin API endpoints."""
|
|
|
|
def test_system_status(self) -> None:
|
|
c = _client()
|
|
resp = c.get("/v1/admin/status")
|
|
assert resp.status_code == 200
|
|
data = resp.json()
|
|
assert data["status"] == "healthy"
|
|
assert "uptime_seconds" in data
|
|
|
|
def test_list_voices(self) -> None:
|
|
c = _client()
|
|
resp = c.get("/v1/admin/voices")
|
|
assert resp.status_code == 200
|
|
assert isinstance(resp.json(), list)
|
|
|
|
def test_add_voice(self) -> None:
|
|
c = _client()
|
|
resp = c.post("/v1/admin/voices", json={"name": "Test Voice", "language": "en-US"})
|
|
assert resp.status_code == 200
|
|
assert resp.json()["name"] == "Test Voice"
|
|
|
|
def test_ethics_endpoint(self) -> None:
|
|
c = _client()
|
|
resp = c.get("/v1/admin/ethics")
|
|
assert resp.status_code == 200
|
|
assert isinstance(resp.json(), list)
|
|
|
|
def test_consequences_endpoint(self) -> None:
|
|
c = _client()
|
|
resp = c.get("/v1/admin/consequences")
|
|
assert resp.status_code == 200
|
|
|
|
def test_insights_endpoint(self) -> None:
|
|
c = _client()
|
|
resp = c.get("/v1/admin/insights")
|
|
assert resp.status_code == 200
|
|
|
|
def test_conversation_style(self) -> None:
|
|
c = _client()
|
|
resp = c.post("/v1/admin/conversation-style", json={"formality": "formal", "verbosity": "concise"})
|
|
assert resp.status_code == 200
|
|
|
|
def test_telemetry(self) -> None:
|
|
c = _client()
|
|
resp = c.get("/v1/admin/telemetry")
|
|
assert resp.status_code == 200
|
|
assert "traces" in resp.json()
|
|
|
|
|
|
class TestTenantEndpoints:
|
|
"""Test multi-tenant API."""
|
|
|
|
def test_current_tenant_default(self) -> None:
|
|
c = _client()
|
|
resp = c.get("/v1/admin/tenants/current")
|
|
assert resp.status_code == 200
|
|
data = resp.json()
|
|
assert data["tenant_id"] == "default"
|
|
assert data["is_default"] is True
|
|
|
|
def test_current_tenant_custom(self) -> None:
|
|
c = _client()
|
|
resp = c.get("/v1/admin/tenants/current", headers={"X-Tenant-ID": "acme"})
|
|
assert resp.status_code == 200
|
|
assert resp.json()["tenant_id"] == "acme"
|
|
|
|
def test_list_tenants(self) -> None:
|
|
c = _client()
|
|
resp = c.get("/v1/admin/tenants")
|
|
assert resp.status_code == 200
|
|
assert "tenants" in resp.json()
|
|
|
|
def test_create_tenant(self) -> None:
|
|
c = _client()
|
|
resp = c.post("/v1/admin/tenants", json={"id": "test-org", "name": "Test Org"})
|
|
assert resp.status_code == 200
|
|
assert resp.json()["id"] == "test-org"
|
|
|
|
|
|
class TestPluginEndpoints:
|
|
"""Test plugin marketplace API."""
|
|
|
|
def test_list_plugins(self) -> None:
|
|
c = _client()
|
|
resp = c.get("/v1/admin/plugins")
|
|
assert resp.status_code == 200
|
|
data = resp.json()
|
|
assert "available" in data
|
|
assert "installed" in data
|
|
|
|
def test_register_and_install_plugin(self) -> None:
|
|
c = _client()
|
|
resp = c.post("/v1/admin/plugins", json={
|
|
"id": "test-plugin",
|
|
"name": "Test Plugin",
|
|
"description": "A test plugin",
|
|
"version": "1.0.0",
|
|
})
|
|
assert resp.status_code == 200
|
|
assert resp.json()["id"] == "test-plugin"
|
|
|
|
resp = c.post("/v1/admin/plugins/test-plugin/install")
|
|
assert resp.status_code == 200
|
|
assert resp.json()["status"] == "installed"
|
|
|
|
|
|
class TestBackupEndpoints:
|
|
"""Test backup/restore API."""
|
|
|
|
def test_list_backups(self) -> None:
|
|
c = _client()
|
|
resp = c.get("/v1/admin/backups")
|
|
assert resp.status_code == 200
|
|
assert "backups" in resp.json()
|
|
|
|
|
|
class TestVersionNegotiation:
|
|
"""Test API version negotiation."""
|
|
|
|
def test_version_endpoint(self) -> None:
|
|
c = _client()
|
|
resp = c.get("/version")
|
|
assert resp.status_code == 200
|
|
data = resp.json()
|
|
assert "current_version" in data
|
|
assert "supported_versions" in data
|
|
|
|
def test_version_header(self) -> None:
|
|
c = _client()
|
|
resp = c.get("/v1/admin/status")
|
|
assert "x-api-version" in resp.headers
|
|
|
|
def test_unsupported_version(self) -> None:
|
|
c = _client()
|
|
resp = c.get("/v1/admin/status", headers={"Accept-Version": "99"})
|
|
assert resp.status_code == 400
|
|
|
|
|
|
class TestSSEStreaming:
|
|
"""Test SSE streaming endpoint."""
|
|
|
|
def test_sse_endpoint_exists(self) -> None:
|
|
c = _client()
|
|
resp = c.post("/v1/sessions/test-session/stream/sse", json={"prompt": "Hi"})
|
|
assert resp.status_code == 200
|
|
assert resp.headers["content-type"].startswith("text/event-stream")
|
|
|
|
|
|
class TestOpenAICompat:
|
|
"""Test OpenAI-compatible endpoints."""
|
|
|
|
def test_models_list(self) -> None:
|
|
c = _client()
|
|
resp = c.get("/v1/models")
|
|
assert resp.status_code == 200
|
|
data = resp.json()
|
|
assert "data" in data
|