Files
agentforge/tests/unit/test_api_agents.py
T

71 lines
2.2 KiB
Python

"""Tests del router /agents (list, get, versions, get_version, diff)."""
from pathlib import Path
import pytest
from fastapi.testclient import TestClient
from agentforge_core.api import deps
from agentforge_core.main import create_app
FIXTURES = Path(__file__).parent.parent / "fixtures"
@pytest.fixture(autouse=True)
def patch_settings(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setenv("DATA_DIR", str(tmp_path))
monkeypatch.setenv("AGENTS_DIR", str(FIXTURES / "agents"))
monkeypatch.setenv("POLICIES_DIR", str(FIXTURES / "policies"))
for fn in (
deps.get_settings,
deps.get_registry,
deps.get_policy_store,
deps.get_orchestrator,
deps.get_llm_provider,
deps.get_guardrail_engine,
):
fn.cache_clear()
def test_list_agents_incluye_incident_analyzer() -> None:
r = TestClient(create_app()).get("/agents")
assert r.status_code == 200
assert any(a["name"] == "incident_analyzer" for a in r.json())
def test_get_agent_activo_devuelve_v1() -> None:
r = TestClient(create_app()).get("/agents/incident_analyzer")
assert r.status_code == 200
assert r.json()["version"] == "v1"
def test_get_agent_inexistente_404() -> None:
r = TestClient(create_app()).get("/agents/inexistente")
assert r.status_code == 404
def test_list_versions_devuelve_meta() -> None:
r = TestClient(create_app()).get("/agents/incident_analyzer/versions")
assert r.status_code == 200
assert r.json()[0]["id"] == "v1"
def test_get_version_concreta() -> None:
r = TestClient(create_app()).get("/agents/incident_analyzer/versions/v1")
assert r.status_code == 200
assert r.json()["name"] == "incident_analyzer"
def test_get_version_inexistente_404() -> None:
r = TestClient(create_app()).get("/agents/incident_analyzer/versions/v999")
assert r.status_code == 404
def test_diff_misma_version_da_diff_vacio() -> None:
r = TestClient(create_app()).get("/agents/incident_analyzer/versions/v1/diff/v1")
assert r.status_code == 200
body = r.json()
assert body["from_version"] == "v1"
assert body["to_version"] == "v1"
assert body["unified_diff"] == ""