AI gateway: - Add a generic, admin-selectable `client_profile` field on gateway_providers (e.g. "opencode") so a provider needing special request headers (OpenCode Zen's client-identity spoofing) is configured like any other provider, not hardcoded by name. - Track per-(provider, model) reliability/speed/latency health in memory, seeded from the existing gateway_usage_ledger at startup - purely observational, never influences routing. - New Stats tab on /admin/gateway: request volume, latency, per-model breakdowns, and reliability weight, charted with a vendored Chart.js and devplace's own theme tokens. - Record which model a failed request actually fell back to (fallback_used_route), surfaced in the Recent Failures table. - Stop excluding context_length errors from fallback, and skip a primary attempt outright when its known context window is already too small for the estimated request size, going straight to the fallback. - gateway_usage_ledger's provider/fallback_used_route columns and indexes are ensured centrally in database/schema.py's init_db(), the single point of truth for this table's schema. - Non-OpenAI upstream routing and client-model passthrough; trust only the upstream's own X-Gateway-Model header for served-model attribution. Devii agent: - Fix a real lockup: plan/verify tools could be individually disabled via the admin tool toggles while still being required by the protocol gate, permanently bricking any task that needed tools. They can no longer be disabled, and the gate now also checks the tool is actually offered. - Fix compaction being silently calibrated for a 1M-token model while running a much smaller one: context budget is now percentage-based and the summarizer's own request is sized to fit the real model. - Give a specific, actionable retry message when plan()'s own arguments get cut off by the output limit, and tighten its schema to discourage overlong plans. Other: - Backup service: offload completed backups to a remote Hetzner Storage Box. - Container manager: fix orphan blob leaks from sync races, add a two-phase plan/execute `system prune` CLI command. - Admin gateway UI: replace the JS-rendered model/provider tables with server-rendered forms and pages. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DhmEkvutuwtzFVcLbTrhdo
83 lines
2.4 KiB
Python
83 lines
2.4 KiB
Python
# retoor <retoor@molodetz.nl>
|
|
|
|
import requests
|
|
|
|
from tests.api.admin.gateway.index import JSON_gateway, admin_session, member_key
|
|
from tests.conftest import BASE_URL
|
|
|
|
|
|
def test_stats_tab_renders_for_admin(seeded_db):
|
|
admin = admin_session(seeded_db)
|
|
response = admin.get(
|
|
f"{BASE_URL}/admin/gateway?tab=stats", headers={"Accept": "text/html"}
|
|
)
|
|
assert response.status_code == 200
|
|
assert "Model pool" in response.text
|
|
assert "Model routes" not in response.text
|
|
|
|
|
|
def test_stats_data_requires_admin(seeded_db):
|
|
assert (
|
|
requests.get(
|
|
f"{BASE_URL}/admin/gateway/stats/data", headers=JSON_gateway, allow_redirects=False
|
|
).status_code
|
|
== 401
|
|
)
|
|
key = member_key()
|
|
assert (
|
|
requests.get(
|
|
f"{BASE_URL}/admin/gateway/stats/data",
|
|
headers={**JSON_gateway, "X-API-KEY": key},
|
|
allow_redirects=False,
|
|
).status_code
|
|
== 403
|
|
)
|
|
|
|
|
|
def test_stats_data_shape_for_admin(seeded_db):
|
|
admin = admin_session(seeded_db)
|
|
response = admin.get(f"{BASE_URL}/admin/gateway/stats/data?range=24h", headers=JSON_gateway)
|
|
assert response.status_code == 200
|
|
data = response.json()
|
|
for key in (
|
|
"totals",
|
|
"per_model",
|
|
"per_endpoint",
|
|
"per_provider",
|
|
"timeseries",
|
|
"status_codes",
|
|
"streaming_split",
|
|
"failure_reasons",
|
|
"hourly_distribution",
|
|
"recent_failures",
|
|
"latency_histogram",
|
|
"tokens_per_second_histogram",
|
|
"bucket_seconds",
|
|
):
|
|
assert key in data
|
|
|
|
|
|
def test_stats_data_rejects_unknown_range(seeded_db):
|
|
admin = admin_session(seeded_db)
|
|
response = admin.get(f"{BASE_URL}/admin/gateway/stats/data?range=nonsense", headers=JSON_gateway)
|
|
assert response.status_code == 400
|
|
|
|
|
|
def test_stats_models_returns_a_list(seeded_db):
|
|
admin = admin_session(seeded_db)
|
|
response = admin.get(f"{BASE_URL}/admin/gateway/stats/models", headers=JSON_gateway)
|
|
assert response.status_code == 200
|
|
assert isinstance(response.json()["models"], list)
|
|
|
|
|
|
def test_stats_model_detail_for_an_unknown_model(seeded_db):
|
|
admin = admin_session(seeded_db)
|
|
response = admin.get(
|
|
f"{BASE_URL}/admin/gateway/stats/model/default/never-called-model?range=24h",
|
|
headers=JSON_gateway,
|
|
)
|
|
assert response.status_code == 200
|
|
data = response.json()
|
|
assert data["summary"]["total_requests"] == 0
|
|
assert data["health"] is None
|