from __future__ import annotations

from fastapi import FastAPI
from fastapi.testclient import TestClient

from src.api.v1.agents import router


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

    response = client.get("/api/v1/agents/dependency-drift-check-plan")

    assert response.status_code == 200
    data = response.json()
    assert data["schema_version"] == "dependency_drift_check_plan_v1"
    assert data["program_status"]["overall_completion_percent"] == 99
    assert data["program_status"]["read_only_mode"] is True
    assert data["program_status"]["current_task_id"] == "P1-205"
    assert data["program_status"]["next_task_id"] == "P1-206"
    assert data["rollups"]["total_cadence_items"] == len(data["cadence_policy"]["items"]) == 5
    assert data["rollups"]["total_local_checks"] == len(data["local_check_plan"]) == 5
    assert data["rollups"]["total_external_source_candidates"] == len(data["external_source_candidates"]) == 10
    assert data["operation_boundaries"]["read_only_plan_allowed"] is True
    assert data["operation_boundaries"]["schedule_activation_allowed"] is False
    assert data["operation_boundaries"]["workflow_write_allowed"] is False
    assert data["operation_boundaries"]["external_cve_lookup_allowed"] is False
    assert data["operation_boundaries"]["external_license_lookup_allowed"] is False
    assert data["operation_boundaries"]["agent_market_external_lookup_allowed"] is False
    assert data["operation_boundaries"]["package_upgrade_allowed"] is False
    assert data["operation_boundaries"]["docker_build_allowed"] is False
    assert data["operation_boundaries"]["paid_api_call_allowed"] is False
    assert data["approval_boundaries"]["shadow_or_canary_allowed"] is False
    assert any(check["check_id"] == "javascript_lockfile_drift_local_check" for check in data["local_check_plan"])
    assert any(source["source_id"] == "agent_official_release_candidate" for source in data["external_source_candidates"])
    assert any(item["cadence_id"] == "weekly_agent_market_watch_review" for item in data["cadence_policy"]["items"])
