from __future__ import annotations

from fastapi import FastAPI
from fastapi.testclient import TestClient

from src.api.v1.agents import router


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

    response = client.get("/api/v1/agents/docker-build-surface-inventory")

    assert response.status_code == 200
    data = response.json()
    assert data["schema_version"] == "docker_build_surface_inventory_v1"
    assert data["program_status"]["overall_completion_percent"] == 97
    assert data["program_status"]["read_only_mode"] is True
    assert data["program_status"]["next_task_id"] == "P1-204"
    assert data["rollups"]["total_surfaces"] == len(data["surfaces"]) == 2
    assert data["rollups"]["external_image_ref_count"] == 3
    assert data["rollups"]["digest_pinned_image_count"] == 0
    assert data["rollups"]["build_time_network_fetch_count"] == 4
    assert data["rollups"]["non_root_runtime_count"] == 2
    assert data["operation_boundaries"]["docker_build_allowed"] is False
    assert data["operation_boundaries"]["image_pull_allowed"] is False
    assert data["operation_boundaries"]["registry_push_allowed"] is False
    assert any(finding["finding_id"] == "base_images_not_digest_pinned" for finding in data["risk_findings"])
    assert any(surface["surface_id"] == "api_dockerfile" for surface in data["surfaces"])
