mirror of
https://github.com/headroomlabs-ai/headroom.git
synced 2026-08-27 14:17:10 -04:00
## Description Fixes #2492, #2028, and #2827. Claude daemon workers consume project settings rather than reliably inheriting wrapper environment state, while the Claude VS Code webview cannot render deferred-tool response blocks. Separately, recent Copilot Chat versions use the whole CAPI override for generation; the legacy proxy override alone only sends model discovery through Headroom. This PR carries both integrations through to the actual consumers instead of only changing their launch-time surface configuration. ## Type of Change - [x] Bug fix - [ ] New feature - [ ] Breaking change - [ ] Documentation update - [ ] Build / CI ## Changes Made - Persist the resolved Claude ENABLE_TOOL_SEARCH value into project settings for daemon workers and restore it transactionally after wrap exits. - Use compatibility-safe Foundry and Claude VS Code defaults while preserving explicit user choices. - Configure both Copilot overrideProxyUrl and overrideCapiUrl in the reversible managed VS Code settings block. - Route Copilot unprefixed POST /chat/completions and HTTP /responses requests through the real compression handlers. - Keep /responses out of the Codex WebSocket aliases because Copilot and Codex use different WebSocket wire protocols. - Extend wrap E2E assertions for both the Claude webview mode and Copilot CAPI routing. ## Testing - [x] 127 combined Claude, Copilot, route-integration, and MCP dependency-contract tests pass. - [x] Ruff check passes on all changed Python files. - [x] Ruff format check passes. - [x] Python compilation and git diff --check pass. ## Runtime Safety Standalone Claude CLI defaults remain unchanged. Explicit Claude tool-search values retain precedence, and project settings are restored through the existing cleanup path. Copilot model/session helper endpoints continue through generic passthrough, while only validated HTTP generation paths receive explicit compression routes. Existing Codex WebSocket behavior is unchanged. ## Review Readiness - [x] Current main and MCP v1 compatibility retained - [x] Worker-facing Claude persistence covered - [x] Reversible Copilot and Claude settings behavior covered - [x] Copilot generation routes covered at registration and proxy integration layers - [x] Ready for review
164 lines
4.9 KiB
Python
164 lines
4.9 KiB
Python
from __future__ import annotations
|
|
|
|
from headroom.providers.route_specs import (
|
|
ANTHROPIC_BATCH_ROUTES,
|
|
ANTHROPIC_HANDLER_ROUTES,
|
|
ANTHROPIC_PASSTHROUGH_ROUTES,
|
|
CLOUDCODE_HANDLER_ROUTES,
|
|
GEMINI_BATCH_ROUTES,
|
|
GEMINI_HANDLER_ROUTES,
|
|
GEMINI_PASSTHROUGH_ROUTES,
|
|
OPENAI_BATCH_ROUTES,
|
|
OPENAI_HANDLER_ROUTES,
|
|
OPENAI_PASSTHROUGH_ROUTES,
|
|
PROVIDER_HANDLER_ROUTES,
|
|
PROVIDER_PASSTHROUGH_ROUTES,
|
|
ProviderHandlerRoute,
|
|
ProviderPassthroughRoute,
|
|
)
|
|
|
|
|
|
def test_provider_passthrough_route_specs_are_unique() -> None:
|
|
route_keys = {(spec.method, spec.path) for spec in PROVIDER_PASSTHROUGH_ROUTES}
|
|
|
|
assert len(route_keys) == len(PROVIDER_PASSTHROUGH_ROUTES)
|
|
|
|
|
|
def test_provider_handler_route_specs_are_unique() -> None:
|
|
route_keys = {(spec.method, spec.path) for spec in PROVIDER_HANDLER_ROUTES}
|
|
|
|
assert len(route_keys) == len(PROVIDER_HANDLER_ROUTES)
|
|
|
|
|
|
def test_openai_passthrough_routes_model_endpoint_intent() -> None:
|
|
assert OPENAI_PASSTHROUGH_ROUTES == (
|
|
ProviderPassthroughRoute("POST", "/v1/embeddings", "openai", "embeddings"),
|
|
ProviderPassthroughRoute("POST", "/v1/moderations", "openai", "moderations"),
|
|
ProviderPassthroughRoute(
|
|
"POST",
|
|
"/v1/audio/transcriptions",
|
|
"openai",
|
|
"audio/transcriptions",
|
|
),
|
|
ProviderPassthroughRoute("POST", "/v1/audio/speech", "openai", "audio/speech"),
|
|
)
|
|
|
|
|
|
def test_anthropic_passthrough_routes_model_endpoint_intent() -> None:
|
|
assert ANTHROPIC_PASSTHROUGH_ROUTES == (
|
|
ProviderPassthroughRoute(
|
|
"POST",
|
|
"/v1/messages/count_tokens",
|
|
"anthropic",
|
|
"count_tokens",
|
|
),
|
|
)
|
|
|
|
|
|
def test_gemini_passthrough_routes_model_endpoint_intent() -> None:
|
|
assert (
|
|
ProviderPassthroughRoute(
|
|
"POST",
|
|
"/v1beta/models/{model}:batchEmbedContents",
|
|
"gemini",
|
|
"batchEmbedContents",
|
|
)
|
|
in GEMINI_PASSTHROUGH_ROUTES
|
|
)
|
|
assert (
|
|
ProviderPassthroughRoute(
|
|
"DELETE",
|
|
"/v1beta/cachedContents/{cache_id}",
|
|
"gemini",
|
|
"cachedContents",
|
|
)
|
|
in GEMINI_PASSTHROUGH_ROUTES
|
|
)
|
|
|
|
|
|
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"),
|
|
)
|
|
assert GEMINI_HANDLER_ROUTES == (
|
|
ProviderHandlerRoute(
|
|
"POST",
|
|
"/v1beta/models/{model}:generateContent",
|
|
"handle_gemini_generate_content",
|
|
"model",
|
|
),
|
|
ProviderHandlerRoute(
|
|
"POST",
|
|
"/v1beta/models/{model}:streamGenerateContent",
|
|
"handle_gemini_stream_generate_content",
|
|
"model",
|
|
),
|
|
ProviderHandlerRoute(
|
|
"POST",
|
|
"/v1beta/models/{model}:countTokens",
|
|
"handle_gemini_count_tokens",
|
|
"model",
|
|
),
|
|
)
|
|
assert CLOUDCODE_HANDLER_ROUTES == (
|
|
ProviderHandlerRoute(
|
|
"POST",
|
|
"/v1internal:streamGenerateContent",
|
|
"handle_google_cloudcode_stream",
|
|
),
|
|
ProviderHandlerRoute(
|
|
"POST",
|
|
"/v1/v1internal:streamGenerateContent",
|
|
"handle_google_cloudcode_stream",
|
|
),
|
|
)
|
|
|
|
|
|
def test_batch_handler_routes_model_endpoint_intent() -> None:
|
|
assert ANTHROPIC_BATCH_ROUTES[0] == ProviderHandlerRoute(
|
|
"POST",
|
|
"/v1/messages/batches",
|
|
"handle_anthropic_batch_create",
|
|
)
|
|
assert (
|
|
ProviderHandlerRoute(
|
|
"GET",
|
|
"/v1/messages/batches/{batch_id}/results",
|
|
"handle_anthropic_batch_results",
|
|
"batch_id",
|
|
)
|
|
in ANTHROPIC_BATCH_ROUTES
|
|
)
|
|
assert OPENAI_BATCH_ROUTES == (
|
|
ProviderHandlerRoute("POST", "/v1/batches", "handle_batch_create"),
|
|
ProviderHandlerRoute("GET", "/v1/batches", "handle_batch_list"),
|
|
ProviderHandlerRoute("GET", "/v1/batches/{batch_id}", "handle_batch_get", "batch_id"),
|
|
ProviderHandlerRoute(
|
|
"POST",
|
|
"/v1/batches/{batch_id}/cancel",
|
|
"handle_batch_cancel",
|
|
"batch_id",
|
|
),
|
|
)
|
|
assert (
|
|
ProviderHandlerRoute(
|
|
"POST",
|
|
"/v1beta/models/{model}:batchGenerateContent",
|
|
"handle_google_batch_create",
|
|
"model",
|
|
)
|
|
in GEMINI_BATCH_ROUTES
|
|
)
|
|
assert (
|
|
ProviderHandlerRoute(
|
|
"DELETE",
|
|
"/v1beta/batches/{batch_name}",
|
|
"handle_google_batch_passthrough",
|
|
"batch_name",
|
|
)
|
|
in GEMINI_BATCH_ROUTES
|
|
)
|