fix(plex,audit): E30 review round 2 — only a missing file is a dead headshot, one spelling per portrait

- warm_portraits: only 404/410 mark a headshot dead (measured: Plex answers a dead CDN file 404);
  a refused token or a 5xx is Plex failing, ends the run after three in a row and marks nothing.
  'failed' counts every failure, not only the current streak.
- is_portrait_url: plain path segments only — no dot or empty segment an HTTP client folds onto
  one file; person_thumb_url uses the same predicate (27 852 stored headshots all pass).
- Tests: Plex refusing (401/403/429/5xx), failures between successes (portraits and bios), the kept
  original served from cache, the audit_clear / demo_reset / discovery_purge rows' counts as data,
  and the 0094 backfill on real rows.
This commit is contained in:
2026-10-01 08:31:03 +02:00
parent fa55e01ef0
commit 6ac9ffd45e
4 changed files with 141 additions and 23 deletions
+36
View File
@@ -0,0 +1,36 @@
"""E30: an admin action that counts something keeps the count as data in its audit row's `after`, under
the key the audit log names in the reader's language (`scheduler.result.<key>`, frontend
auditColumns.tsx) — not only in the English `summary`. A renamed key would fall back to the raw word.
DB lane (Postgres).
"""
from sqlalchemy import select
from app.models import AuditLog
def _after(db, action: str) -> dict:
db.expire_all()
return db.execute(select(AuditLog.after).where(AuditLog.action == action)).scalar_one()
def test_clearing_the_audit_log_keeps_the_count_as_data(as_user, db, make_user):
admin = make_user(email="boss@example.com", role="admin")
db.add_all([AuditLog(action="sync_pause"), AuditLog(action="sync_resume")])
db.commit()
assert as_user(admin).delete("/api/admin/audit").json()["cleared"] == 2
assert _after(db, "audit_clear") == {"cleared": 2}
def test_a_demo_reset_keeps_the_count_as_data(as_user, db, make_user):
admin = make_user(email="boss@example.com", role="admin")
seeded = as_user(admin).post("/api/admin/demo/reset").json()["playlists_seeded"]
assert _after(db, "demo_reset") == {"playlists_seeded": seeded}
def test_a_discovery_purge_keeps_its_counts_as_data(as_user, db, make_user):
admin = make_user(email="boss@example.com", role="admin")
body = as_user(admin).post("/api/admin/purge-discovery").json()
body.pop("ok")
assert _after(db, "discovery_purge") == body
assert {"videos_deleted", "channels_deleted", "search_videos_deleted"} <= set(body)