from fastapi.testclient import TestClient

from src.main import app


def test_get_ai_agent_report_truth_actionability_review_api():
    client = TestClient(app)
    response = client.get("/api/v1/agents/agent-report-truth-actionability-review")

    assert response.status_code == 200
    data = response.json()
    assert data["schema_version"] == "ai_agent_report_truth_actionability_review_v1"
    assert data["program_status"]["current_task_id"] == "P2-403K"
    assert data["program_status"]["next_task_id"] == "P2-403L"
    assert data["report_truth"]["all_zero_weekly_report_is_actionable_anomaly"] is True
    assert data["report_truth"]["freshness_gate_implemented"] is True
    assert data["report_truth"]["source_confidence_gate_implemented"] is True
    assert data["report_truth"]["actionability_score_implemented"] is True
    assert data["report_truth"]["telegram_report_send_allowed"] is False
    assert data["rollups"]["source_freshness_gate_count"] == 6
    assert data["rollups"]["stale_or_untrusted_source_count"] == 5
    assert data["rollups"]["source_confidence_gate_count"] == 5
    assert data["rollups"]["low_confidence_gate_count"] == 5
    assert data["rollups"]["report_actionability_score_count"] == 4
    assert data["rollups"]["zero_signal_work_item_count"] == 5
    assert data["rollups"]["all_zero_weekly_report_actionability_score"] == 82
    assert data["rollups"]["zero_signal_finding_count"] == 5
    assert data["rollups"]["critical_finding_count"] == 1
    assert data["rollups"]["high_finding_count"] == 3
    assert data["rollups"]["cadence_contract_count"] == 3
    assert data["rollups"]["missing_cadence_contract_count"] == 1
    assert data["rollups"]["actionability_lane_count"] == 4
    assert data["telegram_routing_consolidation"]["canonical_room_name"] == "AwoooI SRE 戰情室"
    assert data["telegram_routing_consolidation"]["canonical_room_env"] == "SRE_GROUP_CHAT_ID"
    assert data["telegram_routing_consolidation"]["other_bot_or_group_alerts_allowed"] is False
    assert data["telegram_routing_consolidation"]["direct_telegram_api_send_allowed"] is False
    assert data["telegram_egress_guard"]["summary"]["live_direct_bot_api_call_count"] == 0
    assert data["telegram_egress_guard"]["summary"]["new_bypass_count"] == 0
    assert data["telegram_egress_guard"]["summary"]["gitea_workflow_direct_bot_api_call_count"] == 0
    assert data["telegram_egress_guard"]["summary"]["ops_script_direct_bot_api_call_count"] == 0
    assert data["telegram_egress_guard"]["summary"]["api_direct_bot_api_call_count"] == 0
    assert (
        data["telegram_egress_guard"]["summary"]["direct_bot_api_awooop_db_receipt_missing_count"]
        == 0
    )
    assert (
        data["telegram_egress_guard"]["summary"]["direct_bot_api_ai_controlled_route_missing_count"]
        == 0
    )
    assert (
        data["telegram_egress_guard"]["telegram_receipt_coverage"][
            "all_telegram_alerts_have_db_or_log_receipts"
        ]
        is True
    )
    assert (
        data["telegram_egress_guard"]["telegram_receipt_coverage"]["all_telegram_alerts_ai_controlled"]
        is True
    )
    assert data["rollups"]["telegram_route_finding_count"] == 4
    assert data["rollups"]["legacy_or_direct_route_count"] == 4
    assert data["rollups"]["operator_action_count"] == 5
