mirror of
https://github.com/MrSleeps/jellyfin-scene-search.git
synced 2026-11-16 23:11:27 +00:00
Test targeted restoration of Jellyfin identity and embeddings
This commit is contained in:
@@ -7,7 +7,12 @@ from types import SimpleNamespace
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
from scene_search.database import connect, init_db
|
||||
from scene_search.sync import CaptionMeiliSync, sync_frame_metadata
|
||||
from scene_search.sync import (
|
||||
CaptionMeiliSync,
|
||||
count_caption_repair_documents,
|
||||
repair_caption_documents,
|
||||
sync_frame_metadata,
|
||||
)
|
||||
|
||||
|
||||
class IncrementalCaptionSyncTests(unittest.TestCase):
|
||||
@@ -214,5 +219,84 @@ class IncrementalCaptionSyncTests(unittest.TestCase):
|
||||
self.assertEqual(progress[-1]["meili_sync_pending"], 0)
|
||||
|
||||
|
||||
def test_repair_restores_identity_vectors_and_window_caption_without_reindex(self) -> None:
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
db_path = Path(tmp) / "scenes.sqlite3"
|
||||
self._seed(db_path, count=3)
|
||||
with connect(db_path) as con:
|
||||
con.execute(
|
||||
"""
|
||||
UPDATE media SET jellyfin_item_type = 'Movie',
|
||||
jellyfin_media_source_id = 'source-1'
|
||||
WHERE id = 'media-1'
|
||||
"""
|
||||
)
|
||||
con.execute(
|
||||
"""
|
||||
UPDATE frames
|
||||
SET caption = NULL, caption_model = NULL, captioned_at = NULL
|
||||
WHERE id IN ('frame-0', 'frame-1')
|
||||
"""
|
||||
)
|
||||
con.execute(
|
||||
"""
|
||||
INSERT INTO caption_windows (
|
||||
id, media_id, start_ms, end_ms, representative_frame_id,
|
||||
caption, caption_model, captioned_at,
|
||||
caption_route, caption_route_reason, route_score,
|
||||
route_model, route_policy, routed_at, window_policy
|
||||
)
|
||||
VALUES (
|
||||
'window-1', 'media-1', 0, 20000, 'frame-1',
|
||||
'A distinct red umbrella.', 'caption-model',
|
||||
CURRENT_TIMESTAMP, 'specialist', 'reason', 0.9,
|
||||
'router-model', 'policy-v1', CURRENT_TIMESTAMP,
|
||||
'test-window-policy'
|
||||
)
|
||||
"""
|
||||
)
|
||||
con.executemany(
|
||||
"""
|
||||
INSERT INTO caption_window_frames
|
||||
(window_id, frame_id, position) VALUES (?, ?, ?)
|
||||
""",
|
||||
[('window-1', 'frame-0', 0), ('window-1', 'frame-1', 1)],
|
||||
)
|
||||
# frame-2 is a legacy captioned frame, so it needs repair too.
|
||||
|
||||
self.assertEqual(count_caption_repair_documents(db_path), 3)
|
||||
meili = MagicMock()
|
||||
progress = []
|
||||
restored = repair_caption_documents(
|
||||
db_path=db_path, meili=meili,
|
||||
batch_size=2, progress=progress.append,
|
||||
)
|
||||
|
||||
self.assertEqual(restored, 3)
|
||||
self.assertEqual(meili.add_documents.call_count, 2)
|
||||
self.assertTrue(all(
|
||||
call.kwargs["wait"] for call in meili.add_documents.call_args_list
|
||||
))
|
||||
docs = [
|
||||
document
|
||||
for call in meili.add_documents.call_args_list
|
||||
for document in call.args[0]
|
||||
]
|
||||
by_id = {doc["id"]: doc for doc in docs}
|
||||
self.assertEqual(len(by_id), 3)
|
||||
self.assertEqual(by_id["frame-1"]["caption"], "A distinct red umbrella.")
|
||||
self.assertEqual(by_id["frame-1"]["caption_window_id"], "window-1")
|
||||
self.assertIsNone(by_id["frame-0"]["caption"])
|
||||
self.assertEqual(by_id["frame-2"]["caption"], "Caption 2")
|
||||
for doc in docs:
|
||||
self.assertEqual(doc["jellyfin_item_id"], "item-1")
|
||||
self.assertEqual(doc["jellyfin_item_type"], "Movie")
|
||||
self.assertEqual(doc["jellyfin_library_id"], "lib-1")
|
||||
self.assertEqual(doc["title"], "Movie")
|
||||
self.assertIn("siglip2", doc["_vectors"])
|
||||
self.assertEqual(len(doc["_vectors"]["siglip2"]), 2)
|
||||
self.assertEqual(progress[-1]["documents_processed"], 3)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user