from __future__ import annotations

from fastapi import FastAPI
from fastapi.testclient import TestClient

from src.api.v1.agents import router


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

    response = client.get("/api/v1/agents/package-supply-chain-inventory")

    assert response.status_code == 200
    data = response.json()
    assert data["schema_version"] == "package_supply_chain_inventory_v1"
    assert data["program_status"]["overall_completion_percent"] == 100
    assert data["program_status"]["read_only_mode"] is True
    assert data["program_status"]["next_task_id"] == "P1-103"
    assert data["rollups"]["total_surfaces"] == len(data["surfaces"]) == 10
    assert data["rollups"]["python_manifest_count"] == 6
    assert data["rollups"]["by_status"]["action_required"] == 5
    assert data["rollups"]["by_status"]["planned_next"] == 0
    assert data["operation_boundaries"]["dependency_installation_allowed"] is False
    assert data["operation_boundaries"]["lockfile_write_allowed"] is False
    assert data["operation_boundaries"]["external_cve_lookup_allowed"] is False
    assert any(finding["finding_id"] == "api_python_manifest_drift" for finding in data["drift_findings"])
    assert any(finding["finding_id"] == "javascript_manifest_lockfile_in_sync" for finding in data["drift_findings"])
    assert any(finding["finding_id"] == "docker_base_images_not_digest_pinned" for finding in data["drift_findings"])
    assert any(finding["finding_id"] == "dependency_risk_policy_defined" for finding in data["drift_findings"])
    assert any(finding["finding_id"] == "dependency_drift_check_plan_defined" for finding in data["drift_findings"])
    assert any(
        finding["finding_id"] == "dependency_upgrade_approval_package_template_defined"
        for finding in data["drift_findings"]
    )
