from __future__ import annotations

from fastapi import FastAPI
from fastapi.testclient import TestClient

from src.api.v1.agents import router


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

    response = client.get("/api/v1/agents/agent-tool-adoption-approval-package")

    assert response.status_code == 200
    data = response.json()
    assert data["schema_version"] == "ai_agent_tool_adoption_approval_package_v1"
    assert data["program_status"]["overall_completion_percent"] == 55
    assert data["program_status"]["current_task_id"] == "P2-402C"
    assert data["program_status"]["next_task_id"] == "P2-402D"
    assert data["program_status"]["read_only_mode"] is True
    assert data["approval_boundaries"]["tool_install_allowed"] is False
    assert data["approval_boundaries"]["ci_workflow_change_allowed"] is False
    assert data["approval_boundaries"]["external_registry_lookup_allowed"] is False
    assert data["approval_boundaries"]["vulnerability_database_download_allowed"] is False
    assert data["approval_boundaries"]["gitea_pr_creation_allowed"] is False
    assert data["approval_boundaries"]["telegram_direct_send_allowed"] is False
    assert data["rollups"]["tool_count"] == 5
    assert data["rollups"]["source_evidence_count"] == 5
    assert data["rollups"]["adoption_lane_count"] == 4
    assert data["rollups"]["tool_install_allowed_count"] == 0
    assert data["rollups"]["ci_change_allowed_count"] == 0
    assert data["rollups"]["auto_merge_allowed_count"] == 0
    assert data["rollups"]["telegram_direct_send_count"] == 0
    assert any(tool["tool_id"] == "renovate_gitea" for tool in data["tool_candidates"])
    assert any(tool["tool_id"] == "osv_scanner" for tool in data["tool_candidates"])
    assert any(tool["tool_id"] == "trivy" for tool in data["tool_candidates"])
    assert any(tool["tool_id"] == "syft" for tool in data["tool_candidates"])
    assert any(tool["tool_id"] == "grype" for tool in data["tool_candidates"])
