refactor(ml): drop dead tagger/suggestion settings + columns (#1199)
Hygiene follow-up to the Camie retirement (#1189) — these were left inert to bound that change; nothing reads them now. Migration 0068 drops: - ml_settings: tagger_store_floor, tagger_model_version, suggestion_threshold_ character/general (already dead pre-retirement — scoring uses per-head thresholds), video_min_tag_frames (only the deleted video-prediction aggregator used it). - image_record: tagger_model_version (no writer), centroid_scores (dead JSON cache, no reader). Also: ml_admin _EDITABLE/GET/_validate pruned (dropped the store-floor invariant + video_min_tag_frames check); MLThresholdSliders trimmed to a video-embedding card (interval + max frames only); importer no longer resets the dropped cols; download_models drops the Camie fetch; stale CASCADE comments in cleanup_service no longer name the removed tables. Tests updated. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Ttrj5P7upUTueSfoJcxEqa
This commit is contained in:
+14
-41
@@ -19,19 +19,18 @@ async def test_get_and_patch_settings(client):
|
||||
resp = await client.get("/api/ml/settings")
|
||||
assert resp.status_code == 200
|
||||
body = await resp.get_json()
|
||||
# Default raised 0.50 → 0.70 on 2026-06-02 (alembic 0033) — 0.50
|
||||
# was too noisy in practice. The 0.70 default keeps the rail
|
||||
# signal-rich without hiding everything like the original 0.95.
|
||||
assert body["suggestion_threshold_general"] == pytest.approx(0.70)
|
||||
# Retired threshold columns must not appear in the payload.
|
||||
assert "suggestion_threshold_artist" not in body
|
||||
assert "suggestion_threshold_copyright" not in body
|
||||
assert body["head_min_positives"] == 8
|
||||
# Retired tagger/suggestion-threshold columns are gone from the payload
|
||||
# (Camie retirement #1189/#1199).
|
||||
assert "suggestion_threshold_general" not in body
|
||||
assert "tagger_store_floor" not in body
|
||||
assert "tagger_model_version" not in body
|
||||
|
||||
resp = await client.patch(
|
||||
"/api/ml/settings", json={"suggestion_threshold_general": 0.90}
|
||||
"/api/ml/settings", json={"head_min_positives": 12}
|
||||
)
|
||||
assert resp.status_code == 200
|
||||
assert (await resp.get_json())["suggestion_threshold_general"] == pytest.approx(0.90)
|
||||
assert (await resp.get_json())["head_min_positives"] == 12
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@@ -55,55 +54,29 @@ async def test_embedder_model_settable_and_empty_rejected(client):
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_tagger_store_floor_default_and_patch(client):
|
||||
body = await (await client.get("/api/ml/settings")).get_json()
|
||||
assert body["tagger_store_floor"] == pytest.approx(0.70)
|
||||
|
||||
resp = await client.patch("/api/ml/settings", json={"tagger_store_floor": 0.6})
|
||||
assert resp.status_code == 200
|
||||
assert (await resp.get_json())["tagger_store_floor"] == pytest.approx(0.6)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_suggestion_threshold_below_store_floor_rejected(client):
|
||||
# Invariant (#764): a category threshold can't sit below the store floor —
|
||||
# nothing below the floor is stored, so the gap would surface nothing.
|
||||
# Floor defaults to 0.70; pushing general down to 0.50 must 400.
|
||||
resp = await client.patch(
|
||||
"/api/ml/settings", json={"suggestion_threshold_general": 0.50}
|
||||
)
|
||||
assert resp.status_code == 400
|
||||
assert "tagger_store_floor" in (await resp.get_json())["error"]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_video_tagging_settings_default_and_patch(client):
|
||||
"""#747: video cadence/noise knobs are exposed + patchable."""
|
||||
async def test_video_settings_default_and_patch(client):
|
||||
"""#747: video frame-sampling knobs are exposed + patchable."""
|
||||
body = await (await client.get("/api/ml/settings")).get_json()
|
||||
assert body["video_frame_interval_seconds"] == pytest.approx(4.0)
|
||||
assert body["video_max_frames"] == 64
|
||||
assert body["video_min_tag_frames"] == 3
|
||||
|
||||
resp = await client.patch(
|
||||
"/api/ml/settings",
|
||||
json={"video_frame_interval_seconds": 5, "video_max_frames": 40,
|
||||
"video_min_tag_frames": 4},
|
||||
json={"video_frame_interval_seconds": 5, "video_max_frames": 40},
|
||||
)
|
||||
assert resp.status_code == 200
|
||||
out = await resp.get_json()
|
||||
assert out["video_frame_interval_seconds"] == pytest.approx(5.0)
|
||||
assert out["video_max_frames"] == 40
|
||||
assert out["video_min_tag_frames"] == 4
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_video_min_tag_frames_above_max_rejected(client):
|
||||
async def test_video_max_frames_below_one_rejected(client):
|
||||
resp = await client.patch(
|
||||
"/api/ml/settings",
|
||||
json={"video_max_frames": 10, "video_min_tag_frames": 20},
|
||||
"/api/ml/settings", json={"video_max_frames": 0},
|
||||
)
|
||||
assert resp.status_code == 400
|
||||
assert "video_min_tag_frames" in (await resp.get_json())["error"]
|
||||
assert "video_max_frames" in (await resp.get_json())["error"]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"""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.
|
||||
skip' short-circuit by faking the expected files, and that main() wires the
|
||||
SigLIP fetch. (Camie download retired with the tagger, #1199.)
|
||||
"""
|
||||
|
||||
from unittest.mock import patch
|
||||
@@ -8,29 +8,6 @@ from unittest.mock import patch
|
||||
from backend.app.scripts import download_models as dm
|
||||
|
||||
|
||||
def test_ensure_camie_skips_when_present(tmp_path, monkeypatch):
|
||||
"""v2 layout (HF Camais03/camie-tagger-v2): the ONNX file is named
|
||||
camie-tagger-v2.onnx (not model.onnx) and tags ship inside
|
||||
camie-tagger-v2-metadata.json (not selected_tags.csv). Both at root.
|
||||
Updated 2026-05-25 after the actual repo layout was confirmed via
|
||||
WebFetch — the old assertion pinned the v1 filenames."""
|
||||
monkeypatch.setattr(dm, "MODEL_ROOT", tmp_path)
|
||||
camie = tmp_path / "camie"
|
||||
camie.mkdir(parents=True)
|
||||
(camie / "camie-tagger-v2.onnx").write_bytes(b"x")
|
||||
(camie / "camie-tagger-v2-metadata.json").write_text("{}")
|
||||
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"
|
||||
@@ -42,9 +19,15 @@ def test_ensure_siglip_skips_when_present(tmp_path, monkeypatch):
|
||||
snap.assert_not_called()
|
||||
|
||||
|
||||
def test_main_calls_both(monkeypatch):
|
||||
def test_ensure_siglip_downloads_when_missing(tmp_path, monkeypatch):
|
||||
monkeypatch.setattr(dm, "MODEL_ROOT", tmp_path)
|
||||
with patch.object(dm, "_snapshot") as snap:
|
||||
dm.ensure_siglip()
|
||||
snap.assert_called_once()
|
||||
|
||||
|
||||
def test_main_fetches_siglip(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"]
|
||||
assert calls == ["siglip"]
|
||||
|
||||
@@ -20,12 +20,15 @@ def test_new_tables_registered():
|
||||
|
||||
def test_image_record_columns_renamed():
|
||||
cols = {c.name for c in ImageRecord.__table__.columns}
|
||||
# tagger_predictions (the renamed wd14_predictions) was later dropped in
|
||||
# migration 0046 — predictions live in image_prediction now (#768).
|
||||
assert "tagger_model_version" in cols
|
||||
# Legacy tagger columns are all gone: tagger_predictions/wd14_* dropped in
|
||||
# 0046, tagger_model_version + centroid_scores dropped in 0068 (#1199, Camie
|
||||
# retirement). The SigLIP embedding columns are the live ML fields.
|
||||
assert "siglip_embedding" in cols
|
||||
assert "siglip_model_version" in cols
|
||||
assert "tagger_model_version" not in cols
|
||||
assert "centroid_scores" not in cols
|
||||
assert "tagger_predictions" not in cols
|
||||
assert "wd14_predictions" not in cols
|
||||
assert "wd14_model_version" not in cols
|
||||
|
||||
|
||||
def test_tag_alias_composite_pk():
|
||||
|
||||
Reference in New Issue
Block a user