mirror of
https://github.com/headroomlabs-ai/headroom.git
synced 2026-11-22 13:29:19 +08:00
fix(providers): drop the shadowed POST /v1/messages route spec
register_provider_routes registers POST /v1/messages explicitly (the handler that honours x-headroom-base-url) and then again from ANTHROPIC_HANDLER_ROUTES. Starlette dispatches to the first match, so the spec route never ran; editing it would silently change nothing. Remove the spec and add a test that the registered app has no duplicate (method, path) pairs. Evidence: building the app listed POST /v1/messages twice (routes 4 and 21) and no other duplicate. ANTHROPIC_HANDLER_ROUTES had no other readers. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Assisted-by: claude-code:claude-opus-5-5 Headline-Session: 6e77a807-8dd4-4a77-a2fa-ddce6dc2515e Headline-AI-Share: 100% strict / 100% weighted
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
a9815bbb5f
commit
024a37a67f
@@ -77,11 +77,6 @@ PROVIDER_PASSTHROUGH_ROUTES: tuple[ProviderPassthroughRoute, ...] = (
|
||||
)
|
||||
|
||||
|
||||
ANTHROPIC_HANDLER_ROUTES: tuple[ProviderHandlerRoute, ...] = (
|
||||
ProviderHandlerRoute("POST", "/v1/messages", "handle_anthropic_messages"),
|
||||
)
|
||||
|
||||
|
||||
ANTHROPIC_BATCH_ROUTES: tuple[ProviderHandlerRoute, ...] = (
|
||||
ProviderHandlerRoute("POST", "/v1/messages/batches", "handle_anthropic_batch_create"),
|
||||
ProviderHandlerRoute("GET", "/v1/messages/batches", "handle_anthropic_batch_passthrough"),
|
||||
@@ -206,7 +201,6 @@ CLOUDCODE_HANDLER_ROUTES: tuple[ProviderHandlerRoute, ...] = (
|
||||
|
||||
|
||||
PROVIDER_HANDLER_ROUTES: tuple[ProviderHandlerRoute, ...] = (
|
||||
*ANTHROPIC_HANDLER_ROUTES,
|
||||
*ANTHROPIC_BATCH_ROUTES,
|
||||
*OPENAI_HANDLER_ROUTES,
|
||||
*OPENAI_BATCH_ROUTES,
|
||||
|
||||
@@ -1,8 +1,13 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from collections import Counter
|
||||
from types import SimpleNamespace
|
||||
|
||||
from fastapi import FastAPI
|
||||
|
||||
from headroom.providers.proxy_routes import register_provider_routes
|
||||
from headroom.providers.route_specs import (
|
||||
ANTHROPIC_BATCH_ROUTES,
|
||||
ANTHROPIC_HANDLER_ROUTES,
|
||||
ANTHROPIC_PASSTHROUGH_ROUTES,
|
||||
CLOUDCODE_HANDLER_ROUTES,
|
||||
GEMINI_BATCH_ROUTES,
|
||||
@@ -30,6 +35,21 @@ def test_provider_handler_route_specs_are_unique() -> None:
|
||||
assert len(route_keys) == len(PROVIDER_HANDLER_ROUTES)
|
||||
|
||||
|
||||
def test_registered_provider_routes_are_unique() -> None:
|
||||
"""A second route for the same method and path is shadowed by the first and never runs."""
|
||||
app = FastAPI()
|
||||
proxy = SimpleNamespace(config=SimpleNamespace(bedrock_api_url="https://bedrock.example.test"))
|
||||
register_provider_routes(app, proxy)
|
||||
|
||||
seen: Counter[tuple[str, str]] = Counter()
|
||||
for route in app.router.routes:
|
||||
for method in getattr(route, "methods", None) or {"WEBSOCKET"}:
|
||||
seen[(method, route.path)] += 1
|
||||
|
||||
assert seen[("POST", "/v1/messages")] == 1
|
||||
assert [key for key, count in seen.items() if count > 1] == []
|
||||
|
||||
|
||||
def test_openai_passthrough_routes_model_endpoint_intent() -> None:
|
||||
assert OPENAI_PASSTHROUGH_ROUTES == (
|
||||
ProviderPassthroughRoute("POST", "/v1/embeddings", "openai", "embeddings"),
|
||||
@@ -79,9 +99,6 @@ def test_gemini_passthrough_routes_model_endpoint_intent() -> None:
|
||||
|
||||
|
||||
def test_direct_handler_routes_model_endpoint_intent() -> None:
|
||||
assert ANTHROPIC_HANDLER_ROUTES == (
|
||||
ProviderHandlerRoute("POST", "/v1/messages", "handle_anthropic_messages"),
|
||||
)
|
||||
assert OPENAI_HANDLER_ROUTES == (
|
||||
ProviderHandlerRoute("POST", "/v1/chat/completions", "handle_openai_chat"),
|
||||
ProviderHandlerRoute("POST", "/chat/completions", "handle_openai_chat"),
|
||||
|
||||
Reference in New Issue
Block a user