"""ProofWarden (mgf-test-web) UI specs — the second console, same thin shape.

Proves the harness generalizes to a second console with zero library changes: the
same ``console`` fixture, the same pillars. Coverage spans all four views
(Catalog / Running / History / CI), the populated catalog + history, the
warden-down fail-closed ribbon (a "no broken states" guarantee), and the
honest-absence 200. Uses ProofWarden's own venv + a synthetic catalog.
"""

from __future__ import annotations

from typing import TYPE_CHECKING

import pytest

if TYPE_CHECKING:
    from mgf.uitest_web import Console

SLUG = "demo"
VIEWS = ["catalog", "running", "history", "ci"]


@pytest.mark.e2e
def test_overview_opens_clean(console: Console) -> None:
    console.open("/")
    console.assert_status(200)
    console.assert_layout_clean()
    console.snapshot("overview")


@pytest.mark.e2e
@pytest.mark.parametrize("view", VIEWS)
def test_view_renders_with_clean_layout(console: Console, view: str) -> None:
    console.open(f"/p/{SLUG}/{view}")
    console.assert_status(200)
    console.assert_layout_clean()
    console.snapshot(view)


@pytest.mark.e2e
def test_catalog_lists_the_tests(console: Console) -> None:
    console.open(f"/p/{SLUG}/catalog")
    body = console.text()
    assert "test_one" in body and "test_two" in body, "catalog did not list the synthetic tests"


@pytest.mark.e2e
def test_history_shows_the_run_record(console: Console) -> None:
    console.open(f"/p/{SLUG}/history")
    body = console.text().lower()
    assert "run_hist01" in console.text() or "pass" in body, "history did not show the run record"


@pytest.mark.e2e
def test_running_is_failclosed_not_a_crash(console: Console) -> None:
    """No warden is running -> Running shows a fail-closed ribbon at 200, never a 500."""
    console.open(f"/p/{SLUG}/running")
    console.assert_status(200)
    console.assert_layout_clean()


@pytest.mark.e2e
def test_unknown_project_is_an_honest_200(console: Console) -> None:
    console.open("/p/does-not-exist/catalog")
    console.assert_status(200)
    console.assert_layout_clean()


@pytest.mark.e2e
def test_console_is_healthy(console: Console) -> None:
    console.open(f"/p/{SLUG}/catalog")
    console.assert_healthy()
