1
0
This repository has been archived on 2026-03-24. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
Timmy-time-dashboard/tests/self_coding/test_self_coding_dashboard.py
Claude 4e11dd2490 refactor: Phase 3 — reorganize tests into module-mirroring subdirectories
Move 97 test files from flat tests/ into 13 subdirectories:
  tests/dashboard/   (8 files — routes, mobile, mission control)
  tests/swarm/       (17 files — coordinator, docker, routing, tasks)
  tests/timmy/       (12 files — agent, backends, CLI, tools)
  tests/self_coding/  (14 files — git safety, indexer, self-modify)
  tests/lightning/   (3 files — L402, LND, interface)
  tests/creative/    (8 files — assembler, director, image/music/video)
  tests/integrations/ (10 files — chat bridge, telegram, voice, websocket)
  tests/mcp/         (4 files — bootstrap, discovery, executor)
  tests/spark/       (3 files — engine, tools, events)
  tests/hands/       (3 files — registry, oracle, phase5)
  tests/scripture/   (1 file)
  tests/infrastructure/ (3 files — router cascade, API)
  tests/security/    (3 files — XSS, regression)

Fix Path(__file__) reference in test_mobile_scenarios.py for new depth.
Add __init__.py to all test subdirectories.

Tests: 1503 passed, 9 failed (pre-existing), 53 errors (pre-existing)

https://claude.ai/code/session_019oMFNvD8uSGSSmBMGkBfQN
2026-02-26 21:21:28 +00:00

144 lines
4.8 KiB
Python

"""Tests for Self-Coding Dashboard Routes.
Tests API endpoints and HTMX views.
"""
from __future__ import annotations
import pytest
from fastapi.testclient import TestClient
@pytest.fixture
def client():
"""Create test client."""
from dashboard.app import app
return TestClient(app)
class TestSelfCodingPageRoutes:
"""Page route tests."""
def test_main_page_loads(self, client):
"""Main self-coding page should load."""
response = client.get("/self-coding")
assert response.status_code == 200
assert "Self-Coding" in response.text
def test_journal_partial(self, client):
"""Journal partial should return HTML."""
response = client.get("/self-coding/journal")
assert response.status_code == 200
# Should contain journal list or empty message
assert "journal" in response.text.lower() or "no entries" in response.text.lower()
def test_stats_partial(self, client):
"""Stats partial should return HTML."""
response = client.get("/self-coding/stats")
assert response.status_code == 200
# Should contain stats cards
assert "Total Attempts" in response.text or "success rate" in response.text.lower()
def test_execute_form_partial(self, client):
"""Execute form partial should return HTML."""
response = client.get("/self-coding/execute-form")
assert response.status_code == 200
assert "Task Description" in response.text
assert "textarea" in response.text
class TestSelfCodingAPIRoutes:
"""API route tests."""
def test_api_journal_list(self, client):
"""API should return journal entries."""
response = client.get("/self-coding/api/journal")
assert response.status_code == 200
data = response.json()
assert isinstance(data, list)
def test_api_journal_list_with_limit(self, client):
"""API should respect limit parameter."""
response = client.get("/self-coding/api/journal?limit=5")
assert response.status_code == 200
data = response.json()
assert isinstance(data, list)
assert len(data) <= 5
def test_api_journal_detail_not_found(self, client):
"""API should return 404 for non-existent entry."""
response = client.get("/self-coding/api/journal/99999")
assert response.status_code == 404
def test_api_stats(self, client):
"""API should return stats."""
response = client.get("/self-coding/api/stats")
assert response.status_code == 200
data = response.json()
assert "total_attempts" in data
assert "success_rate" in data
assert "recent_failures" in data
def test_api_codebase_summary(self, client):
"""API should return codebase summary."""
response = client.get("/self-coding/api/codebase/summary")
assert response.status_code == 200
data = response.json()
assert "summary" in data
def test_api_codebase_reindex(self, client):
"""API should trigger reindex."""
response = client.post("/self-coding/api/codebase/reindex")
assert response.status_code == 200
data = response.json()
assert "indexed" in data
assert "failed" in data
assert "skipped" in data
class TestSelfCodingExecuteEndpoint:
"""Execute endpoint tests."""
def test_execute_api_endpoint(self, client):
"""Execute API endpoint should accept task."""
# Note: This will actually try to execute, which may fail
# In production, this should be mocked or require auth
response = client.post(
"/self-coding/api/execute",
json={"task_description": "Test task that will fail preflight"}
)
# Should return response (success or failure)
assert response.status_code == 200
data = response.json()
assert "success" in data
assert "message" in data
def test_execute_htmx_endpoint(self, client):
"""Execute HTMX endpoint should accept form data."""
response = client.post(
"/self-coding/execute",
data={"task_description": "Test task that will fail preflight"}
)
# Should return HTML response
assert response.status_code == 200
assert "text/html" in response.headers["content-type"]
class TestSelfCodingNavigation:
"""Navigation integration tests."""
def test_nav_link_in_header(self, client):
"""Self-coding link should be in header."""
response = client.get("/")
assert response.status_code == 200
assert "/self-coding" in response.text
assert "SELF-CODING" in response.text