from __future__ import annotations

from src.api.v1.platform import router


def test_runs_list_route_is_registered_before_dynamic_run_id() -> None:
    paths = [
        route.path
        for route in router.routes
        if "GET" in getattr(route, "methods", set())
    ]

    assert "/runs/list" in paths
    assert "/runs/{run_id}/detail" in paths
    assert "/runs/{run_id}" in paths
    assert paths.index("/runs/list") < paths.index("/runs/{run_id}")
    assert paths.index("/runs/{run_id}/detail") < paths.index("/runs/{run_id}")


def test_recent_events_route_is_registered() -> None:
    paths = [
        route.path
        for route in router.routes
        if "GET" in getattr(route, "methods", set())
    ]

    assert "/events/recent" in paths


def test_truth_chain_route_is_registered() -> None:
    paths = [
        route.path
        for route in router.routes
        if "GET" in getattr(route, "methods", set())
    ]

    assert "/truth-chain/{source_id}" in paths


def test_truth_chain_quality_summary_route_is_registered_before_dynamic_source_id() -> None:
    paths = [
        route.path
        for route in router.routes
        if "GET" in getattr(route, "methods", set())
    ]

    assert "/truth-chain/quality/summary" in paths
    assert "/truth-chain/{source_id}" in paths
    assert paths.index("/truth-chain/quality/summary") < paths.index("/truth-chain/{source_id}")
