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>
This commit is contained in:
@@ -3,6 +3,7 @@ Tests for household registry.
|
||||
|
||||
Tests capability registration, toolset scoping, and coordination features.
|
||||
"""
|
||||
|
||||
import pytest
|
||||
from pydantic_ai.tools import Tool
|
||||
|
||||
@@ -10,7 +11,6 @@ from src.core.household_registry import (
|
||||
HouseholdCapability,
|
||||
HouseholdMember,
|
||||
HouseholdRegistry,
|
||||
household_registry,
|
||||
)
|
||||
|
||||
|
||||
@@ -38,6 +38,7 @@ def sample_capability():
|
||||
@pytest.fixture
|
||||
def sample_tools():
|
||||
"""Sample tool definitions."""
|
||||
|
||||
def test_function_1(x: int) -> int:
|
||||
"""Test function 1."""
|
||||
return x * 2
|
||||
@@ -96,6 +97,7 @@ class TestHouseholdMember:
|
||||
def test_member_with_agent(self, sample_capability, sample_tools):
|
||||
"""Test member can include an agent."""
|
||||
from unittest.mock import Mock
|
||||
|
||||
mock_agent = Mock()
|
||||
|
||||
member = HouseholdMember(
|
||||
@@ -322,7 +324,9 @@ class TestGetDelegationTools:
|
||||
assert callable(tools[0])
|
||||
assert tools[0].__name__ == "delegate_to_librarian"
|
||||
|
||||
def test_delegation_tools_returns_raw_tools_for_member_without_agent(self, registry, sample_capability, sample_tools):
|
||||
def test_delegation_tools_returns_raw_tools_for_member_without_agent(
|
||||
self, registry, sample_capability, sample_tools
|
||||
):
|
||||
"""Test delegation tools returns raw tools when member has no agent."""
|
||||
registry.register("test_tools", sample_capability, sample_tools)
|
||||
|
||||
@@ -373,8 +377,8 @@ class TestGetDelegationTools:
|
||||
assert tools[0].__name__ == "delegate_to_librarian"
|
||||
|
||||
# Rest should be raw tools
|
||||
assert hasattr(tools[1], 'name')
|
||||
assert hasattr(tools[2], 'name')
|
||||
assert hasattr(tools[1], "name")
|
||||
assert hasattr(tools[2], "name")
|
||||
|
||||
def test_delegation_tools_nonexistent_member(self, registry):
|
||||
"""Test delegation tools handles non-existent member gracefully."""
|
||||
|
||||
@@ -3,12 +3,11 @@ Tests for structured logging configuration.
|
||||
|
||||
Tests logging setup, context management, and FastAPI integration.
|
||||
"""
|
||||
|
||||
import logging
|
||||
from io import StringIO
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
import structlog
|
||||
|
||||
from src.core.logging_config import (
|
||||
add_log_level,
|
||||
@@ -50,10 +49,10 @@ class TestGetLogger:
|
||||
"""Test get_logger returns structlog BoundLogger."""
|
||||
logger = get_logger("test")
|
||||
# Logger should have standard logging methods
|
||||
assert hasattr(logger, 'info')
|
||||
assert hasattr(logger, 'debug')
|
||||
assert hasattr(logger, 'warning')
|
||||
assert hasattr(logger, 'error')
|
||||
assert hasattr(logger, "info")
|
||||
assert hasattr(logger, "debug")
|
||||
assert hasattr(logger, "warning")
|
||||
assert hasattr(logger, "error")
|
||||
|
||||
def test_get_logger_with_module_name(self):
|
||||
"""Test logger with module name."""
|
||||
|
||||
@@ -2,13 +2,14 @@
|
||||
Tests for the memory service (direct access layer).
|
||||
"""
|
||||
|
||||
from unittest.mock import AsyncMock, patch
|
||||
|
||||
import pytest
|
||||
from unittest.mock import MagicMock, patch, AsyncMock
|
||||
|
||||
from src.core.memory_service import (
|
||||
MemoryRecord,
|
||||
MemoryService,
|
||||
MemoryType,
|
||||
MemoryRecord,
|
||||
memory_service,
|
||||
)
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
"""
|
||||
Tests for core router (health check and root endpoints).
|
||||
"""
|
||||
|
||||
import pytest
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
@@ -11,7 +12,7 @@ from src.core.config import config
|
||||
def test_health_check(client: TestClient) -> None:
|
||||
"""Test health check endpoint returns healthy status."""
|
||||
response = client.get("/health")
|
||||
|
||||
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert data["status"] == "healthy"
|
||||
@@ -22,7 +23,7 @@ def test_health_check(client: TestClient) -> None:
|
||||
def test_root_endpoint(client: TestClient) -> None:
|
||||
"""Test root endpoint returns API information."""
|
||||
response = client.get("/")
|
||||
|
||||
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert data["name"] == config.APP_NAME
|
||||
@@ -42,7 +43,7 @@ def test_openapi_schema(client: TestClient) -> None:
|
||||
"""Test that OpenAPI schema is accessible."""
|
||||
response = client.get("/openapi.json")
|
||||
assert response.status_code == 200
|
||||
|
||||
|
||||
schema = response.json()
|
||||
assert schema["info"]["title"] == config.APP_NAME
|
||||
assert schema["info"]["version"] == config.APP_VERSION
|
||||
|
||||
@@ -157,9 +157,7 @@ class TestRequestContextGuard:
|
||||
"jpmschweitzer!",
|
||||
],
|
||||
)
|
||||
@pytest.mark.parametrize(
|
||||
"environment", [Environment.DEVELOPMENT, Environment.TESTING]
|
||||
)
|
||||
@pytest.mark.parametrize("environment", [Environment.DEVELOPMENT, Environment.TESTING])
|
||||
def test_production_tenant_sanitization_variants_are_forced(
|
||||
self, monkeypatch, environment, variant
|
||||
):
|
||||
@@ -175,9 +173,8 @@ class TestRequestContextGuard:
|
||||
with RequestContext(user=variant):
|
||||
effective = get_user()
|
||||
assert effective == TEST_TENANT
|
||||
assert (
|
||||
get_memory_collection_name(effective)
|
||||
!= get_memory_collection_name(PRODUCTION_TENANT)
|
||||
assert get_memory_collection_name(effective) != get_memory_collection_name(
|
||||
PRODUCTION_TENANT
|
||||
)
|
||||
|
||||
def test_dev_non_colliding_user_is_not_forced(self, monkeypatch):
|
||||
@@ -228,10 +225,7 @@ class TestSuiteRunsUnderTestTenant:
|
||||
from src.core.context import get_default_user
|
||||
from src.core.multi_tenancy import get_memory_collection_name
|
||||
|
||||
assert (
|
||||
get_memory_collection_name(get_default_user())
|
||||
== f"memories_{TEST_TENANT}"
|
||||
)
|
||||
assert get_memory_collection_name(get_default_user()) == f"memories_{TEST_TENANT}"
|
||||
|
||||
def test_redis_session_namespace_is_test_tenant(self):
|
||||
from src.core.context import get_default_user
|
||||
|
||||
@@ -3,6 +3,7 @@ Tests for tool call tracking.
|
||||
|
||||
Tests capability extraction and recommendation matching.
|
||||
"""
|
||||
|
||||
import pytest
|
||||
|
||||
from src.core.tool_tracking import ToolCallTracker
|
||||
@@ -29,9 +30,7 @@ class TestToolCallTracker:
|
||||
@pytest.mark.asyncio
|
||||
async def test_track_call_recognizes_delegation_as_recommended(self):
|
||||
"""Test that delegate_to_X is recognized when X is recommended."""
|
||||
tracker = ToolCallTracker(
|
||||
recommended_capabilities=["librarian", "biographer"]
|
||||
)
|
||||
tracker = ToolCallTracker(recommended_capabilities=["librarian", "biographer"])
|
||||
|
||||
await tracker.track_call("delegate_to_librarian", 1.0)
|
||||
|
||||
@@ -42,9 +41,7 @@ class TestToolCallTracker:
|
||||
@pytest.mark.asyncio
|
||||
async def test_track_call_detects_not_recommended(self):
|
||||
"""Test that unrecommended tools are flagged."""
|
||||
tracker = ToolCallTracker(
|
||||
recommended_capabilities=["librarian"]
|
||||
)
|
||||
tracker = ToolCallTracker(recommended_capabilities=["librarian"])
|
||||
|
||||
await tracker.track_call("delegate_to_housekeeper", 1.0)
|
||||
|
||||
@@ -55,9 +52,7 @@ class TestToolCallTracker:
|
||||
|
||||
def test_get_summary_with_delegation_tools(self):
|
||||
"""Test summary correctly maps delegation tools to capabilities."""
|
||||
tracker = ToolCallTracker(
|
||||
recommended_capabilities=["librarian", "biographer"]
|
||||
)
|
||||
tracker = ToolCallTracker(recommended_capabilities=["librarian", "biographer"])
|
||||
tracker.actual_calls = {
|
||||
"delegate_to_librarian": [1.0, 2.0],
|
||||
"delegate_to_housekeeper": [0.5], # Not recommended
|
||||
@@ -72,9 +67,7 @@ class TestToolCallTracker:
|
||||
@pytest.mark.asyncio
|
||||
async def test_finalize_with_delegation_tools(self):
|
||||
"""Test finalize correctly identifies unused recommendations."""
|
||||
tracker = ToolCallTracker(
|
||||
recommended_capabilities=["librarian", "biographer"]
|
||||
)
|
||||
tracker = ToolCallTracker(recommended_capabilities=["librarian", "biographer"])
|
||||
tracker.actual_calls = {
|
||||
"delegate_to_librarian": [1.0],
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user