Convert Tatlock from mock to real PydanticAI agent: - Connect to Ollama backend (mistral-nemo:latest) - British butler personality with research-oriented mindset - Lazy initialization pattern for better testability - Register permanent tools (calculator, date/time, search) - Streaming response support with reasoning output - Error handling for PydanticAI exceptions - Update registry tests for tools capability - Add integration test for streaming functionality
125 lines
3.6 KiB
Python
125 lines
3.6 KiB
Python
"""
|
|
Tests for model registry.
|
|
"""
|
|
|
|
import pytest
|
|
|
|
from src.agents.registry import ModelRegistry
|
|
from src.agents.lorem_tester import LoremTesterAgent
|
|
from src.agents.tatlock import TatlockAgent
|
|
from src.core.exceptions import ModelNotFoundError
|
|
|
|
|
|
@pytest.mark.unit
|
|
@pytest.mark.asyncio
|
|
async def test_list_models():
|
|
"""Test listing all available models."""
|
|
models = await ModelRegistry.list_models()
|
|
|
|
# Should have both models
|
|
assert len(models) == 2
|
|
|
|
# Check model IDs
|
|
model_ids = [m["id"] for m in models]
|
|
assert "lorem-tester" in model_ids
|
|
assert "Tatlock" in model_ids
|
|
|
|
# Check structure
|
|
for model in models:
|
|
assert "id" in model
|
|
assert "object" in model
|
|
assert model["object"] == "model"
|
|
assert "created" in model
|
|
assert "owned_by" in model
|
|
assert "capabilities" in model
|
|
assert "description" in model
|
|
|
|
|
|
@pytest.mark.unit
|
|
@pytest.mark.asyncio
|
|
async def test_lorem_tester_capabilities():
|
|
"""Test lorem-tester model capabilities."""
|
|
models = await ModelRegistry.list_models()
|
|
lorem_model = next(m for m in models if m["id"] == "lorem-tester")
|
|
|
|
capabilities = lorem_model["capabilities"]
|
|
|
|
# Lorem Tester should have all features
|
|
assert capabilities["streaming"] is True
|
|
assert capabilities["reasoning"] is True
|
|
assert capabilities["tools"] is True
|
|
assert capabilities["vision"] is False
|
|
assert capabilities["audio"] is False
|
|
|
|
|
|
@pytest.mark.unit
|
|
@pytest.mark.asyncio
|
|
async def test_tatlock_capabilities():
|
|
"""Test tatlock model capabilities."""
|
|
models = await ModelRegistry.list_models()
|
|
tatlock_model = next(m for m in models if m["id"] == "Tatlock")
|
|
|
|
capabilities = tatlock_model["capabilities"]
|
|
|
|
# Tatlock Phase 1 - basic streaming, reasoning, and permanent tools
|
|
assert capabilities["streaming"] is True
|
|
assert capabilities["reasoning"] is True # Basic reasoning summaries
|
|
assert capabilities["tools"] is True # Permanent tools: calculator, date/time, search
|
|
assert capabilities["vision"] is False # Future
|
|
assert capabilities["audio"] is False # Future
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_get_agent_lorem_tester():
|
|
"""Test getting lorem-tester agent instance."""
|
|
agent = ModelRegistry.get_agent("lorem-tester")
|
|
|
|
assert isinstance(agent, LoremTesterAgent)
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_get_agent_tatlock():
|
|
"""Test getting tatlock agent instance."""
|
|
agent = ModelRegistry.get_agent("Tatlock")
|
|
|
|
assert isinstance(agent, TatlockAgent)
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_get_agent_not_found():
|
|
"""Test getting non-existent agent raises error."""
|
|
with pytest.raises(ModelNotFoundError) as exc_info:
|
|
ModelRegistry.get_agent("nonexistent-model")
|
|
|
|
assert "nonexistent-model" in str(exc_info.value)
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_model_exists():
|
|
"""Test checking if model exists."""
|
|
assert ModelRegistry.model_exists("lorem-tester") is True
|
|
assert ModelRegistry.model_exists("Tatlock") is True
|
|
assert ModelRegistry.model_exists("nonexistent") is False
|
|
|
|
|
|
@pytest.mark.unit
|
|
@pytest.mark.asyncio
|
|
async def test_get_model_info():
|
|
"""Test getting detailed model information."""
|
|
info = await ModelRegistry.get_model_info("lorem-tester")
|
|
|
|
assert info["id"] == "lorem-tester"
|
|
assert info["object"] == "model"
|
|
assert "created" in info
|
|
assert "owned_by" in info
|
|
assert "capabilities" in info
|
|
assert "description" in info
|
|
|
|
|
|
@pytest.mark.unit
|
|
@pytest.mark.asyncio
|
|
async def test_get_model_info_not_found():
|
|
"""Test getting info for non-existent model raises error."""
|
|
with pytest.raises(ModelNotFoundError):
|
|
await ModelRegistry.get_model_info("nonexistent-model")
|