From de215dfb649aea0e986734e9d4ebc2143c671f25 Mon Sep 17 00:00:00 2001 From: Adam Moussa Date: Tue, 23 Jun 2026 14:15:34 -0400 Subject: [PATCH] test(agent-team): unit tests for status_page render + read-only reader --- agent-team/tests/test_status_page.py | 265 +++++++++++++++++++++++++++ 1 file changed, 265 insertions(+) create mode 100644 agent-team/tests/test_status_page.py diff --git a/agent-team/tests/test_status_page.py b/agent-team/tests/test_status_page.py new file mode 100644 index 0000000..0701622 --- /dev/null +++ b/agent-team/tests/test_status_page.py @@ -0,0 +1,265 @@ +"""Tests for the LAN-only read-only status dashboard (``agent_team.status_page``). + +No live socket is bound: :func:`render_html` is exercised against fabricated +:class:`Snapshot` objects, and the read-only reader (:func:`build_snapshot`) is +exercised against a temp SQLite ledger seeded with a couple of rows (a real +``SqliteSaver`` checkpoint plus ``pending_questions`` / ``budget_ledger`` rows). +``conftest.py`` already puts ``agent-team/`` on ``sys.path``. +""" + +from __future__ import annotations + +import sqlite3 +from contextlib import closing +from pathlib import Path + +import pytest + +from agent_team.status_page import ( + Snapshot, + TaskView, + build_snapshot, + render_html, +) + +# --- pure render_html tests (no DB, no socket). ------------------------------ + + +def _sample_snapshot() -> Snapshot: + return Snapshot( + generated_at="2026-06-23 12:00:00 UTC", + db_path="/home/adam/orchestrator/agent-team/state/agent_team.sqlite", + ok=True, + tasks=[ + TaskView( + thread_id="abc123def456", + short_id="abc123de", + task="remediate CVE-2026-0001 in payments-svc", + current_phase="clarify", + status="waiting_human", + waiting=True, + waiting_since="2026-06-23T11:50:00+00:00", + ), + TaskView( + thread_id="ffff0000aaaa", + short_id="ffff0000", + task="add a smoke-test file", + current_phase="plan", + status="active", + waiting=False, + ), + TaskView( + thread_id="dead0000beef", + short_id="dead0000", + task="stalled task", + current_phase="parked", + status="parked", + waiting=False, + ), + ], + question_counts={"open": 1, "answered": 4, "expired": 1}, + recent_spend=[ + { + "recorded_at": "2026-06-23T11:00:00+00:00", + "stage": "plan", + "model": "claude-opus-4", + "usd_cost": 0.1234, + } + ], + spend_total_usd=1.5, + budget_available=True, + ) + + +def test_render_html_returns_complete_document() -> None: + html_out = render_html(_sample_snapshot()) + assert html_out.startswith("") + assert html_out.rstrip().endswith("") + # Auto-refresh + offline (no external CDN / http references). + assert '' in html_out + assert "http://" not in html_out and "https://" not in html_out + assert "