from __future__ import annotations

from src.services.agent_market_discovery_classifier import (
    run_agent_market_discovery_classification,
)


def test_discovery_classifier_recommends_framework_and_governance_watch_entries():
    report = run_agent_market_discovery_classification(
        discovery_review=_discovery_review(),
        repository_metadata={
            "framerslab/agentos": {
                "html_url": "https://github.com/framerslab/agentos",
                "description": "TypeScript AI agent framework with multi-agent orchestration.",
                "topics": ["agent-framework", "multi-agent", "guardrails"],
                "language": "TypeScript",
                "stargazers_count": 568,
                "pushed_at": "2026-06-04T00:57:43Z",
            },
            "microsoft/agent-governance-toolkit": {
                "html_url": "https://github.com/microsoft/agent-governance-toolkit",
                "description": "AI Agent Governance Toolkit with policy enforcement and OWASP controls.",
                "topics": ["agent-framework", "governance", "owasp"],
                "language": "Python",
                "stargazers_count": 3925,
                "pushed_at": "2026-06-03T23:36:16Z",
            },
        },
        generated_at="2026-06-04T00:00:00+00:00",
    )

    assert report["policy"]["auto_watch_registry_addition_approved"] is False
    assert report["summary"]["recommended_watch_additions"] == 2
    by_repo = {candidate["repository_full_name"]: candidate for candidate in report["candidates"]}
    assert by_repo["framerslab/agentos"]["classification"] == "agent_framework_candidate"
    assert by_repo["microsoft/agent-governance-toolkit"]["classification"] == (
        "agent_governance_candidate"
    )
    assert by_repo["framerslab/agentos"]["approval_boundary"]["approved_for_replay"] is False


def test_discovery_classifier_defers_vertical_and_watch_only_ui_products():
    report = run_agent_market_discovery_classification(
        discovery_review=_discovery_review(
            ["hugohe3/ppt-master", "ekkolearnai/hermes-web-ui"]
        ),
        repository_metadata={
            "hugohe3/ppt-master": {
                "html_url": "https://github.com/hugohe3/ppt-master",
                "description": "AI generates editable PowerPoint presentations.",
                "topics": ["ai-agent", "powerpoint", "pptx", "slides"],
                "language": "Python",
                "stargazers_count": 24106,
            },
            "ekkolearnai/hermes-web-ui": {
                "html_url": "https://github.com/EKKOLearnAI/hermes-web-ui",
                "description": "Web dashboard for Hermes Agent with session management.",
                "topics": ["web-ui", "dashboard", "hermes-agent"],
                "language": "TypeScript",
                "stargazers_count": 7177,
            },
        },
        generated_at="2026-06-04T00:00:00+00:00",
    )

    by_repo = {candidate["repository_full_name"]: candidate for candidate in report["candidates"]}
    assert by_repo["hugohe3/ppt-master"]["recommendation"] == "defer_not_core_agent_framework"
    assert by_repo["ekkolearnai/hermes-web-ui"]["recommendation"] == (
        "watch_only_product_surface_signal"
    )
    assert report["summary"]["recommended_watch_additions"] == 0


def _discovery_review(repositories: list[str] | None = None) -> dict:
    repositories = repositories or ["framerslab/agentos", "microsoft/agent-governance-toolkit"]
    return {
        "schema_version": "agent_market_discovery_review_v1",
        "generated_at": "2026-06-04T00:00:00+00:00",
        "candidate_drafts": [
            {
                "repository_full_name": repo,
                "html_url": f"https://github.com/{repo}",
                "status": "needs_primary_source_classification",
                "stargazers_count_max": 1,
            }
            for repo in repositories
        ],
    }
