Refactor: split serve/server.py (3220 lines) into focused modules

serve/server.py is now 69 lines — app factory, middleware, and router
registration only.

New modules:
  deps.py    (168 lines) — module-level globals + auth dependency functions
  models.py   (85 lines) — all Pydantic request/response models
  tasks.py   (136 lines) — background workers and job tracker
  routers/               — one file per domain (10 routers, ~2750 lines total)
    auth.py, me.py, admin.py, activities.py, uploads.py,
    segments.py, strava.py, garmin.py, ideas.py, feed.py

cli.py updated to set globals on deps instead of server.

88 new regression tests in tests/serve/ cover auth guards and key
behaviours for every router; 294 total passing after the split.
This commit is contained in:
Davide Scaini
2026-05-13 23:47:19 +02:00
parent 2ec4d9157c
commit 8380b1d2cc
28 changed files with 3982 additions and 3193 deletions
+28
View File
@@ -0,0 +1,28 @@
"""Pre-split regression tests for feed, stats, and wheel routes."""
from __future__ import annotations
from fastapi.testclient import TestClient
class TestFeed:
def test_unauthenticated_returns_401(self, client: TestClient):
assert client.get("/api/feed").status_code == 401
def test_authenticated_returns_activities(self, user_client: TestClient):
r = user_client.get("/api/feed")
assert r.status_code == 200
assert "activities" in r.json()
class TestStats:
def test_public_returns_200(self, client: TestClient):
r = client.get("/api/stats")
assert r.status_code == 200
assert "user_count" in r.json()
class TestWheelVersion:
def test_public_returns_version(self, client: TestClient):
r = client.get("/api/wheel/version")
assert r.status_code == 200
assert "version" in r.json()