from __future__ import annotations

from fastapi import FastAPI
from fastapi.testclient import TestClient

from src.api.v1.agents import router


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

    response = client.get("/api/v1/agents/agent-communication-learning-contract")

    assert response.status_code == 200
    data = response.json()
    assert data["schema_version"] == "ai_agent_communication_learning_contract_v1"
    assert data["program_status"]["overall_completion_percent"] == 35
    assert data["program_status"]["current_task_id"] == "P2-401A"
    assert data["program_status"]["next_task_id"] == "P2-401B"
    assert data["program_status"]["read_only_mode"] is True
    assert data["communication_plane"]["message_bus"] == "Redis Streams"
    assert data["communication_plane"]["frontend_redaction"]["operator_conversation_display_allowed"] is False
    assert data["approval_boundaries"]["runtime_worker_allowed"] is False
    assert data["approval_boundaries"]["db_migration_allowed"] is False
    assert data["approval_boundaries"]["telegram_direct_send_allowed"] is False
    assert data["rollups"]["agent_lane_count"] == 3
    assert data["rollups"]["mcp_stack_count"] == 9
    assert data["rollups"]["rag_layer_count"] == 3
    assert data["rollups"]["learning_loop_count"] == 5
    assert data["rollups"]["intelligence_service_count"] == 7
    assert any(lane["agent_id"] == "openclaw" for lane in data["agent_lanes"])
    assert any(lane["agent_id"] == "hermes" for lane in data["agent_lanes"])
    assert any(lane["agent_id"] == "nemotron" for lane in data["agent_lanes"])
