Send per-app provider attribution titles from one gateway app registry

Add openai_gateway/apps.py as the single list of internal gateway apps and
send X-OpenRouter-Title (plus legacy X-Title and HTTP-Referer) per app to
every upstream. Label the Devii agent, bots, modifier, quiz grading, SEO
metadata, community and sync callers. Shorten two app references that
exceeded the 30 character limit and were recorded as default.
Also includes the pending Muse Code, route health and Responses work.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-04 18:45:09 +01:00
co-authored by Claude Sonnet 5.5
parent ec30ed408c
commit bc11475f29
31 changed files with 2198 additions and 208 deletions
@@ -179,6 +179,87 @@ def test_resolve_fallback_ignores_a_fallback_of_a_different_kind(local_db):
_cleanup([], ["fb-primary-3", "fb-backup-embed"])
def _chain_route(source, target, fallback="", active=True):
r.model_store.set(
r.ModelRouteIn(
source_model=source,
target_model=target,
kind="chat",
fallback_model=fallback,
is_active=active,
)
)
def _mark_health(source, status):
from devplacepy.services.openai_gateway import health
code = "" if status == "ok" else "http_500"
message = "" if status == "ok" else "boom"
health.record_health(
source, health.ProbeResult(status == "ok", code, message, 1.0)
)
def test_fallback_chain_skips_bad_and_inactive_links(local_db):
_chain_route("chain-a", "v/a", "chain-b")
_chain_route("chain-b", "v/b", "chain-c")
_chain_route("chain-c", "v/c", "chain-d")
_chain_route("chain-d", "v/d", "", active=False)
_mark_health("chain-b", "bad")
try:
line = r.resolve_fallback_chain("chain-a", "chat")
assert [m.source_model for m in line] == ["chain-c"]
finally:
_cleanup([], ["chain-a", "chain-b", "chain-c", "chain-d"])
def test_fallback_chain_stops_on_cycles(local_db):
_chain_route("chain-e", "v/e", "chain-f")
_chain_route("chain-f", "v/f", "chain-e")
try:
line = r.resolve_fallback_chain("chain-e", "chat")
assert [m.source_model for m in line] == ["chain-f"]
finally:
_cleanup([], ["chain-e", "chain-f"])
def test_fallback_chain_respects_max_hops(local_db):
names = [f"chain-h{i}" for i in range(8)]
for pos, name in enumerate(names):
nxt = names[pos + 1] if pos + 1 < len(names) else ""
_chain_route(name, f"v/{name}", nxt)
try:
line = r.resolve_fallback_chain(names[0], "chat", max_hops=3)
assert [m.source_model for m in line] == names[1:4]
assert len(r.resolve_fallback_chain(names[0], "chat")) <= 5
finally:
_cleanup([], names)
def test_entry_route_preroutes_bad_models(local_db):
_chain_route("chain-g", "v/g", "chain-h")
_chain_route("chain-h", "v/h")
_mark_health("chain-g", "bad")
try:
assert r.resolve_entry_route("chain-g", "chat").source_model == "chain-h"
assert r.resolve_entry_route("chain-h", "chat").source_model == "chain-h"
assert r.resolve_entry_route("ghost-entry", "chat") is None
finally:
_cleanup([], ["chain-g", "chain-h"])
def test_entry_route_falls_back_to_original_when_line_is_empty(local_db):
_chain_route("chain-i", "v/i", "chain-j")
_chain_route("chain-j", "v/j")
_mark_health("chain-i", "bad")
_mark_health("chain-j", "bad")
try:
assert r.resolve_entry_route("chain-i", "chat").source_model == "chain-i"
finally:
_cleanup([], ["chain-i", "chain-j"])
def test_vision_merge_overlay(local_db):
r.provider_store.set(
r.ProviderIn(
@@ -362,6 +443,31 @@ def test_provider_without_a_client_profile_gets_no_extra_headers(local_db):
_cleanup(["plainprov"], ["ut-plain"])
def test_provider_with_a_muse_profile_gets_muse_headers(local_db):
r.provider_store.set(
r.ProviderIn(
name="meta",
base_url="https://api.meta.ai/v1/responses",
api_key="secret",
client_profile="muse",
)
)
r.model_store.set(
r.ModelRouteIn(
source_model="ut-muse",
provider="meta",
target_model="muse-spark",
)
)
try:
overlay = r.chat_overlay("ut-muse", {})
headers = overlay["gateway_extra_request_headers"]
assert headers["X-Client-Id"] == "tbh:exec"
assert headers["User-Agent"].startswith("muse-build/")
finally:
_cleanup(["meta"], ["ut-muse"])
def test_client_profile_rejects_unknown_value():
with pytest.raises(ValidationError):
r.ProviderIn(name="badprofile", client_profile="not-a-real-profile")