feat(plex): a Surprise reshuffle deals the previous draw last

The rail draws three unseen titles per kind under the sidebar filters; on a
small filtered pool every reshuffle dealt the same few again. The redraw now
sends the draw on screen (exclude=), the server deals the rest of the pool
first and tops up from the excluded titles only when the pool is short, so a
small pool still fills the rail. (The two discover.py baseline entries went
with the rewritten draw.)
This commit is contained in:
2026-10-09 00:06:11 +02:00
parent 6dd82ef5e2
commit 5f42ff61c8
6 changed files with 82 additions and 51 deletions
+15
View File
@@ -316,6 +316,21 @@ def test_surprise_excludes_watched_and_caps_per_kind(db, monkeypatch, override_d
assert len([c for c in items if c["type"] == "show"]) <= 3
def test_a_reshuffle_deals_other_titles_first(db, monkeypatch, override_dep):
# The ↻ sends the previous draw: what is left of the pool comes first, and a pool smaller than a
# draw is topped up from the excluded titles rather than leaving the rail short.
user = _seed(db)
def movies(url: str) -> list[str]:
items = _get(db, user, monkeypatch, override_dep, url).json()["items"]
return [c["id"] for c in items if c["type"] == "movie"]
for _ in range(5): # random order: one lucky pass would prove nothing
got = movies("/api/plex/surprise?scope=movie&exclude=m2")
assert got[0] == "m3" and set(got) == {"m2", "m3"}
assert set(movies("/api/plex/surprise?scope=movie&exclude=m2&exclude=m3")) == {"m2", "m3"}
def test_discover_scope_movie_excludes_shows(db, monkeypatch, override_dep):
user = _seed(db)
d = _get(db, user, monkeypatch, override_dep, "/api/plex/discover?scope=movie").json()