feat(fc2b): importer enqueues tag_and_embed + ml-worker model self-heal
import_media_file now enqueues tag_and_embed alongside generate_thumbnail after a successful import. scripts/download_models.py snapshots Camie + SigLIP into /models, idempotent (skips when present). The ml-worker entrypoint runs it before starting the Celery worker so a fresh /models volume self-heals on first boot. Downloader tests are pure-logic (no network in CI). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
"""download_models tests. No network in CI; we test the 'already present →
|
||||
skip' short-circuit by faking the expected files, and that main() wires
|
||||
both ensure_* calls.
|
||||
"""
|
||||
|
||||
from unittest.mock import patch
|
||||
|
||||
from backend.app.scripts import download_models as dm
|
||||
|
||||
|
||||
def test_ensure_camie_skips_when_present(tmp_path, monkeypatch):
|
||||
monkeypatch.setattr(dm, "MODEL_ROOT", tmp_path)
|
||||
camie = tmp_path / "camie"
|
||||
camie.mkdir(parents=True)
|
||||
(camie / "model.onnx").write_bytes(b"x")
|
||||
(camie / "selected_tags.csv").write_text("tag_id,name,category,count\n")
|
||||
with patch.object(dm, "_snapshot") as snap:
|
||||
dm.ensure_camie()
|
||||
snap.assert_not_called()
|
||||
|
||||
|
||||
def test_ensure_camie_downloads_when_missing(tmp_path, monkeypatch):
|
||||
monkeypatch.setattr(dm, "MODEL_ROOT", tmp_path)
|
||||
with patch.object(dm, "_snapshot") as snap:
|
||||
dm.ensure_camie()
|
||||
snap.assert_called_once()
|
||||
|
||||
|
||||
def test_ensure_siglip_skips_when_present(tmp_path, monkeypatch):
|
||||
monkeypatch.setattr(dm, "MODEL_ROOT", tmp_path)
|
||||
sig = tmp_path / "siglip"
|
||||
sig.mkdir(parents=True)
|
||||
(sig / "config.json").write_text("{}")
|
||||
(sig / "model.safetensors").write_bytes(b"x")
|
||||
with patch.object(dm, "_snapshot") as snap:
|
||||
dm.ensure_siglip()
|
||||
snap.assert_not_called()
|
||||
|
||||
|
||||
def test_main_calls_both(monkeypatch):
|
||||
calls = []
|
||||
monkeypatch.setattr(dm, "ensure_camie", lambda: calls.append("camie"))
|
||||
monkeypatch.setattr(dm, "ensure_siglip", lambda: calls.append("siglip"))
|
||||
assert dm.main() == 0
|
||||
assert calls == ["camie", "siglip"]
|
||||
Reference in New Issue
Block a user