File size: 1,125 Bytes
b123708
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
"""Unload GPU-resident tagger sessions via POST /api/models/unload."""

from __future__ import annotations

from fastapi.testclient import TestClient

from app.main import app
from app.storage import execute


def test_unload_models_clears_loaded_list():
    with TestClient(app) as client:
        resp = client.post("/api/models/unload")
        assert resp.status_code == 200
        body = resp.json()
        assert isinstance(body["unloaded"], list)
        assert "message" in body
        providers = client.get("/api/providers").json()
        assert providers["loaded_models"] == []


def test_unload_models_rejects_while_run_is_active():
    execute(
        """
        INSERT INTO runs (
            created_at, root_repo, categories_root, confidence_threshold,
            status, total_images, processed_images, failed_images
        ) VALUES ('2026-08-16T00:00:00+00:00', 'x', 'y', 0.45, 'running', 10, 1, 0)
        """
    )
    with TestClient(app) as client:
        resp = client.post("/api/models/unload")
        assert resp.status_code == 409
        assert "running" in resp.json()["detail"].lower()