from __future__ import annotations

from fastapi import FastAPI
from fastapi.testclient import TestClient

from src.api.v1.agents import router


def test_ai_agent_live_read_model_gate_endpoint_returns_committed_snapshot():
    app = FastAPI()
    app.include_router(router, prefix="/api/v1")
    client = TestClient(app)

    response = client.get("/api/v1/agents/agent-live-read-model-gate")

    assert response.status_code == 200
    data = response.json()
    assert data["schema_version"] == "ai_agent_live_read_model_gate_v1"
    assert data["program_status"]["overall_completion_percent"] == 55
    assert data["program_status"]["current_task_id"] == "P2-403B"
    assert data["program_status"]["next_task_id"] == "P2-403C"
    assert data["program_status"]["read_only_mode"] is True
    assert data["program_status"]["runtime_authority"] == "gate_plan_only_no_live_worker"
    assert data["existing_storage_contract"]["db_table"] == "agent_sessions"
    assert data["existing_storage_contract"]["approved_for_live_query"] is False
    assert data["redis_stream_contract"]["consumer_group_allowed"] is False
    assert data["live_truth"]["active_live_agent_sessions"] == 0
    assert data["live_truth"]["live_redis_events_24h"] == 0
    assert data["approval_boundaries"]["live_db_query_allowed"] is False
    assert data["approval_boundaries"]["redis_consumer_group_allowed"] is False
    assert data["approval_boundaries"]["telegram_direct_send_allowed"] is False
    assert data["display_redaction_contract"]["work_window_conversation_display_allowed"] is False
    assert data["rollups"]["read_model_card_count"] == 5
    assert data["rollups"]["gate_count"] == 5
    assert data["rollups"]["no_write_smoke_count"] == 5
    assert data["rollups"]["live_truth_count_total"] == 0
