include_unconfigured was hardcoded True in _handle_model_options, so external API consumers had no way to request the explicit-only view. Forward the include_unconfigured query param (default true, back-compatible) to build_model_options_payload. With _append_unconfigured_rows now honoring model_catalog.excluded_providers, this endpoint no longer resurrects excluded providers on any view (#68816). Also lifts model_options decoding (_request_reasoning_config / _request_service_tier) into gateway/platforms/api_server_request_options.py to offset api_server.py's frozen line cap (moved code keeps its cap; the facade re-exports both names).
51 lines
2.0 KiB
Python
51 lines
2.0 KiB
Python
"""GET /api/model/options must forward ``include_unconfigured`` from the query
|
|
string (default true) to ``build_model_options_payload`` instead of hardcoding
|
|
it — external API consumers need a way to request the explicit-only view, and the
|
|
unconfigured-row path must honor ``model_catalog.excluded_providers``
|
|
(#68816)."""
|
|
|
|
from unittest.mock import patch
|
|
|
|
import pytest
|
|
from aiohttp import web
|
|
from aiohttp.test_utils import TestClient, TestServer
|
|
|
|
from gateway.config import PlatformConfig
|
|
from gateway.platforms.api_server import APIServerAdapter
|
|
|
|
|
|
def _make_adapter() -> APIServerAdapter:
|
|
return APIServerAdapter(PlatformConfig(enabled=True))
|
|
|
|
|
|
def _create_app(adapter: APIServerAdapter) -> web.Application:
|
|
"""Minimal app exposing only the route under test (no key configured → auth passes)."""
|
|
app = web.Application()
|
|
app.router.add_get("/api/model/options", adapter._handle_model_options)
|
|
return app
|
|
|
|
|
|
async def _captured_include_unconfigured(adapter, query: str) -> tuple[int, bool]:
|
|
app = _create_app(adapter)
|
|
with patch("hermes_cli.inventory.load_picker_context", return_value=object()), \
|
|
patch("hermes_cli.inventory.build_model_options_payload",
|
|
return_value={"providers": []}) as build:
|
|
async with TestClient(TestServer(app)) as cli:
|
|
response = await cli.get(f"/api/model/options{query}")
|
|
return response.status, bool(build.call_args.kwargs.get("include_unconfigured"))
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_default_keeps_unconfigured_rows():
|
|
status, flag = await _captured_include_unconfigured(_make_adapter(), "")
|
|
assert status == 200
|
|
assert flag is True, "default (no query param) must stay include_unconfigured=True"
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_false_query_param_disables_unconfigured_rows():
|
|
status, flag = await _captured_include_unconfigured(
|
|
_make_adapter(), "?include_unconfigured=false")
|
|
assert status == 200
|
|
assert flag is False, "explicit include_unconfigured=false must reach the payload builder"
|