forked from Rockachopa/Timmy-time-dashboard
feat: code quality audit + autoresearch integration + infra hardening (#150)
This commit is contained in:
committed by
GitHub
parent
fd0ede0d51
commit
ae3bb1cc21
@@ -1,15 +1,10 @@
|
||||
"""Tests for the custom models API routes."""
|
||||
|
||||
from unittest.mock import patch, MagicMock
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from infrastructure.models.registry import (
|
||||
CustomModel,
|
||||
ModelFormat,
|
||||
ModelRegistry,
|
||||
ModelRole,
|
||||
)
|
||||
from infrastructure.models.registry import CustomModel, ModelFormat, ModelRegistry, ModelRole
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@@ -27,9 +22,7 @@ class TestModelsAPIList:
|
||||
def test_list_models_empty(self, client, tmp_path):
|
||||
db = tmp_path / "api.db"
|
||||
with patch("infrastructure.models.registry.DB_PATH", db):
|
||||
with patch(
|
||||
"dashboard.routes.models.model_registry"
|
||||
) as mock_reg:
|
||||
with patch("dashboard.routes.models.model_registry") as mock_reg:
|
||||
mock_reg.list_models.return_value = []
|
||||
resp = client.get("/api/v1/models")
|
||||
assert resp.status_code == 200
|
||||
@@ -44,9 +37,7 @@ class TestModelsAPIList:
|
||||
path="llama3.2",
|
||||
role=ModelRole.GENERAL,
|
||||
)
|
||||
with patch(
|
||||
"dashboard.routes.models.model_registry"
|
||||
) as mock_reg:
|
||||
with patch("dashboard.routes.models.model_registry") as mock_reg:
|
||||
mock_reg.list_models.return_value = [model]
|
||||
resp = client.get("/api/v1/models")
|
||||
assert resp.status_code == 200
|
||||
@@ -59,9 +50,7 @@ class TestModelsAPIRegister:
|
||||
"""Test model registration via the API."""
|
||||
|
||||
def test_register_ollama_model(self, client):
|
||||
with patch(
|
||||
"dashboard.routes.models.model_registry"
|
||||
) as mock_reg:
|
||||
with patch("dashboard.routes.models.model_registry") as mock_reg:
|
||||
mock_reg.register.return_value = CustomModel(
|
||||
name="my-model",
|
||||
format=ModelFormat.OLLAMA,
|
||||
@@ -111,17 +100,13 @@ class TestModelsAPIDelete:
|
||||
"""Test model deletion via the API."""
|
||||
|
||||
def test_delete_model(self, client):
|
||||
with patch(
|
||||
"dashboard.routes.models.model_registry"
|
||||
) as mock_reg:
|
||||
with patch("dashboard.routes.models.model_registry") as mock_reg:
|
||||
mock_reg.unregister.return_value = True
|
||||
resp = client.delete("/api/v1/models/my-model")
|
||||
assert resp.status_code == 200
|
||||
|
||||
def test_delete_nonexistent(self, client):
|
||||
with patch(
|
||||
"dashboard.routes.models.model_registry"
|
||||
) as mock_reg:
|
||||
with patch("dashboard.routes.models.model_registry") as mock_reg:
|
||||
mock_reg.unregister.return_value = False
|
||||
resp = client.delete("/api/v1/models/nonexistent")
|
||||
assert resp.status_code == 404
|
||||
@@ -137,18 +122,14 @@ class TestModelsAPIGet:
|
||||
path="llama3.2",
|
||||
role=ModelRole.GENERAL,
|
||||
)
|
||||
with patch(
|
||||
"dashboard.routes.models.model_registry"
|
||||
) as mock_reg:
|
||||
with patch("dashboard.routes.models.model_registry") as mock_reg:
|
||||
mock_reg.get.return_value = model
|
||||
resp = client.get("/api/v1/models/my-model")
|
||||
assert resp.status_code == 200
|
||||
assert resp.json()["name"] == "my-model"
|
||||
|
||||
def test_get_nonexistent(self, client):
|
||||
with patch(
|
||||
"dashboard.routes.models.model_registry"
|
||||
) as mock_reg:
|
||||
with patch("dashboard.routes.models.model_registry") as mock_reg:
|
||||
mock_reg.get.return_value = None
|
||||
resp = client.get("/api/v1/models/nonexistent")
|
||||
assert resp.status_code == 404
|
||||
@@ -158,9 +139,7 @@ class TestModelsAPIAssignments:
|
||||
"""Test agent model assignment endpoints."""
|
||||
|
||||
def test_assign_model(self, client):
|
||||
with patch(
|
||||
"dashboard.routes.models.model_registry"
|
||||
) as mock_reg:
|
||||
with patch("dashboard.routes.models.model_registry") as mock_reg:
|
||||
mock_reg.assign_model.return_value = True
|
||||
resp = client.post(
|
||||
"/api/v1/models/assignments",
|
||||
@@ -169,9 +148,7 @@ class TestModelsAPIAssignments:
|
||||
assert resp.status_code == 200
|
||||
|
||||
def test_assign_nonexistent_model(self, client):
|
||||
with patch(
|
||||
"dashboard.routes.models.model_registry"
|
||||
) as mock_reg:
|
||||
with patch("dashboard.routes.models.model_registry") as mock_reg:
|
||||
mock_reg.assign_model.return_value = False
|
||||
resp = client.post(
|
||||
"/api/v1/models/assignments",
|
||||
@@ -180,25 +157,19 @@ class TestModelsAPIAssignments:
|
||||
assert resp.status_code == 404
|
||||
|
||||
def test_unassign_model(self, client):
|
||||
with patch(
|
||||
"dashboard.routes.models.model_registry"
|
||||
) as mock_reg:
|
||||
with patch("dashboard.routes.models.model_registry") as mock_reg:
|
||||
mock_reg.unassign_model.return_value = True
|
||||
resp = client.delete("/api/v1/models/assignments/agent-1")
|
||||
assert resp.status_code == 200
|
||||
|
||||
def test_unassign_nonexistent(self, client):
|
||||
with patch(
|
||||
"dashboard.routes.models.model_registry"
|
||||
) as mock_reg:
|
||||
with patch("dashboard.routes.models.model_registry") as mock_reg:
|
||||
mock_reg.unassign_model.return_value = False
|
||||
resp = client.delete("/api/v1/models/assignments/nonexistent")
|
||||
assert resp.status_code == 404
|
||||
|
||||
def test_list_assignments(self, client):
|
||||
with patch(
|
||||
"dashboard.routes.models.model_registry"
|
||||
) as mock_reg:
|
||||
with patch("dashboard.routes.models.model_registry") as mock_reg:
|
||||
mock_reg.get_agent_assignments.return_value = {
|
||||
"agent-1": "model-a",
|
||||
"agent-2": "model-b",
|
||||
@@ -219,9 +190,7 @@ class TestModelsAPIRoles:
|
||||
path="deepseek-r1:1.5b",
|
||||
role=ModelRole.REWARD,
|
||||
)
|
||||
with patch(
|
||||
"dashboard.routes.models.model_registry"
|
||||
) as mock_reg:
|
||||
with patch("dashboard.routes.models.model_registry") as mock_reg:
|
||||
mock_reg.get_reward_model.return_value = model
|
||||
resp = client.get("/api/v1/models/roles/reward")
|
||||
assert resp.status_code == 200
|
||||
@@ -229,18 +198,14 @@ class TestModelsAPIRoles:
|
||||
assert data["reward_model"]["name"] == "reward-m"
|
||||
|
||||
def test_get_reward_model_none(self, client):
|
||||
with patch(
|
||||
"dashboard.routes.models.model_registry"
|
||||
) as mock_reg:
|
||||
with patch("dashboard.routes.models.model_registry") as mock_reg:
|
||||
mock_reg.get_reward_model.return_value = None
|
||||
resp = client.get("/api/v1/models/roles/reward")
|
||||
assert resp.status_code == 200
|
||||
assert resp.json()["reward_model"] is None
|
||||
|
||||
def test_get_teacher_model(self, client):
|
||||
with patch(
|
||||
"dashboard.routes.models.model_registry"
|
||||
) as mock_reg:
|
||||
with patch("dashboard.routes.models.model_registry") as mock_reg:
|
||||
mock_reg.get_teacher_model.return_value = None
|
||||
resp = client.get("/api/v1/models/roles/teacher")
|
||||
assert resp.status_code == 200
|
||||
@@ -251,9 +216,7 @@ class TestModelsAPISetActive:
|
||||
"""Test enable/disable model endpoint."""
|
||||
|
||||
def test_enable_model(self, client):
|
||||
with patch(
|
||||
"dashboard.routes.models.model_registry"
|
||||
) as mock_reg:
|
||||
with patch("dashboard.routes.models.model_registry") as mock_reg:
|
||||
mock_reg.set_active.return_value = True
|
||||
resp = client.patch(
|
||||
"/api/v1/models/my-model/active",
|
||||
@@ -262,9 +225,7 @@ class TestModelsAPISetActive:
|
||||
assert resp.status_code == 200
|
||||
|
||||
def test_disable_nonexistent(self, client):
|
||||
with patch(
|
||||
"dashboard.routes.models.model_registry"
|
||||
) as mock_reg:
|
||||
with patch("dashboard.routes.models.model_registry") as mock_reg:
|
||||
mock_reg.set_active.return_value = False
|
||||
resp = client.patch(
|
||||
"/api/v1/models/nonexistent/active",
|
||||
|
||||
Reference in New Issue
Block a user