promptlooper/backend/tests/test_routers.py
John Lightner 82e97e9dba MAESTRO: Implement experiments router with full CRUD and sweep control endpoints
Add complete experiments API: list (with project filter), get, create, update,
delete, plus sweep lifecycle (start/pause/resume/stop/status). Adds
SweepRequest and SweepStatusResponse schemas. Sweep dispatch routes through
Celery with synchronous fallback for single-container mode. Redis flags control
pause/resume/stop; direct DB updates used when Redis unavailable. 34 tests.
2026-04-07 03:19:43 -05:00

225 lines
6 KiB
Python

"""Tests for router stubs — verify all routes are mounted and return 501."""
import pytest
from fastapi.testclient import TestClient
@pytest.fixture()
def client(tmp_path, monkeypatch):
"""Create a test client with a temporary database."""
monkeypatch.setenv("DATA_DIR", str(tmp_path))
monkeypatch.setenv("DATABASE_URL", "")
monkeypatch.setenv("REDIS_URL", "")
# Reload config to pick up test env
import importlib
import config as config_mod
importlib.reload(config_mod)
import main as main_mod
importlib.reload(main_mod)
with TestClient(main_mod.app) as c:
yield c
# ---- Auth router (/api/auth) ----
def test_auth_setup(client):
resp = client.post("/api/auth/setup")
assert resp.status_code == 501
def test_auth_login(client):
resp = client.post("/api/auth/login")
assert resp.status_code == 501
def test_auth_me(client):
resp = client.get("/api/auth/me")
assert resp.status_code == 501
# ---- Projects router (/api/projects) ----
def test_projects_list(client):
resp = client.get("/api/projects/")
assert resp.status_code == 501
def test_projects_create(client):
resp = client.post("/api/projects/")
assert resp.status_code == 501
def test_projects_get(client):
resp = client.get("/api/projects/00000000-0000-0000-0000-000000000001")
assert resp.status_code == 501
def test_projects_update(client):
resp = client.put("/api/projects/00000000-0000-0000-0000-000000000001")
assert resp.status_code == 501
def test_projects_delete(client):
resp = client.delete("/api/projects/00000000-0000-0000-0000-000000000001")
assert resp.status_code == 501
# ---- Experiments router (/api/experiments) — now implemented, requires auth ----
def test_experiments_list(client):
resp = client.get("/api/experiments/")
assert resp.status_code == 401
def test_experiments_create(client):
resp = client.post("/api/experiments/")
assert resp.status_code == 401
def test_experiments_get(client):
resp = client.get("/api/experiments/00000000-0000-0000-0000-000000000001")
assert resp.status_code == 401
def test_experiments_update(client):
resp = client.put("/api/experiments/00000000-0000-0000-0000-000000000001")
assert resp.status_code == 401
def test_experiments_delete(client):
resp = client.delete("/api/experiments/00000000-0000-0000-0000-000000000001")
assert resp.status_code == 401
def test_experiments_sweep(client):
resp = client.post("/api/experiments/00000000-0000-0000-0000-000000000001/sweep")
assert resp.status_code == 401
def test_experiments_pause(client):
resp = client.post("/api/experiments/00000000-0000-0000-0000-000000000001/pause")
assert resp.status_code == 401
def test_experiments_resume(client):
resp = client.post("/api/experiments/00000000-0000-0000-0000-000000000001/resume")
assert resp.status_code == 401
def test_experiments_stop(client):
resp = client.post("/api/experiments/00000000-0000-0000-0000-000000000001/stop")
assert resp.status_code == 401
# ---- Runs router (/api/runs) ----
def test_runs_list(client):
resp = client.get("/api/runs/experiments/00000000-0000-0000-0000-000000000001/runs")
assert resp.status_code == 501
def test_runs_get(client):
resp = client.get("/api/runs/00000000-0000-0000-0000-000000000001")
assert resp.status_code == 501
def test_runs_create(client):
resp = client.post("/api/runs/")
assert resp.status_code == 501
def test_runs_score(client):
resp = client.post("/api/runs/00000000-0000-0000-0000-000000000001/score")
assert resp.status_code == 501
def test_runs_leaderboard(client):
resp = client.get("/api/runs/experiments/00000000-0000-0000-0000-000000000001/leaderboard")
assert resp.status_code == 501
# ---- Endpoints router (/api/endpoints) ----
# Endpoints router is now fully implemented and requires auth (returns 401 without credentials)
def test_endpoints_list(client):
resp = client.get("/api/endpoints/")
assert resp.status_code == 401
def test_endpoints_create(client):
resp = client.post("/api/endpoints/")
assert resp.status_code == 401
def test_endpoints_update(client):
resp = client.put("/api/endpoints/00000000-0000-0000-0000-000000000001")
assert resp.status_code == 401
def test_endpoints_delete(client):
resp = client.delete("/api/endpoints/00000000-0000-0000-0000-000000000001")
assert resp.status_code == 401
def test_endpoints_test(client):
resp = client.post("/api/endpoints/00000000-0000-0000-0000-000000000001/test")
assert resp.status_code == 401
# ---- Export router (/api/export) ----
def test_export_best(client):
resp = client.get("/api/export/experiments/00000000-0000-0000-0000-000000000001/best")
assert resp.status_code == 501
def test_export_env(client):
resp = client.get("/api/export/experiments/00000000-0000-0000-0000-000000000001/env")
assert resp.status_code == 501
def test_export_yaml(client):
resp = client.get("/api/export/experiments/00000000-0000-0000-0000-000000000001/yaml")
assert resp.status_code == 501
def test_export_report(client):
resp = client.get("/api/export/experiments/00000000-0000-0000-0000-000000000001/report")
assert resp.status_code == 501
# ---- Webhooks router (/api/webhooks) ----
def test_webhooks_list(client):
resp = client.get("/api/webhooks/")
assert resp.status_code == 501
def test_webhooks_create(client):
resp = client.post("/api/webhooks/")
assert resp.status_code == 501
def test_webhooks_delete(client):
resp = client.delete("/api/webhooks/00000000-0000-0000-0000-000000000001")
assert resp.status_code == 501
# ---- Admin router (/api/admin) ----
def test_admin_get_settings(client):
resp = client.get("/api/admin/settings")
assert resp.status_code == 501
def test_admin_update_settings(client):
resp = client.put("/api/admin/settings")
assert resp.status_code == 501
def test_admin_stats(client):
resp = client.get("/api/admin/stats")
assert resp.status_code == 501