from __future__ import annotations

import pytest
from httpx import ASGITransport, AsyncClient

from src.main import app


@pytest.mark.asyncio
async def test_get_agent_result_capture_owner_approved_execution_rehearsal_api() -> None:
    transport = ASGITransport(app=app)
    async with AsyncClient(transport=transport, base_url="http://testserver") as client:
        response = await client.get("/api/v1/agents/agent-result-capture-owner-approved-execution-rehearsal")

    assert response.status_code == 200
    data = response.json()
    assert data["schema_version"] == "ai_agent_result_capture_owner_approved_execution_rehearsal_v1"
    assert data["program_status"]["current_task_id"] == "P2-126"
    assert data["program_status"]["next_task_id"] == "P2-127"

    rollups = data["rollups"]
    assert rollups["execution_rehearsal_count"] == 5
    assert rollups["no_write_apply_check_count"] == 5
    assert rollups["post_write_verifier_rehearsal_count"] == 5
    assert rollups["rollback_drill_count"] == 5
    assert rollups["blocked_live_apply_count"] == 6
    assert rollups["operator_action_count"] == 5
    assert rollups["writer_apply_count"] == 0
    assert rollups["execution_apply_count"] == 0
    assert rollups["receipt_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["gateway_queue_write_count"] == 0
    assert rollups["telegram_send_count"] == 0
    assert rollups["bot_api_call_count"] == 0
    assert rollups["production_write_count"] == 0
    assert {item["no_write_only"] for item in data["execution_rehearsals"]} == {True}
    assert {item["live_apply_enabled"] for item in data["execution_rehearsals"]} == {False}
    assert {item["live_read_enabled"] for item in data["post_write_verifier_rehearsals"]} == {False}
