from fastapi.testclient import TestClient

from src.main import app


def test_get_ai_agent_matched_playbook_learning_gap_api():
    client = TestClient(app)
    response = client.get("/api/v1/agents/agent-matched-playbook-learning-gap")

    assert response.status_code == 200
    data = response.json()
    assert data["schema_version"] == "ai_agent_matched_playbook_learning_gap_v1"
    assert data["program_status"]["current_task_id"] == "P2-104"
    assert data["program_status"]["next_task_id"] == "P2-105"
    assert data["program_status"]["overall_completion_percent"] == 100
    assert data["production_readback"]["approval_24h_total"] == 66
    assert data["production_readback"]["approval_24h_matched"] == 66
    assert data["production_readback"]["matched_rate_24h_percent"] == 100
    assert data["production_readback"]["playbook_updated_24h"] == 0
    assert data["learning_gap_truth"]["matched_playbook_id_gap_resolved"] is True
    assert data["learning_gap_truth"]["execution_learning_gap_detected"] is True
    assert data["learning_gap_truth"]["approved_without_execution_meta_24h"] == 63
    assert data["learning_gap_truth"]["playbook_trust_write_enabled"] is False
    assert data["learning_gap_truth"]["telegram_send_enabled"] is False
    assert data["rollups"]["gap_lane_count"] == 5
    assert data["rollups"]["learning_gate_count"] == 5
    assert data["rollups"]["writeback_candidate_count"] == 4
    assert data["rollups"]["live_learning_write_count"] == 0
    assert data["rollups"]["playbook_trust_write_count"] == 0
    assert data["rollups"]["gateway_queue_write_count"] == 0
    assert data["rollups"]["telegram_send_count"] == 0
