Files
devplacepy/tests/api/admin/services/devii_tools.py
T
retoorandClaude Sonnet 5 569f1dcc64 Add OpenCode Zen support, model health/stats dashboard, and gateway fallback fixes
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
2026-09-09 07:38:24 +02:00

116 lines
3.2 KiB
Python

# retoor <retoor@molodetz.nl>
import time
import pytest
import requests
from tests.conftest import BASE_URL
from devplacepy.database import clear_settings_cache, get_table, refresh_snapshot
from devplacepy.services.devii import tool_prefs
JSON = {"Accept": "application/json"}
_counter = [0]
@pytest.fixture(scope="module", autouse=True)
def _settings(app_server):
from devplacepy.database import set_setting
set_setting("rate_limit_per_minute", "1000000")
set_setting("registration_open", "1")
yield
def _admin(seeded_db):
refresh_snapshot()
key = get_table("users").find_one(username="alice_test")["api_key"]
s = requests.Session()
s.headers.update({"X-API-KEY": key, **JSON})
return s
def _member():
_counter[0] += 1
name = f"dtmem{int(time.time() * 1000)}{_counter[0]}"
requests.post(
f"{BASE_URL}/auth/signup",
data={
"username": name,
"email": f"{name}@t.dev",
"password": "secret123",
"confirm_password": "secret123",
"birth_date": "1990-01-01",
"accept_terms": "1",
},
allow_redirects=True,
)
refresh_snapshot()
s = requests.Session()
s.headers.update(
{"X-API-KEY": get_table("users").find_one(username=name)["api_key"], **JSON}
)
return s
def _all_tool_names():
return set(tool_prefs.GROUPS_BY_TOOL_NAME)
def test_devii_service_page_has_tools_tab(seeded_db):
admin = _admin(seeded_db)
r = admin.get(f"{BASE_URL}/admin/services/devii")
assert r.status_code == 200
assert 'data-tab="tools"' in r.text
assert "devii-tools-form" in r.text
def test_other_service_page_has_no_tools_tab(seeded_db):
admin = _admin(seeded_db)
r = admin.get(f"{BASE_URL}/admin/services/news")
assert r.status_code == 200
assert 'data-tab="tools"' not in r.text
def test_admin_can_disable_and_reenable_a_tool(seeded_db):
admin = _admin(seeded_db)
all_names = _all_tool_names()
try:
enabled = sorted(all_names - {"create_post"})
r = admin.post(
f"{BASE_URL}/admin/services/devii/tools",
data=[("enabled", name) for name in enabled],
)
assert r.status_code == 200, r.text[:300]
assert r.json()["ok"] is True
clear_settings_cache()
assert tool_prefs.disabled_tool_names() == frozenset({"create_post"})
r2 = admin.post(
f"{BASE_URL}/admin/services/devii/tools",
data=[("enabled", name) for name in all_names],
)
assert r2.status_code == 200
clear_settings_cache()
assert tool_prefs.disabled_tool_names() == frozenset()
finally:
clear_settings_cache()
tool_prefs.set_disabled_tool_names(set())
def test_member_cannot_save_tool_config(app_server):
member = _member()
r = member.post(
f"{BASE_URL}/admin/services/devii/tools",
data={"enabled": "create_post"},
allow_redirects=False,
)
assert r.status_code in (302, 303, 403)
def test_guest_cannot_save_tool_config(app_server):
r = requests.post(
f"{BASE_URL}/admin/services/devii/tools",
data={"enabled": "create_post"},
allow_redirects=False,
)
assert r.status_code in (302, 303, 401)