from __future__ import annotations

from fastapi import FastAPI
from fastapi.testclient import TestClient

from src.api.v1.agents import router


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

    response = client.get("/api/v1/agents/dependency-upgrade-approval-package-template")

    assert response.status_code == 200
    data = response.json()
    assert data["schema_version"] == "dependency_upgrade_approval_package_template_v1"
    assert data["program_status"]["overall_completion_percent"] == 100
    assert data["program_status"]["read_only_mode"] is True
    assert data["program_status"]["current_task_id"] == "P1-206"
    assert data["program_status"]["next_task_id"] == "P1-103"
    assert data["rollups"]["total_templates"] == len(data["package_templates"]) == 8
    assert len(data["rollups"]["hitl_required_template_ids"]) == 8
    assert data["operation_boundaries"]["read_only_template_allowed"] is True
    assert data["operation_boundaries"]["package_upgrade_allowed"] is False
    assert data["operation_boundaries"]["lockfile_write_allowed"] is False
    assert data["operation_boundaries"]["manifest_write_allowed"] is False
    assert data["operation_boundaries"]["dockerfile_write_allowed"] is False
    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 data["operation_boundaries"]["package_publish_allowed"] is False
    assert data["operation_boundaries"]["shadow_or_canary_allowed"] is False
    assert data["decision_gate_contract"]["hitl_required"] is True
    assert any(
        template["template_id"] == "docker_base_digest_pin_package"
        for template in data["package_templates"]
    )
    assert any(
        template["template_id"] == "external_source_activation_package"
        for template in data["package_templates"]
    )
