from __future__ import annotations

import json

from fastapi import FastAPI
from fastapi.testclient import TestClient

from src.api.v1.agents import router


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

    response = client.get("/api/v1/agents/agent-gitea-pr-draft-lane")

    assert response.status_code == 200
    data = response.json()
    assert data["schema_version"] == "ai_agent_gitea_pr_draft_lane_v1"
    assert data["program_status"]["overall_completion_percent"] == 78
    assert data["program_status"]["current_task_id"] == "P2-402E"
    assert data["program_status"]["next_task_id"] == "P2-402F"
    assert data["program_status"]["read_only_mode"] is True
    assert data["branch_strategy"]["branch_push_allowed"] is False
    assert data["branch_strategy"]["pr_creation_allowed"] is False
    assert data["branch_strategy"]["automerge"] is False
    assert data["operation_boundaries"]["gitea_branch_push_allowed"] is False
    assert data["operation_boundaries"]["gitea_pr_creation_allowed"] is False
    assert data["operation_boundaries"]["workflow_trigger_allowed"] is False
    assert data["operation_boundaries"]["lockfile_write_allowed"] is False
    assert data["operation_boundaries"]["telegram_direct_send_allowed"] is False
    assert data["operation_boundaries"]["conversation_transcript_allowed"] is False
    assert data["approval_boundaries"]["gitea_pr_creation_approved"] is False
    assert data["rollups"]["grouping_rule_count"] == 6
    assert data["rollups"]["lane_step_count"] == 7
    assert data["rollups"]["required_check_count"] == 9
    assert data["rollups"]["draft_template_count"] == 4
    assert data["rollups"]["gitea_pr_creation_allowed_count"] == 0
    assert data["rollups"]["auto_merge_allowed_count"] == 0
    assert data["rollups"]["workflow_trigger_allowed_count"] == 0

    serialized = json.dumps(data, ensure_ascii=False)
    for marker in [
        "批准！繼續",
        "My request for Codex",
        "Current URL:",
        "# In app browser",
        "AGENTS.md instructions",
    ]:
        assert marker not in serialized
