import pytest from aiatlas.connectors.code.github import GitHubConnector, entity_type_for, repo_entries from aiatlas.connectors.code.pypi import PyPIConnector, _license, _norm from aiatlas.ontology.taxonomy import FRAMEWORK_KINDS from aiatlas.registry import organizations from aiatlas.sdk.facts import Target from tests.conftest import claims_of, extract_from_fixture, fixture_path def test_repositories_registry(): entries = repo_entries() assert len(entries) >= 70 and len({e["key"] for e in entries}) == len(entries) assert all((e["kind"] == "model" or e["kind"] in FRAMEWORK_KINDS) and e["repo"].count("/") == 1 for e in entries) # canonical kinds assert all(e["organization"] in organizations() for e in entries if e.get("organization")) agents = [e for e in entries if e["kind"] == "agent"] assert {e["key"] for e in agents} == {"claude-code", "codex", "gemini-cli", "openhands", "aider", "browser-use"} assert all(e.get("agent_kind") in ("coding", "browser", "research") for e in agents) assert entity_type_for("agent") == "agent" and entity_type_for("application") == "tool" and entity_type_for("mcp-server") == "tool" assert entity_type_for("model") == "repository" and entity_type_for("inference-engine") == "framework" and entity_type_for("library") == "framework" tools = [e["key"] for e in entries if entity_type_for(e["kind"]) == "tool"] assert {"comfyui", "lms", "text-generation-webui", "stable-diffusion-webui", "mcp-servers"} <= set(tools) @pytest.fixture def gh() -> GitHubConnector: return GitHubConnector() async def test_github_discover(gh): targets = await gh.discover(None) # type: ignore[arg-type] assert len(targets) == 3 * len(repo_entries()) assert {t.doc_type for t in targets} == {"repository", "feed", "readme"} and gh.rate_per_min == 20 async def test_github_repo_page(gh): target = Target(url="https://github.com/vllm-project/vllm", doc_type="repository", key="repo:vllm-project/vllm", meta={"repo": "vllm-project/vllm"}) facts = await extract_from_fixture(gh, target, fixture_path("github", "repo-vllm.html")) vllm = next(e for e in facts.entities if e.entity_type == "framework") assert vllm.identifiers == {"github_repo": "vllm-project/vllm", "pypi": "vllm"} and vllm.organization.name == "vLLM project" c = claims_of(facts, "vllm") assert c["metric.stars"] == 91512 and c["metric.forks"] == 22070 and c["license"] == "Apache-2.0" and c["metric.releases"] == 105 assert c["kind"] == "inference-engine" and "kind_raw" not in c and "license_raw" not in c # already canonical in the seed / SPDX assert c["description"].startswith("A high-throughput") and c["homepage"] == "https://vllm.ai" and "llm-serving" in c["topics"] assert c["created_at"] == "2023-02-09T11:23:20+00:00" and "language" not in c # language bar is client-rendered async def test_github_releases(gh): target = Target(url="https://github.com/vllm-project/vllm/releases.atom", doc_type="feed", key="releases:vllm-project/vllm", meta={"repo": "vllm-project/vllm"}) facts = await extract_from_fixture(gh, target, fixture_path("github", "releases-vllm.atom"), content_type="application/atom+xml") c = claims_of(facts, "vllm") assert c["latest_version"] == "0.29.0" and c["latest_release_tag"] == "v0.29.0" and c["latest_release_at"].startswith("2026-09-10") events = [e for e in facts.events if e.event_type == "RELEASE"] assert len(events) == 10 and events[0].dedupe_key == "RELEASE:https://github.com/vllm-project/vllm/releases/tag/proto-v0.1.0" assert all(e.effective_at is not None for e in events) async def test_github_readme(gh): target = Target(url="https://raw.githubusercontent.com/vllm-project/vllm/HEAD/README.md", doc_type="readme", key="readme:vllm-project/vllm", meta={"repo": "vllm-project/vllm"}) facts = await extract_from_fixture(gh, target, fixture_path("github", "readme-vllm.md"), content_type="text/markdown") assert facts.document_entity is not None and facts.document_entity.identifiers["github_repo"] == "vllm-project/vllm" async def test_pypi_package(): c = PyPIConnector() assert len(c.packages()) >= 100 and "vllm" in c.packages() and c.packages()["vllm"]["repo"] == "vllm-project/vllm" target = Target(url="https://pypi.org/pypi/vllm/json", doc_type="package", key="pkg:vllm", meta={"pypi": "vllm"}) facts = await extract_from_fixture(c, target, fixture_path("pypi", "vllm.json"), content_type="application/json") ent = next(e for e in facts.entities if e.entity_type == "framework") assert ent.identifiers == {"github_repo": "vllm-project/vllm", "pypi": "vllm"} # merges with the GitHub entity cl = claims_of(facts, "vllm") assert cl["pypi_version"] == "0.29.0" and cl["pypi_release_at"] == "2026-09-09T08:58:32+00:00" and cl["pypi_license"] == "Apache-2.0" assert "license" not in cl and "homepage" not in cl # owned by the GitHub page for mapped repos assert cl["requires_python"] == "<3.15,>=3.10" and cl["metric.releases"] == 97 and cl["docs_url"] == "https://docs.vllm.ai/en/latest/" assert "latest_version" not in cl # owned by the GitHub release feed for mapped repos def test_pypi_helpers(): assert _norm("Llama_CPP.python") == "llama-cpp-python" assert _license({"license_expression": "MIT"}) == "MIT" assert _license({"license": "", "classifiers": ["License :: OSI Approved :: Apache Software License"]}) == "Apache Software License"