feat(I): I-DASH/I-COST/I-USE — platform dashboard, cost tracking, usage analytics (agent/workflow/search/knowledge metrics, cost per agent, budget alerts, success rates), 38 tests passing
This commit is contained in:
@@ -380,3 +380,65 @@ class TestProactiveFeed:
|
||||
trigger="mail.received", payload={"entity_id": eid},
|
||||
)
|
||||
assert len(suggestions) == 0
|
||||
|
||||
|
||||
# ─── I-DASH/I-COST/I-USE: Dashboard & Analytics ──────────────────────────────
|
||||
|
||||
|
||||
class TestDashboardAnalytics:
|
||||
"""Test the dashboard & analytics module (I-DASH, I-COST, I-USE)."""
|
||||
|
||||
def test_dashboard_functions_importable(self):
|
||||
"""All dashboard functions are importable."""
|
||||
from app.ai.dashboard import get_platform_dashboard, get_cost_dashboard, get_usage_analytics
|
||||
assert callable(get_platform_dashboard)
|
||||
assert callable(get_cost_dashboard)
|
||||
assert callable(get_usage_analytics)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_platform_dashboard_returns_dict(self):
|
||||
"""get_platform_dashboard returns a dict with expected keys."""
|
||||
from app.ai.dashboard import get_platform_dashboard
|
||||
|
||||
# Mock all DB queries to return 0
|
||||
mock_db = AsyncMock()
|
||||
mock_db.scalar = AsyncMock(return_value=0)
|
||||
mock_db.execute = AsyncMock(return_value=MagicMock(scalars=MagicMock(return_value=[])))
|
||||
|
||||
result = await get_platform_dashboard(mock_db, uuid.uuid4())
|
||||
assert isinstance(result, dict)
|
||||
assert "agents" in result
|
||||
assert "workflows" in result
|
||||
assert "knowledge" in result
|
||||
assert "system_health" in result
|
||||
assert "generated_at" in result
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_cost_dashboard_returns_dict(self):
|
||||
"""get_cost_dashboard returns a dict with cost data."""
|
||||
from app.ai.dashboard import get_cost_dashboard
|
||||
|
||||
mock_db = AsyncMock()
|
||||
mock_db.scalar = AsyncMock(return_value=0.0)
|
||||
mock_db.execute = AsyncMock(return_value=MagicMock(scalars=MagicMock(return_value=[])))
|
||||
|
||||
result = await get_cost_dashboard(mock_db, uuid.uuid4(), days=30)
|
||||
assert isinstance(result, dict)
|
||||
assert "total_cost_usd" in result
|
||||
assert "by_agent" in result
|
||||
assert "period_days" in result
|
||||
assert result["period_days"] == 30
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_usage_analytics_returns_dict(self):
|
||||
"""get_usage_analytics returns a dict with usage data."""
|
||||
from app.ai.dashboard import get_usage_analytics
|
||||
|
||||
mock_db = AsyncMock()
|
||||
mock_db.scalar = AsyncMock(return_value=0)
|
||||
|
||||
result = await get_usage_analytics(mock_db, uuid.uuid4(), days=7)
|
||||
assert isinstance(result, dict)
|
||||
assert "agent_runs" in result
|
||||
assert "workflow_executions" in result
|
||||
assert result["period_days"] == 7
|
||||
|
||||
Reference in New Issue
Block a user