from __future__ import annotations

from fastapi import FastAPI
from fastapi.testclient import TestClient

from src.api.v1.agents import router


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

    response = client.get("/api/v1/agents/agent-report-no-write-analysis-runtime")

    assert response.status_code == 200
    data = response.json()
    assert data["schema_version"] == "ai_agent_report_no_write_analysis_runtime_v1"
    assert data["program_status"]["current_task_id"] == "P2-407"
    assert data["program_status"]["next_task_id"] == "P2-408"
    assert data["program_status"]["read_only_mode"] is True
    assert data["program_status"]["runtime_authority"] == "report_analysis_no_write_runtime_only_committed_snapshot"
    assert data["rollups"]["source_readback_count"] == len(data["source_readbacks"]) == 5
    assert data["rollups"]["report_input_count"] == len(data["report_inputs"]) == 3
    assert data["rollups"]["agent_analysis_pass_count"] == len(data["agent_analysis_passes"]) == 3
    assert data["rollups"]["draft_recommendation_count"] == len(data["draft_recommendations"]) == 6
    assert data["rollups"]["draft_artifact_count"] == len(data["draft_artifacts"]) == 4
    assert data["rollups"]["owner_review_gate_count"] == len(data["owner_review_gates"]) == 3
    assert data["rollups"]["approval_required_recommendation_count"] == 0
    assert data["rollups"]["live_report_delivery_count"] == 0
    assert data["rollups"]["live_ai_analysis_count"] == 0
    assert data["rollups"]["telegram_send_count"] == 0
    assert data["rollups"]["gateway_queue_write_count"] == 0
    assert data["rollups"]["bot_api_call_count"] == 0
    assert data["rollups"]["receipt_production_write_count"] == 0
    assert data["rollups"]["production_write_count"] == 0
    assert data["rollups"]["secret_read_count"] == 0
    assert data["rollups"]["paid_api_call_count"] == 0
    assert data["rollups"]["host_write_count"] == 0
    assert data["rollups"]["kubectl_action_count"] == 0
    assert data["telegram_policy"]["canonical_room"] == "AwoooI SRE 戰情室"
    assert data["telegram_policy"]["canonical_room_env"] == "SRE_GROUP_CHAT_ID"
    assert data["telegram_policy"]["telegram_send_allowed"] is False
    assert data["telegram_policy"]["gateway_queue_write_allowed"] is False
    assert data["telegram_policy"]["direct_bot_api_allowed"] is False
    assert data["activation_boundaries"]["ai_analysis_runtime_enabled"] is False
    assert data["activation_boundaries"]["openclaw_replacement_allowed"] is False
