summaryrefslogtreecommitdiffstats
path: root/packages/meshbay-node/tests/test_ops_rematch_video.py
diff options
context:
space:
mode:
authorChristophe Besson <cbesson@gmail.com>2026-08-29 15:12:32 +0200
committerChristophe Besson <cbesson@gmail.com>2026-08-29 15:12:32 +0200
commit5a88f8d7a0a35b0c75b0a56d0f6fce1d0a495c12 (patch)
treecbc0a8207885476cd0d331db399536c259ca4f80 /packages/meshbay-node/tests/test_ops_rematch_video.py
parentbe57cf9c3b499c8e59a94d13059f16f1456fcae1 (diff)
parent71b7a310ce938f072fe20f27eeeadd40685f1ad1 (diff)
downloadmeshbay-5a88f8d7a0a35b0c75b0a56d0f6fce1d0a495c12.tar.gz
Merge branch 'fix/videos-tmdb-matching'
Diffstat (limited to 'packages/meshbay-node/tests/test_ops_rematch_video.py')
-rw-r--r--packages/meshbay-node/tests/test_ops_rematch_video.py71
1 files changed, 71 insertions, 0 deletions
diff --git a/packages/meshbay-node/tests/test_ops_rematch_video.py b/packages/meshbay-node/tests/test_ops_rematch_video.py
new file mode 100644
index 0000000..f63a1a9
--- /dev/null
+++ b/packages/meshbay-node/tests/test_ops_rematch_video.py
@@ -0,0 +1,71 @@
+"""
+Tests for ops.rematch_video — drops a group's *auto-resolved* video->TMDB
+matches so they re-resolve against the current matcher (run by the operator
+after a matcher/parser fix; `media_cache.file_tmdb` is keyed by content
+hash and is otherwise only pruned on deletion). Manual "Fix match"
+corrections are kept.
+"""
+
+import types
+
+import pytest
+from meshbay_node import ops
+from meshbay_node.media_cache import MediaCache
+
+pytestmark = pytest.mark.asyncio
+
+
+def _indexer(*entries):
+ return types.SimpleNamespace(index=types.SimpleNamespace(entries=list(entries)))
+
+
+def _entry(file_id, type_="video"):
+ return types.SimpleNamespace(id=file_id, type=type_)
+
+
+@pytest.fixture
+async def media_cache(tmp_path):
+ c = MediaCache(db_path=tmp_path / "media_cache.db")
+ await c.open()
+ yield c
+ await c.close()
+
+
+async def test_no_media_cache_raises():
+ with pytest.raises(ops.OpError):
+ await ops.rematch_video({}, "g" * 32)
+
+
+async def test_unknown_group_raises(media_cache):
+ with pytest.raises(ops.OpError):
+ await ops.rematch_video({"media_cache": media_cache, "indexers": {}}, "nope")
+
+
+async def test_clears_auto_matches_keeps_overrides_ignores_non_video(media_cache):
+ await media_cache.set_file_tmdb("v-auto-1", "10", "movie")
+ await media_cache.set_file_tmdb("v-auto-2", "20", "movie")
+ await media_cache.set_file_tmdb("v-fixed", "30", "movie")
+ await media_cache.mark_tmdb_override("v-fixed")
+ await media_cache.set_file_mbid("a-track", "some-mbid") # audio, untouched
+
+ state = {
+ "media_cache": media_cache,
+ "indexers": {"g": _indexer(
+ _entry("v-auto-1"), _entry("v-auto-2"), _entry("v-fixed"),
+ _entry("a-track", "audio"),
+ )},
+ }
+
+ result = await ops.rematch_video(state, "g")
+
+ assert result == {"status": "cleared", "removed": 2, "videos": 3, "group_id": "g"}
+ assert await media_cache.get_file_tmdb("v-auto-1") is None
+ assert await media_cache.get_file_tmdb("v-auto-2") is None
+ assert await media_cache.get_file_tmdb("v-fixed") == ("30", "movie")
+ assert await media_cache.get_file_mbid("a-track") == "some-mbid"
+
+
+async def test_group_with_no_videos_is_a_clean_noop(media_cache):
+ state = {"media_cache": media_cache, "indexers": {"g": _indexer()}}
+ result = await ops.rematch_video(state, "g")
+ assert result == {"status": "cleared", "removed": 0, "videos": 0, "group_id": "g"}