forked from Rockachopa/Timmy-time-dashboard
Mission Control Dashboard: - /swarm/mission-control page with real-time system status - Sovereignty score display with visual progress bar - Dependency health grid (Ollama, Redis, Lightning, SQLite) - Recommendations based on dependency status - Heartbeat monitor with tick counter - System metrics: uptime, agents, tasks, sats earned Health Endpoints: - /health/sovereignty - Full sovereignty audit report - /health/components - Component status and config Tests (TDD approach): - 11 Mission Control tests (all passing) - 23 scary path tests for production scenarios - Concurrent load, memory persistence, edge cases Total: 525 tests passing
135 lines
4.9 KiB
Python
135 lines
4.9 KiB
Python
"""Tests for Mission Control dashboard.
|
|
|
|
TDD approach: Tests written first, then implementation.
|
|
"""
|
|
|
|
import pytest
|
|
from unittest.mock import patch, MagicMock
|
|
|
|
|
|
class TestSovereigntyEndpoint:
|
|
"""Tests for /health/sovereignty endpoint."""
|
|
|
|
def test_sovereignty_returns_overall_score(self, client):
|
|
"""Should return overall sovereignty score."""
|
|
response = client.get("/health/sovereignty")
|
|
assert response.status_code == 200
|
|
|
|
data = response.json()
|
|
assert "overall_score" in data
|
|
assert isinstance(data["overall_score"], (int, float))
|
|
assert 0 <= data["overall_score"] <= 10
|
|
|
|
def test_sovereignty_returns_dependencies(self, client):
|
|
"""Should return list of dependencies with status."""
|
|
response = client.get("/health/sovereignty")
|
|
assert response.status_code == 200
|
|
|
|
data = response.json()
|
|
assert "dependencies" in data
|
|
assert isinstance(data["dependencies"], list)
|
|
|
|
# Check required fields for each dependency
|
|
for dep in data["dependencies"]:
|
|
assert "name" in dep
|
|
assert "status" in dep # "healthy", "degraded", "unavailable"
|
|
assert "sovereignty_score" in dep
|
|
assert "details" in dep
|
|
|
|
def test_sovereignty_returns_recommendations(self, client):
|
|
"""Should return recommendations list."""
|
|
response = client.get("/health/sovereignty")
|
|
assert response.status_code == 200
|
|
|
|
data = response.json()
|
|
assert "recommendations" in data
|
|
assert isinstance(data["recommendations"], list)
|
|
|
|
def test_sovereignty_includes_timestamps(self, client):
|
|
"""Should include timestamp."""
|
|
response = client.get("/health/sovereignty")
|
|
assert response.status_code == 200
|
|
|
|
data = response.json()
|
|
assert "timestamp" in data
|
|
|
|
|
|
class TestMissionControlPage:
|
|
"""Tests for Mission Control dashboard page."""
|
|
|
|
def test_mission_control_page_loads(self, client):
|
|
"""Should render Mission Control page."""
|
|
response = client.get("/swarm/mission-control")
|
|
assert response.status_code == 200
|
|
assert "Mission Control" in response.text
|
|
|
|
def test_mission_control_includes_sovereignty_score(self, client):
|
|
"""Page should display sovereignty score element."""
|
|
response = client.get("/swarm/mission-control")
|
|
assert response.status_code == 200
|
|
assert "sov-score" in response.text # Element ID for JavaScript
|
|
|
|
def test_mission_control_includes_dependency_grid(self, client):
|
|
"""Page should display dependency grid."""
|
|
response = client.get("/swarm/mission-control")
|
|
assert response.status_code == 200
|
|
assert "dependency-grid" in response.text
|
|
|
|
|
|
class TestHealthComponentsEndpoint:
|
|
"""Tests for /health/components endpoint."""
|
|
|
|
def test_components_returns_lightning_info(self, client):
|
|
"""Should return Lightning backend info."""
|
|
response = client.get("/health/components")
|
|
assert response.status_code == 200
|
|
|
|
data = response.json()
|
|
assert "lightning" in data
|
|
assert "configured_backend" in data["lightning"]
|
|
|
|
def test_components_returns_config(self, client):
|
|
"""Should return system config."""
|
|
response = client.get("/health/components")
|
|
assert response.status_code == 200
|
|
|
|
data = response.json()
|
|
assert "config" in data
|
|
assert "debug" in data["config"]
|
|
assert "model_backend" in data["config"]
|
|
|
|
|
|
class TestScaryPathScenarios:
|
|
"""Scary path tests for production scenarios."""
|
|
|
|
def test_concurrent_sovereignty_requests(self, client):
|
|
"""Should handle concurrent requests to /health/sovereignty."""
|
|
import concurrent.futures
|
|
|
|
def fetch():
|
|
return client.get("/health/sovereignty")
|
|
|
|
with concurrent.futures.ThreadPoolExecutor(max_workers=5) as executor:
|
|
futures = [executor.submit(fetch) for _ in range(10)]
|
|
responses = [f.result() for f in concurrent.futures.as_completed(futures)]
|
|
|
|
# All should succeed
|
|
assert all(r.status_code == 200 for r in responses)
|
|
|
|
# All should have valid JSON
|
|
for r in responses:
|
|
data = r.json()
|
|
assert "overall_score" in data
|
|
|
|
def test_sovereignty_with_missing_dependencies(self, client):
|
|
"""Should handle missing dependencies gracefully."""
|
|
# Mock a failure scenario - patch at the module level where used
|
|
with patch("dashboard.routes.health.check_ollama", return_value=False):
|
|
response = client.get("/health/sovereignty")
|
|
assert response.status_code == 200
|
|
|
|
data = response.json()
|
|
# Should still return valid response even with failures
|
|
assert "overall_score" in data
|
|
assert "dependencies" in data
|