chore: snapshot current project updates

This commit is contained in:
windyboy
2026-02-13 13:36:39 +08:00
parent 5931f16a71
commit 0be802eac5
74 changed files with 594899 additions and 66082 deletions
+69
View File
@@ -1,5 +1,8 @@
"""Unit tests for enrichment pipeline."""
import threading
import time
import pytest
from vlm.config import Config
@@ -351,3 +354,69 @@ def test_enrich_auth_failure_stops_immediately(tmp_path, monkeypatch):
with pytest.raises(RuntimeError, match="authentication failed"):
enrich_identities_data(identities, config, refresh_mode="refresh_all")
def test_enrich_respects_max_concurrency_for_uncached_records(tmp_path, monkeypatch):
"""Multiple uncached records should be enriched by multiple worker threads."""
config = Config(
library_root=tmp_path,
enrichment_cache_db=tmp_path / "cache.db",
enrichment_providers=["dummy"],
translation_fallback_machine=False,
enrichment_max_concurrency=4,
)
identities = {
"metadata": {},
"movies": [
{
"path": f"/library/movie/Test.{i}.mkv",
"filename": f"Test.{i}.mkv",
"category": "movie",
"title": f"Test {i}",
"year": 2020,
"confidence": 0.9,
"needs_review": False,
}
for i in range(8)
],
"series": [],
"anime": [],
"other": [],
}
thread_ids: set[int] = set()
lock = threading.Lock()
def _fake_enrich(record, media_type, config_obj, request_timeout, retries):
time.sleep(0.01)
with lock:
thread_ids.add(threading.get_ident())
title = record.get("title", "X")
payload = {
"canonical_id": f"id:{title}",
"title_zh": title,
"title_en": title,
"translation_source": "dummy",
"reputation_score": None,
"reputation_votes": None,
"reputation_source": None,
"provider_metadata": {},
"review_status": "pending",
"enrichment_confidence": 0.8,
"needs_review": False,
"display_title": title,
"enriched": True,
}
return payload, 1, [], ""
monkeypatch.setattr(
"vlm.enrichment._enrich_record_with_fresh_providers",
_fake_enrich,
)
_, stats = enrich_identities_data(identities, config, refresh_mode="refresh_all")
assert stats["enriched"] == 8
assert stats["cache_hits"] == 0
assert len(thread_ids) > 1