from __future__ import annotations

from fastapi import FastAPI
from fastapi.testclient import TestClient

from src.api.v1.agents import router


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

    response = client.get("/api/v1/agents/agent-low-medium-risk-whitelist")

    assert response.status_code == 200
    data = response.json()
    assert data["schema_version"] == "ai_agent_low_medium_risk_whitelist_v1"
    assert data["program_status"]["current_task_id"] == "P2-408"
    assert data["program_status"]["next_task_id"] == "P2-409"
    assert data["program_status"]["read_only_mode"] is True
    assert (
        data["program_status"]["runtime_authority"]
        == "low_medium_risk_whitelist_no_live_execution_committed_snapshot"
    )
    assert data["rollups"]["source_readback_count"] == len(data["source_readbacks"]) == 5
    assert data["rollups"]["whitelist_candidate_count"] == len(data["whitelist_candidates"]) == 6
    assert data["rollups"]["low_risk_candidate_count"] == 3
    assert data["rollups"]["medium_risk_candidate_count"] == 3
    assert data["rollups"]["dry_run_verifier_count"] == len(data["dry_run_verifiers"]) == 5
    assert data["rollups"]["rollback_proof_count"] == len(data["rollback_proofs"]) == 5
    assert data["rollups"]["audit_reason_template_count"] == len(data["audit_reason_templates"]) == 6
    assert data["rollups"]["high_risk_redirect_count"] == len(data["high_risk_redirects"]) == 3
    assert data["rollups"]["owner_review_gate_count"] == len(data["owner_review_gates"]) == 3
    assert data["rollups"]["live_execution_approval_required_count"] == 6
    assert data["rollups"]["blocked_runtime_action_count"] == 27
    assert data["rollups"]["auto_worker_run_count"] == 0
    assert data["rollups"]["low_risk_execution_count"] == 0
    assert data["rollups"]["medium_risk_execution_count"] == 0
    assert data["rollups"]["gateway_queue_write_count"] == 0
    assert data["rollups"]["telegram_send_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["rollups"]["destructive_operation_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"]["auto_worker_enabled"] is False
    assert data["activation_boundaries"]["low_risk_live_execution_enabled"] is False
    assert data["activation_boundaries"]["medium_risk_live_execution_enabled"] is False
    assert data["activation_boundaries"]["openclaw_replacement_allowed"] is False
