from __future__ import annotations

from fastapi import FastAPI
from fastapi.testclient import TestClient

from src.api.v1.agents import router


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

    response = client.get("/api/v1/agents/agent-version-lifecycle-update-proposal")

    assert response.status_code == 200
    data = response.json()
    assert data["schema_version"] == "ai_agent_version_lifecycle_update_proposal_v1"
    assert data["program_status"]["overall_completion_percent"] == 78
    assert data["program_status"]["current_task_id"] == "P2-413"
    assert data["program_status"]["next_task_id"] == "P2-414"
    assert data["program_status"]["read_only_mode"] is True
    assert data["runtime_boundaries"]["package_upgrade_allowed"] is False
    assert data["runtime_boundaries"]["k3s_upgrade_allowed"] is False
    assert data["runtime_boundaries"]["telegram_direct_send_allowed"] is False
    assert data["runtime_boundaries"]["production_write_allowed"] is False
    assert data["runtime_boundaries"]["openclaw_replacement_allowed"] is False
    assert data["rollups"]["domain_count"] == 12
    assert data["rollups"]["proposal_count"] == 12
    assert data["rollups"]["approval_required_count"] == 12
    assert data["rollups"]["auto_execution_allowed_count"] == 0
    assert data["rollups"]["telegram_direct_send_count"] == 0
    assert data["rollups"]["production_write_count"] == 0
    assert any(
        proposal["proposal_id"] == "telegram_bot_gateway_policy_refresh"
        for proposal in data["update_proposals"]
    )
