"""Deterministic route tests over a pinned synthetic federation (tmp roots).

These cover every render path independently of the live repos: a project that
reports (alpha), one that reports only an architecture graph + finished work
(beta), an unreadable one (broken), and the empty / absent slices.
"""

from __future__ import annotations

from fastapi.testclient import TestClient


def test_overview_lists_all_with_states(synthetic_client: TestClient) -> None:
    body = synthetic_client.get("/").text
    for slug in ("alpha", "beta", "broken"):
        assert slug in body
    # alpha + beta read IN_SYNC (hashes match, no git HEAD in tmp); broken UNREADABLE.
    assert "status-chip--in-sync" in body
    assert "status-chip--unreadable" in body


def test_alpha_roadmap_renders_chain_and_table(synthetic_client: TestClient) -> None:
    body = synthetic_client.get("/p/alpha/roadmap").text
    assert "Roadmap to v1.0" in body
    assert "Phase A — Foundation" in body
    assert "you are here" in body  # derived marker on the in_progress stage


def test_alpha_in_progress_lists_the_task(synthetic_client: TestClient) -> None:
    body = synthetic_client.get("/p/alpha/inprogress").text
    assert "Wire the spine reader" in body
    assert "in progress" in body.lower()


def test_alpha_decisions_lists_founder_task(synthetic_client: TestClient) -> None:
    body = synthetic_client.get("/p/alpha/decisions").text
    assert "Approve the schema freeze" in body  # owner == founder, still open


def test_beta_architecture_graph_renders(synthetic_client: TestClient) -> None:
    body = synthetic_client.get("/p/beta/architecture").text
    assert "core/engine" in body  # a node label
    assert "CORE" in body  # the layer group header


def test_beta_in_progress_empty_is_honest(synthetic_client: TestClient) -> None:
    # status present but no in_progress task -> explicit empty, not a blank table.
    body = synthetic_client.get("/p/beta/inprogress").text
    assert "Nothing in progress" in body


def test_beta_decisions_empty_is_honest(synthetic_client: TestClient) -> None:
    body = synthetic_client.get("/p/beta/decisions").text
    assert "Nothing waiting on you" in body


def test_beta_roadmap_absent_is_honest(synthetic_client: TestClient) -> None:
    # beta reports no roadmap.json -> "Nothing reported yet".
    assert "Nothing reported yet" in synthetic_client.get("/p/beta/roadmap").text


def test_broken_project_is_unreadable_not_500(synthetic_client: TestClient) -> None:
    resp = synthetic_client.get("/p/broken")
    assert resp.status_code == 200
    body = resp.text
    assert "UNREADABLE" in body
    assert "schema" in body  # the reason names the unrecognized schema_version
