import pytest
from httpx import ASGITransport, AsyncClient

from src.main import app


@pytest.mark.asyncio
async def test_get_agent_owner_approved_result_capture_promotion_dry_run_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-owner-approved-result-capture-promotion-dry-run")

    assert response.status_code == 200
    data = response.json()
    assert data["schema_version"] == "ai_agent_owner_approved_result_capture_promotion_dry_run_v1"
    assert data["program_status"]["current_task_id"] == "P2-120"
    assert data["program_status"]["next_task_id"] == "P2-121"
    assert data["program_status"]["overall_completion_percent"] == 100

    rollups = data["rollups"]
    assert rollups["promotion_dry_run_template_count"] == 5
    assert rollups["owner_acceptance_fixture_count"] == 5
    assert rollups["dry_run_verifier_check_count"] == 5
    assert rollups["blocked_runtime_promotion_count"] == 5
    assert rollups["operator_action_count"] == 5
    assert rollups["critical_blocker_count"] == 3
    assert rollups["owner_approval_received_count"] == 0
    assert rollups["capture_promotion_approved_count"] == 0
    assert rollups["dry_run_preview_generated_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["production_write_count"] == 0

    assert {template["target_dry_run"] for template in data["promotion_dry_run_templates"]} == {
        "result_capture_promotion_dry_run_preview"
    }
    assert {template["runtime_write_enabled"] for template in data["promotion_dry_run_templates"]} == {False}
