from fastapi.testclient import TestClient

from src.main import app


def test_get_ai_agent_runtime_readback_implementation_review_api():
    client = TestClient(app)
    response = client.get("/api/v1/agents/agent-runtime-readback-implementation-review")

    assert response.status_code == 200
    data = response.json()
    assert data["schema_version"] == "ai_agent_runtime_readback_implementation_review_v1"
    assert data["program_status"]["current_task_id"] == "P2-110"
    assert data["program_status"]["next_task_id"] == "P2-111"
    assert data["program_status"]["overall_completion_percent"] == 100
    assert data["prior_approval_package"]["source_schema_version"] == "ai_agent_runtime_readback_approval_package_v1"
    assert data["prior_approval_package"]["approval_packet_count"] == 5
    assert data["implementation_review_truth"]["p2_109_approval_package_loaded"] is True
    assert data["implementation_review_truth"]["implementation_review_ready"] is True
    assert data["implementation_review_truth"]["adapter_contract_ready"] is True
    assert data["implementation_review_truth"]["verifier_contract_ready"] is True
    assert data["implementation_review_truth"]["redaction_contract_ready"] is True
    assert data["implementation_review_truth"]["telemetry_receipt_contract_ready"] is True
    assert data["implementation_review_truth"]["canonical_runtime_readback_enabled"] is False
    assert data["implementation_review_truth"]["live_query_enabled"] is False
    assert data["implementation_review_truth"]["runtime_result_capture_write_enabled"] is False
    assert data["implementation_review_truth"]["reviewer_queue_write_enabled"] is False
    assert data["implementation_review_truth"]["telegram_failure_receipt_send_enabled"] is False
    assert data["implementation_review_truth"]["bot_api_call_enabled"] is False
    assert data["implementation_review_truth"]["rollback_work_item_write_enabled"] is False
    assert data["implementation_review_truth"]["runtime_readback_execution_count"] == 0
    assert data["rollups"]["implementation_review_card_count"] == 5
    assert data["rollups"]["no_write_verifier_check_count"] == 5
    assert data["rollups"]["implementation_blocker_count"] == 5
    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"]["live_query_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
