from __future__ import annotations

from fastapi import FastAPI
from fastapi.testclient import TestClient

from src.api.v1.agents import router


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

    response = client.get("/api/v1/agents/agent-proactive-operations-contract")

    assert response.status_code == 200
    data = response.json()
    assert data["schema_version"] == "ai_agent_proactive_operations_contract_v1"
    assert data["program_status"]["overall_completion_percent"] == 100
    assert data["program_status"]["current_task_id"] == "P2-403J"
    assert data["program_status"]["next_task_id"] == "P2-403K"
    assert data["program_status"]["read_only_mode"] is True
    assert data["approval_boundaries"]["runtime_version_update_allowed"] is False
    assert data["approval_boundaries"]["package_upgrade_allowed"] is False
    assert data["approval_boundaries"]["workflow_schedule_enabled"] is False
    assert data["approval_boundaries"]["telegram_direct_send_allowed"] is False
    assert data["rollups"]["version_domain_count"] == 12
    assert data["rollups"]["delegable_capability_count"] == 24
    assert data["rollups"]["rollout_task_count"] == 17
    assert data["rollups"]["auto_execute_allowed_count"] == 0
    assert any(domain["domain_id"] == "host_os_packages" for domain in data["version_lifecycle_domains"])
    assert any(
        capability["capability_id"] == "market_watch_and_candidate_intake"
        for capability in data["delegable_capabilities"]
    )
