diff options
| author | Christophe Besson <cbesson@gmail.com> | 2026-08-26 17:09:07 +0200 |
|---|---|---|
| committer | Christophe Besson <cbesson@gmail.com> | 2026-08-26 17:09:07 +0200 |
| commit | 59289b82dc8af08c605fd247c90a5c5ec92c6db3 (patch) | |
| tree | 590e2daf81b2feef674f1bd580b9bf40f83addad /packages/meshbay-node/tests | |
| parent | 8b315b99b941f5e08ab9d622c26fb85d4bc64955 (diff) | |
| download | meshbay-59289b82dc8af08c605fd247c90a5c5ec92c6db3.tar.gz | |
fix(video): a TMDB override never stored the metadata its chosen id names
Found live: "fix match" appeared to work for two shows but not for a movie
whose own automatic search kept landing on the same wrong result. The
override only ever recorded the file->tmdb_id mapping — never the
metadata that id actually names. _do_media_meta_request's cache check
agrees the mapping is fresh (same media_type) but finds nothing under
that *new* id in tmdb_meta, since nothing had ever fetched it, and falls
through to a brand-new search using the file's own title — reproducing
the exact match the override was meant to replace.
This stayed invisible for the two shows only because their own title
happened to be enough for that fallback search to land on the right
answer anyway, entirely independent of whatever the override recorded —
never because the override was actually being honored. It surfaced on a
movie whose own title search kept landing on the same wrong match
regardless.
Fetches and stores the real metadata for the chosen tmdb_id up front (via
the existing _tmdb_build_meta, which needs only the id — no search result
object required), so a later lookup finds the override itself instead of
falling through to a search blind to it.
Diffstat (limited to 'packages/meshbay-node/tests')
| -rw-r--r-- | packages/meshbay-node/tests/test_tmdb_override_policy.py | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/packages/meshbay-node/tests/test_tmdb_override_policy.py b/packages/meshbay-node/tests/test_tmdb_override_policy.py index cd1cee1..c2f28e6 100644 --- a/packages/meshbay-node/tests/test_tmdb_override_policy.py +++ b/packages/meshbay-node/tests/test_tmdb_override_policy.py @@ -195,5 +195,63 @@ async def test_override_updates_every_entry_sharing_the_display_title(tmp_path): await media_cache.close() +class _FakeTmdbClient: + """Just enough for _tmdb_build_meta to run end to end — a fixed, + deterministic response, not a search stub (the override already has a + chosen tmdb_id; nothing here should need to search for anything).""" + + async def movie_details(self, tmdb_id, language=None): + return {"title": "The Corrected Title", "overview": "A correct overview.", + "poster_path": "/poster.jpg", "genres": [{"name": "Drama"}]} + + async def tv_details(self, tmdb_id, language=None): + return await self.movie_details(tmdb_id, language) + + async def movie_credits(self, tmdb_id): + return {"cast": [], "crew": []} + + async def tv_credits(self, tmdb_id): + return {"cast": [], "crew": []} + + +async def test_override_stores_the_chosen_matchs_metadata_not_just_its_id(tmp_path): + """ + The real bug this guards: only the file->tmdb_id mapping ever got + recorded, never the metadata the chosen id actually names. + _do_media_meta_request's cache check agrees the mapping is fresh (same + media_type) but finds nothing under that id in tmdb_meta — nothing had + ever fetched it — and falls through to a brand new search using the + file's own title, reproducing the very match the override was meant to + replace. Confirmed live: this stayed invisible for shows whose own + title happened to be enough for that fallback search to land on the + right answer anyway, and surfaced on a movie whose own title kept + landing on the same wrong match regardless of the override. + """ + session = _session(tmp_path, "op", operator="op") + index = session._ctx["index"] + entry = _entry("shared", "movie.mkv", "Some Movie's Own Wrong Title") + index.add_entry(entry) + + media_cache = MediaCache(db_path=tmp_path / "media_cache.db") + await media_cache.open() + try: + session._ctx["media_cache"] = media_cache + session._ctx["tmdb_client"] = _FakeTmdbClient() + session._verify_admin_sig = lambda transcript, sig: _true() + session._peer_registry = lambda: {} + + await session._admin_exec_tmdb_override( + {"subject": f"file_id={entry.id},tmdb_id=999,media_type=movie"}, + b"transcript", b"sig") + + meta = await media_cache.get_tmdb_meta("999", "movie") + assert meta is not None, ( + "the override must store the metadata its chosen id actually names, " + "not just the file->tmdb_id mapping") + assert meta["title"] == "The Corrected Title" + finally: + await media_cache.close() + + async def _true(): return True |