Files
larry/tests/unit/test_domain_agent.py
T

71 lines
1.9 KiB
Python

"""Tests unitarios para los modelos de dominio del agente."""
from datetime import UTC, datetime
import pytest
from pydantic import ValidationError
from agentforge_core.domain.agent import (
AgentDefinition,
AgentVersionMeta,
LLMConfig,
)
def test_llm_config_default_provider_is_mock() -> None:
cfg = LLMConfig()
assert cfg.provider == "mock"
assert cfg.model == "gpt-4o"
assert cfg.temperature == 0.2
def test_llm_config_rechaza_provider_invalido() -> None:
with pytest.raises(ValidationError):
LLMConfig(provider="bedrock") # type: ignore[arg-type]
def test_agent_version_meta_serialize() -> None:
meta = AgentVersionMeta(
id="v1",
hash="abc123",
author="Juan",
message="inicial",
created_at=datetime(2026, 5, 9, tzinfo=UTC),
)
dumped = meta.model_dump(mode="json")
assert dumped["id"] == "v1"
assert dumped["created_at"].startswith("2026-05-09")
def test_agent_definition_minimo_valido() -> None:
agent = AgentDefinition(
name="incident_analyzer",
version="v1",
owner="Juan",
purpose="Análisis de incidentes",
state="active",
guardrails=["default"],
llm=LLMConfig(),
system_prompt="eres un analista...",
output_schema={"type": "object"},
updated_at=datetime.now(UTC),
)
assert agent.risk_threshold_for_hitl == 4 # default
assert agent.state == "active"
def test_agent_definition_rechaza_state_invalido() -> None:
with pytest.raises(ValidationError):
AgentDefinition(
name="x",
version="v1",
owner="x",
purpose="x",
state="archived", # type: ignore[arg-type]
guardrails=[],
llm=LLMConfig(),
system_prompt="x",
output_schema={},
updated_at=datetime.now(UTC),
)