from __future__ import annotations

from fastapi import FastAPI
from fastapi.testclient import TestClient

from src.api.v1.agents import router


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

    response = client.get(
        "/api/v1/agents/gitea-workflow-runner-owner-attestation-request"
    )

    assert response.status_code == 200
    data = response.json()
    assert (
        data["schema_version"]
        == "gitea_workflow_runner_owner_attestation_request_v1"
    )
    assert data["priority"] == "P1-002"
    assert data["status"] == "owner_attestation_request_ready_waiting_response"
    assert data["readback"]["contract_id"] == "ubuntu_latest_gitea_runner_label"
    assert data["readback"]["runner_label"] == "ubuntu-latest"
    assert data["request_packet"]["request_template_ready"] is True
    assert data["request_packet"]["request_sent"] is False
    assert data["request_packet"]["owner_response_received"] is False
    assert data["request_packet"]["owner_response_accepted"] is False
    assert (
        len(data["request_packet"]["workflow_ids_requiring_attestation"])
        == data["rollups"]["workflow_requiring_attestation_count"]
        == 8
    )
    assert data["rollups"]["required_owner_field_count"] >= 10
    assert data["rollups"]["owner_response_received_count"] == 0
    assert data["rollups"]["owner_response_accepted_count"] == 0
    assert "owner_attestation_response_not_received" in data["active_blockers"]

    boundaries = data["operation_boundaries"]
    assert boundaries["read_only_api_allowed"] is True
    assert boundaries["request_send_performed"] is False
    assert boundaries["workflow_modification_allowed"] is False
    assert boundaries["workflow_trigger_allowed"] is False
    assert boundaries["runner_label_change_allowed"] is False
    assert boundaries["runner_registration_allowed"] is False
    assert boundaries["runner_restart_allowed"] is False
    assert boundaries["secret_read_allowed"] is False
    assert boundaries["runner_token_read_allowed"] is False
    assert boundaries["gitea_api_write_allowed"] is False
    assert boundaries["github_api_used"] is False
