from __future__ import annotations

import json

from fastapi import FastAPI
from fastapi.testclient import TestClient

from src.api.v1.agents import router


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

    response = client.get("/api/v1/agents/ai-agent-market-radar-readback")

    assert response.status_code == 200
    data = response.json()
    assert data["schema_version"] == "ai_agent_market_radar_readback_v1"
    assert data["summary"]["overall_completion_percent"] == 42.2
    assert data["summary"]["market_candidates"] == 13
    assert data["summary"]["market_sources"] == 36
    assert data["summary"]["changed_candidates"] == 5
    assert data["summary"]["integration_blocked_candidates"] == 5
    assert data["summary"]["source_failures"] == 0
    assert data["summary"]["replacement_decisions_approved"] == 0
    assert data["policy"]["openclaw_replacement_approved"] is False
    assert data["policy"]["telegram_send_approved"] is False

    serialized = json.dumps(data, ensure_ascii=False)
    assert "/Users/" not in serialized
    assert ".claude/projects" not in serialized
    assert ".codex" not in serialized
    assert "192.168." not in serialized
