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:
2026-08-11 17:25:18 +02:00
co-authored by Claude
parent 57fa6c13fc
commit 78066fab1b
103 changed files with 1601 additions and 1749 deletions
+15 -18
View File
@@ -8,6 +8,7 @@ Tests:
- Router registration
- Exception handlers
"""
import pytest
from fastapi import FastAPI
from fastapi.testclient import TestClient
@@ -56,8 +57,9 @@ def test_cors_middleware():
# Better check: verify CORS functionality by checking middleware stack
# The middleware should be present (wrapped as Middleware)
middleware_types = [type(m.cls).__name__ if hasattr(m, 'cls') else type(m).__name__
for m in app.user_middleware]
middleware_types = [
type(m.cls).__name__ if hasattr(m, "cls") else type(m).__name__ for m in app.user_middleware
]
assert "CORSMiddleware" in middleware_types or len(app.user_middleware) > 0
@@ -67,10 +69,7 @@ def test_cors_allows_all_origins(client: TestClient):
# Make OPTIONS request with Origin header
response = client.options(
"/v1/models",
headers={
"Origin": "http://example.com",
"Access-Control-Request-Method": "GET"
}
headers={"Origin": "http://example.com", "Access-Control-Request-Method": "GET"},
)
# Should allow CORS
@@ -81,10 +80,7 @@ def test_cors_allows_all_origins(client: TestClient):
@pytest.mark.unit
def test_cors_allows_credentials(client: TestClient):
"""Test that CORS allows credentials."""
response = client.get(
"/health",
headers={"Origin": "http://example.com"}
)
response = client.get("/health", headers={"Origin": "http://example.com"})
# Should include CORS headers
assert response.status_code == 200
@@ -96,10 +92,11 @@ def test_cors_allows_credentials(client: TestClient):
@pytest.mark.unit
def test_exception_handlers_registered():
"""Test that custom exception handlers are registered."""
from src.main import app
from src.core.exceptions import AppException
from fastapi.exceptions import RequestValidationError
from src.core.exceptions import AppException
from src.main import app
# App should have exception handlers
assert len(app.exception_handlers) > 0
@@ -119,8 +116,8 @@ def test_model_not_found_exception_handler(client: TestClient):
json={
"model": "non-existent-model-xyz",
"input": [{"role": "user", "content": "test"}],
"stream": False
}
"stream": False,
},
)
assert response.status_code == 404
@@ -137,8 +134,8 @@ def test_app_exception_handler(client: TestClient):
json={
"model": "lorem-tester",
"input": [], # Empty input might cause issues
"temperature": 3.0 # Invalid temperature
}
"temperature": 3.0, # Invalid temperature
},
)
# Should return validation error
@@ -149,8 +146,8 @@ def test_app_exception_handler(client: TestClient):
@pytest.mark.asyncio
async def test_lifespan_startup():
"""Test lifespan startup event."""
from src.main import app
from contextlib import asynccontextmanager
# The lifespan context manager should be defined
assert hasattr(app.router, "lifespan_context")
@@ -238,7 +235,7 @@ def test_validation_error_handler(client: TestClient):
json={
# Missing "model" field
"messages": [{"role": "user", "content": "test"}]
}
},
)
assert response.status_code == 422