forked from Rockachopa/Timmy-time-dashboard
test: add 157 functional tests covering 8 low-coverage modules
Analyze test coverage (75.3% → 85.4%) and add functional test suites for the major gaps identified: - test_agent_core.py: Full coverage for agent_core/interface.py (0→100%) and agent_core/ollama_adapter.py (0→100%) — data classes, factories, abstract enforcement, perceive/reason/act/recall workflow, effect logging - test_docker_runner.py: Full coverage for swarm/docker_runner.py (0→100%) — container spawn/stop/list lifecycle with mocked subprocess - test_timmy_tools.py: Tool usage tracking, persona toolkit mapping, catalog generation, graceful degradation without Agno - test_routes_tools.py: /tools page, API stats endpoint, and WebSocket /swarm/live connect/disconnect/send lifecycle (41→82%) - test_voice_tts_functional.py: VoiceTTS init, speak, volume clamping, voice listing, graceful degradation (41→94%) - test_watchdog_functional.py: _run_tests, watch loop state transitions, regression detection, KeyboardInterrupt (47→97%) - test_lnd_backend.py: LND init from params/env, grpc stub enforcement, method-level BackendNotAvailableError, settle returns False (25→61%) - test_swarm_routes_functional.py: Agent spawn/stop, task CRUD, auction, insights, UI partials, error paths (63→92%) https://claude.ai/code/session_01WU4h3cQQiouMwmgYmAgkMM
This commit is contained in:
70
tests/test_routes_tools.py
Normal file
70
tests/test_routes_tools.py
Normal file
@@ -0,0 +1,70 @@
|
||||
"""Functional tests for dashboard routes: /tools and /swarm/live WebSocket.
|
||||
|
||||
Tests the tools dashboard page, API stats endpoint, and the swarm
|
||||
WebSocket live endpoint.
|
||||
"""
|
||||
|
||||
from unittest.mock import patch, MagicMock, AsyncMock
|
||||
|
||||
import pytest
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
|
||||
# ── /tools route ──────────────────────────────────────────────────────────────
|
||||
|
||||
|
||||
class TestToolsPage:
|
||||
def test_tools_page_returns_200(self, client):
|
||||
response = client.get("/tools")
|
||||
assert response.status_code == 200
|
||||
|
||||
def test_tools_page_html_content(self, client):
|
||||
response = client.get("/tools")
|
||||
assert "text/html" in response.headers["content-type"]
|
||||
|
||||
def test_tools_api_stats_returns_json(self, client):
|
||||
response = client.get("/tools/api/stats")
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert "all_stats" in data
|
||||
assert "available_tools" in data
|
||||
assert isinstance(data["available_tools"], list)
|
||||
assert len(data["available_tools"]) > 0
|
||||
|
||||
def test_tools_api_stats_includes_base_tools(self, client):
|
||||
response = client.get("/tools/api/stats")
|
||||
data = response.json()
|
||||
base_tools = {"web_search", "shell", "python", "read_file", "write_file", "list_files"}
|
||||
for tool in base_tools:
|
||||
assert tool in data["available_tools"], f"Missing: {tool}"
|
||||
|
||||
def test_tools_page_with_agents(self, client):
|
||||
"""Spawn an agent and verify tools page includes it."""
|
||||
client.post("/swarm/spawn", data={"name": "Echo"})
|
||||
response = client.get("/tools")
|
||||
assert response.status_code == 200
|
||||
|
||||
|
||||
# ── /swarm/live WebSocket ─────────────────────────────────────────────────────
|
||||
|
||||
|
||||
class TestSwarmWebSocket:
|
||||
def test_websocket_connect_disconnect(self, client):
|
||||
with client.websocket_connect("/swarm/live") as ws:
|
||||
# Connection succeeds
|
||||
pass
|
||||
# Disconnect on context manager exit
|
||||
|
||||
def test_websocket_send_receive(self, client):
|
||||
"""The WebSocket endpoint should accept messages (it logs them)."""
|
||||
with client.websocket_connect("/swarm/live") as ws:
|
||||
ws.send_text("ping")
|
||||
# The endpoint only echoes via logging, not back to client.
|
||||
# The key test is that it doesn't crash on receiving a message.
|
||||
|
||||
def test_websocket_multiple_connections(self, client):
|
||||
"""Multiple clients can connect simultaneously."""
|
||||
with client.websocket_connect("/swarm/live") as ws1:
|
||||
with client.websocket_connect("/swarm/live") as ws2:
|
||||
ws1.send_text("hello from 1")
|
||||
ws2.send_text("hello from 2")
|
||||
Reference in New Issue
Block a user