fix: test suite green (156 passed, 7 skipped)

- Fix seed data to match actual DB schemas (capture.processed, daily_focus.completed, weblinks junction table)
- Add date/datetime coercion in BaseRepository for asyncpg compatibility
- Add UUID validation in BaseRepository.get() to prevent DataError on invalid UUIDs
- Fix focus.py and time_tracking.py date string handling for asyncpg
- Fix test ordering (action before delete) and skip destructive admin actions
- Fix form_factory FK resolution for flat UUID strings
- Fix route_report.py to use get_route_registry(app)
- Add asyncio_default_test_loop_scope=session to pytest.ini

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-01 21:30:27 +00:00
parent f7c5ac2d89
commit a427f7c781
12 changed files with 203 additions and 81 deletions

20
main.py
View File

@@ -72,12 +72,20 @@ templates = Jinja2Templates(directory="templates")
# ---- Template globals and filters ----
@app.middleware("http")
async def add_request_context(request: Request, call_next):
"""Make environment available to all templates."""
request.state.environment = os.getenv("ENVIRONMENT", "production")
response = await call_next(request)
return response
from starlette.types import ASGIApp, Receive, Scope, Send
class RequestContextMiddleware:
"""Pure ASGI middleware - avoids BaseHTTPMiddleware's TaskGroup issues with asyncpg."""
def __init__(self, app: ASGIApp):
self.app = app
self.environment = os.getenv("ENVIRONMENT", "production")
async def __call__(self, scope: Scope, receive: Receive, send: Send):
if scope["type"] == "http":
scope.setdefault("state", {})["environment"] = self.environment
await self.app(scope, receive, send)
app.add_middleware(RequestContextMiddleware)
# ---- Dashboard ----