"""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 json import sqlite3 from contextlib import closing from pathlib import Path import pytest from agent_team.status_page import ( STAGES, Snapshot, TaskView, build_snapshot, render_html, snapshot_to_dict, ) # --- 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 "