Protocol tests (16): - AgentRequest/AgentResponse serialization - DelegationIntent and DelegationReason validation - CoordinationResult aggregation - Error type tests Coordination tests (14): - Engine initialization and agent availability - Delegation execution (success, error, timeout) - Multi-intent coordination - Streaming delegation Librarian tests (42): - Library-desk client (all endpoints) - Wiki operations (search, get, create, update) - Smart-create with HybridRAG - Capability registration - Response model validation Total: 72 new tests, all passing 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
127 lines
4.1 KiB
Python
127 lines
4.1 KiB
Python
"""
|
|
Tests for Librarian capability registration.
|
|
"""
|
|
|
|
import pytest
|
|
from unittest.mock import MagicMock, patch
|
|
|
|
from src.agents.librarian.capability import (
|
|
LIBRARIAN_CAPABILITY,
|
|
get_librarian_capability,
|
|
register_librarian,
|
|
unregister_librarian,
|
|
)
|
|
from src.core.household_registry import HouseholdCapability
|
|
|
|
|
|
@pytest.mark.unit
|
|
class TestLibrarianCapability:
|
|
"""Tests for the Librarian capability definition."""
|
|
|
|
def test_capability_is_household_capability(self):
|
|
"""Test capability is correct type."""
|
|
assert isinstance(LIBRARIAN_CAPABILITY, HouseholdCapability)
|
|
|
|
def test_capability_name(self):
|
|
"""Test capability has correct name."""
|
|
assert LIBRARIAN_CAPABILITY.name == "librarian"
|
|
|
|
def test_capability_role(self):
|
|
"""Test capability has correct role."""
|
|
assert LIBRARIAN_CAPABILITY.role == "The Librarian"
|
|
|
|
def test_capability_category(self):
|
|
"""Test capability is in research category."""
|
|
assert LIBRARIAN_CAPABILITY.category == "research"
|
|
|
|
def test_capability_domains(self):
|
|
"""Test capability covers expected domains."""
|
|
domains = LIBRARIAN_CAPABILITY.domains
|
|
|
|
assert "research" in domains
|
|
assert "knowledge" in domains
|
|
assert "wiki" in domains
|
|
assert "search" in domains
|
|
|
|
def test_capability_requires_network(self):
|
|
"""Test capability requires network access."""
|
|
assert LIBRARIAN_CAPABILITY.requires_network is True
|
|
|
|
def test_get_librarian_capability(self):
|
|
"""Test getter returns same capability."""
|
|
cap = get_librarian_capability()
|
|
|
|
assert cap is LIBRARIAN_CAPABILITY
|
|
|
|
|
|
@pytest.mark.unit
|
|
class TestLibrarianRegistration:
|
|
"""Tests for Librarian registration functions."""
|
|
|
|
def test_register_librarian(self):
|
|
"""Test registering librarian with registry."""
|
|
mock_registry = MagicMock()
|
|
mock_registry.__contains__ = MagicMock(return_value=False)
|
|
|
|
with patch(
|
|
"src.agents.librarian.capability.get_household_registry",
|
|
return_value=mock_registry,
|
|
):
|
|
with patch(
|
|
"src.agents.librarian.capability.get_librarian_agent"
|
|
) as mock_get_agent:
|
|
mock_agent = MagicMock()
|
|
mock_get_agent.return_value = mock_agent
|
|
|
|
register_librarian()
|
|
|
|
mock_registry.register.assert_called_once()
|
|
call_kwargs = mock_registry.register.call_args[1]
|
|
|
|
assert call_kwargs["name"] == "librarian"
|
|
assert call_kwargs["capability"] is LIBRARIAN_CAPABILITY
|
|
assert call_kwargs["agent"] is mock_agent
|
|
|
|
def test_register_librarian_already_registered(self):
|
|
"""Test registering when already registered does nothing."""
|
|
mock_registry = MagicMock()
|
|
mock_registry.__contains__ = MagicMock(return_value=True)
|
|
|
|
with patch(
|
|
"src.agents.librarian.capability.get_household_registry",
|
|
return_value=mock_registry,
|
|
):
|
|
register_librarian()
|
|
|
|
# Should not call register since already registered
|
|
mock_registry.register.assert_not_called()
|
|
|
|
def test_unregister_librarian(self):
|
|
"""Test unregistering librarian from registry."""
|
|
mock_registry = MagicMock()
|
|
|
|
with patch(
|
|
"src.agents.librarian.capability.get_household_registry",
|
|
return_value=mock_registry,
|
|
):
|
|
unregister_librarian()
|
|
|
|
mock_registry.unregister.assert_called_once_with("librarian")
|
|
|
|
|
|
@pytest.mark.unit
|
|
class TestCapabilityDescription:
|
|
"""Tests for capability description."""
|
|
|
|
def test_description_mentions_library_desk(self):
|
|
"""Test description mentions library-desk API."""
|
|
assert "library-desk" in LIBRARIAN_CAPABILITY.description.lower()
|
|
|
|
def test_description_mentions_search(self):
|
|
"""Test description mentions search capability."""
|
|
assert "search" in LIBRARIAN_CAPABILITY.description.lower()
|
|
|
|
def test_description_mentions_wiki(self):
|
|
"""Test description mentions wiki access."""
|
|
assert "wiki" in LIBRARIAN_CAPABILITY.description.lower()
|