refactor(backend): select() and an inline now everywhere, held by a test

CLAUDE.md's canonical table names SQLAlchemy 2.0 select() and an inline
datetime.now(timezone.utc), and both had drifted: five db.query(...) calls
remained in routes/auth.py and routes/me.py (seven before the demo went),
and four private now helpers stood in sync/videos.py, utils.py (imported
as _now by explore and maintenance), scheduler.py (_now_iso) and the e2e
seed. All are the canonical form now.

Ruff cannot ban a method call on an instance or a function by name, so
tests/test_canonical_patterns.py reads every app module's AST and fails on
a .query(...) call or a now/_now/now_utc helper — seen red on a planted file.
This commit is contained in:
2026-10-05 00:19:39 +02:00
parent ab76166878
commit 24c47d12bd
10 changed files with 111 additions and 59 deletions
+7 -7
View File
@@ -45,10 +45,6 @@ if not PASSWORD:
N_SUBS = 3
def _now() -> datetime:
return datetime.now(timezone.utc)
def main() -> None:
db = SessionLocal()
try:
@@ -99,7 +95,11 @@ def main() -> None:
db.execute(delete(Subscription).where(Subscription.user_id == user.id))
for cid in channel_ids:
db.add(Subscription(user_id=user.id, channel_id=cid, subscribed_at=_now()))
db.add(
Subscription(
user_id=user.id, channel_id=cid, subscribed_at=datetime.now(timezone.utc)
)
)
db.commit()
# 3. Deterministic watch state (reset each run):
@@ -133,7 +133,7 @@ def main() -> None:
video_id=vid.id,
status="new",
position_seconds=42,
progress_updated_at=_now(),
progress_updated_at=datetime.now(timezone.utc),
)
)
in_progress = vid.id
@@ -146,7 +146,7 @@ def main() -> None:
user_id=user.id,
video_id=wv.id,
status="watched",
watched_at=_now(),
watched_at=datetime.now(timezone.utc),
)
)
watched = wv.id