Files
mono/test/bp/dashboard/routes.py
giles 1559c5c931 Add test runner dashboard service (test.rose-ash.com)
Public Quart microservice that runs pytest against shared/tests/ and
shared/sexp/tests/, serving an HTMX-powered sexp-rendered dashboard
with pass/fail/running status, auto-refresh polling, and re-run button.
No database — results stored in memory.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-28 20:08:10 +00:00

65 lines
2.0 KiB
Python

"""Test dashboard routes."""
from __future__ import annotations
import asyncio
from quart import Blueprint, Response, make_response, request
def register(url_prefix: str = "/") -> Blueprint:
bp = Blueprint("dashboard", __name__, url_prefix=url_prefix)
@bp.get("/")
async def index():
"""Full page dashboard with last results."""
from shared.sexp.page import get_template_context
from shared.browser.app.csrf import generate_csrf_token
from sexp.sexp_components import render_dashboard_page
import runner
ctx = await get_template_context()
result = runner.get_results()
running = runner.is_running()
csrf = generate_csrf_token()
html = await render_dashboard_page(ctx, result, running, csrf)
return await make_response(html, 200)
@bp.post("/run")
async def run():
"""Trigger a test run, redirect to /."""
import runner
if not runner.is_running():
asyncio.create_task(runner.run_tests())
# HX-Redirect for HTMX, regular redirect for non-HTMX
if request.headers.get("HX-Request"):
resp = Response("", status=200)
resp.headers["HX-Redirect"] = "/"
return resp
from quart import redirect as qredirect
return qredirect("/")
@bp.get("/results")
async def results():
"""HTMX partial — poll target for results table."""
from shared.browser.app.csrf import generate_csrf_token
from sexp.sexp_components import render_results_partial
import runner
result = runner.get_results()
running = runner.is_running()
csrf = generate_csrf_token()
html = await render_results_partial(result, running, csrf)
resp = Response(html, status=200, content_type="text/html")
# If still running, tell HTMX to keep polling
if running:
resp.headers["HX-Trigger-After-Swap"] = "test-still-running"
return resp
return bp