from __future__ import annotations

from fastapi import FastAPI
from fastapi.testclient import TestClient

from src.api.v1.agents import router


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

    response = client.get("/api/v1/agents/agent-host-runaway-aiops-loop-readiness")

    assert response.status_code == 200
    data = response.json()
    assert data["schema_version"] == "host_runaway_aiops_loop_readiness_v1"
    assert data["program_status"]["current_task_id"] == "P3-009"
    assert data["program_status"]["next_task_id"] == "P3-010"
    assert data["program_status"]["read_only_mode"] is True
    assert data["rollups"]["loop_stage_count"] == len(data["loop_stages"]) == 6
    assert data["rollups"]["alert_lane_count"] == len(data["alert_lanes"]) == 2
    assert data["rollups"]["asset_writeback_contract_count"] == len(data["asset_writeback_contract"]) == 5
    assert data["rollups"]["runtime_remediation_authorized_count"] == 0
    assert data["rollups"]["process_termination_count"] == 0
    assert data["rollups"]["host_write_count"] == 0
    assert data["rollups"]["docker_restart_count"] == 0
    assert data["live_readback"]["host_label"] == "110"
    assert data["live_readback"]["monitor_up"] == 1
    assert data["live_readback"]["orphan_browser_group_count"] == 0
    assert data["live_readback"]["remediation_authorized_count"] == 0
    assert data["live_readback"]["deploy_marker"] == "2d278568"
    assert data["remediation_gate"]["dry_run_required"] is True
    assert data["remediation_gate"]["owner_approval_required"] is True
    assert data["remediation_gate"]["process_termination_authorized"] is False
    assert data["activation_boundaries"]["runtime_remediation_enabled"] is False
    assert data["activation_boundaries"]["process_termination_authorized"] is False
    assert data["activation_boundaries"]["host_write_enabled"] is False
