import pytest
from httpx import ASGITransport, AsyncClient

from src.main import app


@pytest.mark.asyncio
async def test_get_agent_failure_receipt_no_send_replay_api() -> None:
    transport = ASGITransport(app=app)
    async with AsyncClient(transport=transport, base_url="http://test") as client:
        response = await client.get("/api/v1/agents/agent-failure-receipt-no-send-replay")

    assert response.status_code == 200
    data = response.json()
    assert data["schema_version"] == "ai_agent_failure_receipt_no_send_replay_v1"
    assert data["program_status"]["current_task_id"] == "P2-116"
    assert data["program_status"]["next_task_id"] == "P2-117"
    assert data["program_status"]["overall_completion_percent"] == 100

    rollups = data["rollups"]
    assert rollups["no_send_replay_fixture_count"] == 5
    assert rollups["route_lock_check_count"] == 4
    assert rollups["replay_verifier_check_count"] == 5
    assert rollups["blocked_send_count"] == 5
    assert rollups["operator_action_count"] == 5
    assert rollups["critical_blocker_count"] == 3
    assert rollups["owner_approval_received_count"] == 0
    assert rollups["canonical_runtime_target_read_count"] == 0
    assert rollups["failure_receipt_send_count"] == 0
    assert rollups["gateway_queue_write_count"] == 0
    assert rollups["telegram_send_count"] == 0
    assert rollups["bot_api_call_count"] == 0
    assert rollups["report_receipt_write_count"] == 0
    assert rollups["reviewer_queue_write_count"] == 0
    assert rollups["result_capture_write_count"] == 0
    assert rollups["learning_write_count"] == 0
    assert rollups["playbook_trust_write_count"] == 0
    assert rollups["production_write_count"] == 0

    assert {fixture["target_channel"] for fixture in data["no_send_replay_fixtures"]} == {"awoooi_sre_war_room"}
    assert {check["target_route"] for check in data["route_lock_checks"]} == {"awoooi_sre_war_room"}
