from fastapi.testclient import TestClient

from src.main import app


def test_get_ai_agent_runtime_readback_approval_package_api():
    client = TestClient(app)
    response = client.get("/api/v1/agents/agent-runtime-readback-approval-package")

    assert response.status_code == 200
    data = response.json()
    assert data["schema_version"] == "ai_agent_runtime_readback_approval_package_v1"
    assert data["program_status"]["current_task_id"] == "P2-109"
    assert data["program_status"]["next_task_id"] == "P2-110"
    assert data["program_status"]["overall_completion_percent"] == 100
    assert data["prior_readback_readiness"]["source_schema_version"] == (
        "ai_agent_owner_approved_result_capture_readback_v1"
    )
    assert data["prior_readback_readiness"]["readback_digest_count"] == 5
    assert data["approval_package_truth"]["p2_107_readback_loaded"] is True
    assert data["approval_package_truth"]["approval_package_ready"] is True
    assert data["approval_package_truth"]["canonical_readback_plan_ready"] is True
    assert data["approval_package_truth"]["rollback_drill_ready"] is True
    assert data["approval_package_truth"]["telegram_failure_receipt_gate_ready"] is True
    assert data["approval_package_truth"]["canonical_runtime_readback_enabled"] is False
    assert data["approval_package_truth"]["runtime_result_capture_write_enabled"] is False
    assert data["approval_package_truth"]["reviewer_queue_write_enabled"] is False
    assert data["approval_package_truth"]["telegram_failure_receipt_send_enabled"] is False
    assert data["approval_package_truth"]["bot_api_call_enabled"] is False
    assert data["approval_package_truth"]["rollback_work_item_write_enabled"] is False
    assert data["approval_package_truth"]["runtime_readback_execution_count"] == 0
    assert data["rollups"]["approval_packet_count"] == 5
    assert data["rollups"]["canonical_readback_plan_count"] == 4
    assert data["rollups"]["rollback_drill_lane_count"] == 4
    assert data["rollups"]["telegram_failure_receipt_gate_count"] == 4
    assert data["rollups"]["operator_action_count"] == 5
    assert data["rollups"]["owner_approval_received_count"] == 0
    assert data["rollups"]["runtime_readback_execution_count"] == 0
    assert data["rollups"]["result_capture_write_count"] == 0
    assert data["rollups"]["score_write_count"] == 0
    assert data["rollups"]["learning_write_count"] == 0
    assert data["rollups"]["playbook_trust_write_count"] == 0
    assert data["rollups"]["reviewer_queue_write_count"] == 0
    assert data["rollups"]["gateway_queue_write_count"] == 0
    assert data["rollups"]["telegram_failure_receipt_send_count"] == 0
    assert data["rollups"]["bot_api_call_count"] == 0
    assert data["rollups"]["rollback_work_item_write_count"] == 0
    assert data["rollups"]["production_write_count"] == 0
