from __future__ import annotations

from fastapi import FastAPI
from fastapi.testclient import TestClient

from src.api.v1.agents import router


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

    response = client.get("/api/v1/agents/dependency-supply-chain-drift-monitor")

    assert response.status_code == 200
    data = response.json()
    assert data["schema_version"] == "dependency_supply_chain_drift_monitor_v1"
    assert data["program_status"]["current_task_id"] == "P2-004"
    assert data["program_status"]["next_task_id"] == "P2-406B"
    assert data["program_status"]["read_only_mode"] is True
    assert data["rollups"]["source_snapshot_count"] == len(data["source_snapshot_readbacks"]) == 6
    assert data["rollups"]["monitor_check_count"] == len(data["monitor_checks"]) == 7
    assert data["rollups"]["drift_candidate_count"] == len(data["drift_candidates"]) == 9
    assert data["rollups"]["action_required_candidate_count"] == 9
    assert data["rollups"]["blocked_operation_count"] == 20
    assert data["monitor_boundaries"]["external_cve_lookup_allowed"] is False
    assert data["monitor_boundaries"]["package_upgrade_allowed"] is False
    assert data["monitor_boundaries"]["lockfile_write_allowed"] is False
    assert data["monitor_boundaries"]["docker_build_allowed"] is False
    assert data["monitor_boundaries"]["telegram_send_allowed"] is False
    assert data["monitor_boundaries"]["production_write_allowed"] is False
    assert data["telegram_policy"]["direct_send_allowed"] is False
    assert any(
        candidate["candidate_id"] == "api_python_manifest_drift"
        for candidate in data["drift_candidates"]
    )
    assert any(
        candidate["candidate_id"] == "agent_market_source_lookup_not_approved"
        for candidate in data["drift_candidates"]
    )
