The code cited its plan instead of saying why: `E28 review J4`, `(R6 S3b)`, `S1 justified…`,
`deep-review round 5`. That plan lives in the private ops repo, so for every reader of this one the
citation was noise, and a sentence whose subject was the plan step ("round 2 showed…") hid its
lesson behind an id. Each one is gone and the "why" kept: a bare citation is deleted, a sentence
carrying a lesson is reworded around it ("a later attempt showed…").
Measured (`scripts/audit_metrics.py`, product code): 652 lines in 270 files carried an epic code by
the definition the next commit holds (507 / 241 by the old, two-digit-only one) -> 0. Across all
code, tests, scripts and configs: ~1100 epic-code lines plus ~320 sprint/round ids.
Behaviour unchanged, checked mechanically: every changed .py file has the same AST once docstrings
are blanked; css/sh/toml/yml/json files are identical once comments are stripped; the only
non-comment changes in TS/JS are test titles, one description string in a contract table, and five
ESLint messages, whose text is all the gates snapshot diff holds. Not touched: Markdown (docs and
the changelog keep their history), Alembic migrations, TV episode notation (`S2 · E5`), DESIGN.md
ids (`C1`, `B4`, `S3h`), tracker ids (`SEC-16`, `DX-17`).
One stale claim fixed on the way: test_hls_reaper's docstring said the player checkpoints "every
10 s whether or not it is playing", which plex/stream.py calls wrong; it now says what the code does.
78 lines
2.8 KiB
Python
78 lines
2.8 KiB
Python
"""A card asks the Plex image proxy for a small cut; a detail page keeps the full one.
|
||
|
||
Cards fetched the 400×600 poster for a ~144px picture and the 1280×720 backdrop for a ~212px shelf
|
||
picture. The `_sm` variants are cut by Plex at a card's size and cached apart from the full ones; an
|
||
unknown variant still gets the full poster. DB lane (the proxy opens its own short session).
|
||
"""
|
||
|
||
from fastapi.testclient import TestClient
|
||
|
||
import app.state as app_state
|
||
from app.main import app
|
||
from app.models import PlexItem, PlexLibrary
|
||
from app.plex import imgcache
|
||
from app.routes.plex import playback
|
||
|
||
|
||
class _FakePlex:
|
||
calls: list[tuple[str, int | None, int | None]] = []
|
||
|
||
def __init__(self, db) -> None:
|
||
pass
|
||
|
||
def __enter__(self):
|
||
return self
|
||
|
||
def __exit__(self, *exc) -> None:
|
||
return None
|
||
|
||
def image_bytes(self, key, width=None, height=None):
|
||
_FakePlex.calls.append((key, width, height))
|
||
return b"\xff\xd8jpeg", "image/jpeg"
|
||
|
||
|
||
def _setup(db, make_user, monkeypatch, tmp_path) -> TestClient:
|
||
user = make_user()
|
||
lib = PlexLibrary(plex_key="90", title="Movies", kind="movie", enabled=True)
|
||
db.add(lib)
|
||
db.flush()
|
||
db.add(
|
||
PlexItem(
|
||
rating_key="pm1",
|
||
library_id=lib.id,
|
||
kind="movie",
|
||
title="A Movie",
|
||
thumb_key="/library/metadata/pm1/thumb/1",
|
||
art_key="/library/metadata/pm1/art/1",
|
||
)
|
||
)
|
||
db.commit()
|
||
monkeypatch.setattr(app_state, "_configured_cache", True)
|
||
monkeypatch.setattr(playback, "resolved_user_id", lambda request: (user.id, True))
|
||
monkeypatch.setattr(playback, "PlexClient", _FakePlex)
|
||
monkeypatch.setattr(imgcache, "CACHE_DIR", tmp_path)
|
||
_FakePlex.calls = []
|
||
return TestClient(app)
|
||
|
||
|
||
def test_each_variant_is_cut_at_its_own_size(db, make_user, monkeypatch, tmp_path):
|
||
client = _setup(db, make_user, monkeypatch, tmp_path)
|
||
for variant in ("thumb", "thumb_sm", "art", "art_sm"):
|
||
assert client.get(f"/api/plex/image/pm1?variant={variant}").status_code == 200
|
||
assert _FakePlex.calls == [
|
||
("/library/metadata/pm1/thumb/1", 400, 600),
|
||
("/library/metadata/pm1/thumb/1", 240, 360),
|
||
("/library/metadata/pm1/art/1", 1280, 720),
|
||
("/library/metadata/pm1/art/1", 480, 270),
|
||
]
|
||
# Each cut is cached under its own name: asking again reaches Plex no more.
|
||
for variant in ("thumb", "thumb_sm", "art", "art_sm"):
|
||
assert client.get(f"/api/plex/image/pm1?variant={variant}").status_code == 200
|
||
assert len(_FakePlex.calls) == 4
|
||
|
||
|
||
def test_an_unknown_variant_gets_the_full_poster(db, make_user, monkeypatch, tmp_path):
|
||
client = _setup(db, make_user, monkeypatch, tmp_path)
|
||
assert client.get("/api/plex/image/pm1?variant=huge").status_code == 200
|
||
assert _FakePlex.calls == [("/library/metadata/pm1/thumb/1", 400, 600)]
|