Files
devplacepy/tests/e2e/openai/v1/embeddings.py
T
retoorandClaude Sonnet 5.5 f55c7ee5f4
DevPlace CI / test (push) Failing after 31m42s
Add community node protocol spec, Agent Skills, and make the failing tests hermetic
Community nodes (Phase 1 of plan.md): the protocol specification in
services/nodes/spec.py as the single source of truth, GET /nodes/spec.json,
a generated protocol docs page, the Community nodes API docs group, and the
implementation plan plus the residential proxy research. The no-open-proxy rule
is enforced in the spec (open_proxy cannot be set).

Agent Skills: register the Skills API docs group, cascade skills on account
deletion, add the nested CLAUDE.md, README and routes docs, and cover the
parser, the fetcher (end to end against a mock origin), the data layer and the
routes with 73 unit and 16 api tests.

Tests made hermetic with the repo's existing patterns instead of ambient
environment: embeddings tests set OPENROUTER_API_KEY via monkeypatch, the
workspace tests install FakeBackend via runtime.set_backend, and the skills
install tests use run_async. DockerCliBackend now returns 127 (command not
found) when the CLI is missing instead of raising FileNotFoundError, so a host
without docker answers with a clean error rather than a 500. The Providers tab
empty state no longer names the Model routes tab.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-14 07:13:25 +02:00

90 lines
2.9 KiB
Python

# retoor <retoor@molodetz.nl>
import requests
from tests.conftest import BASE_URL
from devplacepy.database import get_table
def _config(page, **fields):
page.request.post(f"{BASE_URL}/admin/services/openai/config", form=fields)
def _grant_ai_consent(page, username):
page.request.post(
f"{BASE_URL}/profile/{username}/consent",
form={"kind": "ai_third_party", "granted": "1"},
)
def test_embeddings_disabled_returns_503(alice):
page, _ = alice
page.request.post(f"{BASE_URL}/admin/services/openai/stop")
try:
r = requests.post(
f"{BASE_URL}/openai/v1/embeddings", json={"input": "hello"}
)
assert r.status_code == 503
finally:
page.request.post(f"{BASE_URL}/admin/services/openai/start")
def test_embeddings_requires_auth(alice):
page, _ = alice
page.request.post(f"{BASE_URL}/admin/services/openai/start")
_config(page, gateway_access_key="embedkey")
try:
no_creds = requests.post(
f"{BASE_URL}/openai/v1/embeddings", json={"input": "hello"}
)
assert no_creds.status_code == 401
finally:
_config(page, gateway_access_key="")
page.request.post(f"{BASE_URL}/admin/services/openai/start")
def test_embeddings_auth_passes_upstream_unreachable(alice):
page, user = alice
page.request.post(f"{BASE_URL}/admin/services/openai/start")
_config(
page,
gateway_embed_enabled="1",
gateway_embed_url="http://127.0.0.1:9/embeddings",
gateway_embed_key="test-embed-key",
gateway_access_key="embedkey",
)
try:
with_key = requests.post(
f"{BASE_URL}/openai/v1/embeddings",
headers={"X-API-KEY": "embedkey"},
json={"model": "molodetz~embed", "input": "hello"},
)
assert with_key.status_code == 502
admin_key = get_table("users").find_one(username=user["username"])["api_key"]
_grant_ai_consent(page, user["username"])
with_admin = requests.post(
f"{BASE_URL}/openai/v1/embeddings",
headers={"Authorization": f"Bearer {admin_key}"},
json={"model": "molodetz~embed", "input": "hello"},
)
assert with_admin.status_code == 502
finally:
_config(page, gateway_access_key="", gateway_embed_key="")
page.request.post(f"{BASE_URL}/admin/services/openai/start")
def test_embeddings_disabled_via_config_returns_503(alice):
page, _ = alice
page.request.post(f"{BASE_URL}/admin/services/openai/start")
_config(page, gateway_embed_enabled="0", gateway_access_key="embedkey")
try:
r = requests.post(
f"{BASE_URL}/openai/v1/embeddings",
headers={"X-API-KEY": "embedkey"},
json={"input": "hello"},
)
assert r.status_code == 503
finally:
_config(page, gateway_embed_enabled="1", gateway_access_key="")
page.request.post(f"{BASE_URL}/admin/services/openai/start")