Files
jpmschweitzerandClaude 78066fab1b style: apply ruff's automatic fixes and formatter
Mechanical only, and separated from the judgment calls that follow so the
reviewable changes are not buried in a 98-file whitespace diff.

227 automatic fixes: 60 blank lines carrying whitespace, 60 unsorted import
blocks, 34 Optional[X] to X | None, 28 unused imports, 16 deprecated typing
imports, 12 datetime.timezone.utc to datetime.UTC, and assorted smaller
modernisations. Then `ruff format` over src and tests: 98 files reformatted,
35 already conforming.

No file among the unused-import findings defines __all__ or is an __init__.py,
so nothing here removes a re-export.

`make test`: 658 passed, unchanged from HEAD.

Two things observed while verifying, neither addressed here:

`pytest tests/` cannot collect — tests/e2e/test_orchestration_e2e.py uses an
`e2e` marker that is not registered, and the config is strict about markers.
This fails identically at HEAD, so it predates this change; `make test` passes
because it ignores tests/e2e, tests/integration and tests/contracts.

test_tatlock_tool_call_logging_calculator is flaky. It failed once in a full run
with these changes and passed on the next, passes in isolation with them, and
fails in isolation at HEAD. It is order- or timing-dependent, not a regression
from this commit — established by running the full suite both ways rather than
by reasoning about which change could have caused it.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-08-11 17:25:18 +02:00

129 lines
4.2 KiB
Python

"""
Tests for Librarian capability registration.
"""
from unittest.mock import MagicMock, patch
import pytest
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_wiki_capabilities(self):
"""Test description mentions wiki read/write capabilities."""
desc = LIBRARIAN_CAPABILITY.description.lower()
assert "create" in desc
assert "update" in desc
assert "search" in desc
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()