feat(webui): simplify model preset settings (#5061)

This commit is contained in:
chengyongru
2026-07-24 00:55:06 +08:00
committed by GitHub
parent d993c81f08
commit aae259c790
29 changed files with 4548 additions and 1182 deletions
+65 -13
View File
@@ -11,6 +11,22 @@ from nanobot.webui.http_utils import http_json_response
from nanobot.webui.settings_routes import WebUISettingsRouter
def _router(*, authorized: bool = True) -> WebUISettingsRouter:
return WebUISettingsRouter(
bus=SimpleNamespace(),
logger=SimpleNamespace(exception=lambda *_args: None),
check_api_token=lambda _request: authorized,
parse_query=lambda path: parse_qs(urlsplit(path).query),
json_response=http_json_response,
error_response=lambda status, message: http_json_response(
{"error": message},
status=status,
),
runtime_surface="browser",
runtime_capabilities={},
)
@pytest.mark.asyncio
async def test_xai_oauth_completion_reads_code_from_private_header(monkeypatch) -> None:
captured: dict[str, object] = {}
@@ -24,19 +40,7 @@ async def test_xai_oauth_completion_reads_code_from_private_header(monkeypatch)
}
monkeypatch.setattr("nanobot.webui.settings_routes.complete_oauth_provider", complete)
router = WebUISettingsRouter(
bus=SimpleNamespace(),
logger=SimpleNamespace(exception=lambda *_args: None),
check_api_token=lambda _request: True,
parse_query=lambda path: parse_qs(urlsplit(path).query),
json_response=http_json_response,
error_response=lambda status, message: http_json_response(
{"error": message},
status=status,
),
runtime_surface="browser",
runtime_capabilities={},
)
router = _router()
request = SimpleNamespace(
path=(
"/api/settings/provider/oauth-login/complete"
@@ -70,3 +74,51 @@ async def test_xai_oauth_completion_reads_code_from_private_header(monkeypatch)
"authorization_code": "secret",
}
assert "secret" not in request.path
@pytest.mark.parametrize(
("request_path", "route_path", "function_name", "expected_query"),
[
(
"/api/settings/model-configurations/delete?name=spare",
"/api/settings/model-configurations/delete",
"delete_model_configuration",
{"name": ["spare"]},
),
(
"/api/settings/model-configurations/migrate",
"/api/settings/model-configurations/migrate",
"migrate_model_configurations",
{},
),
(
"/api/settings/model-call-order/update?order=%5B%22backup%22%5D",
"/api/settings/model-call-order/update",
"update_model_call_order",
{"order": ['["backup"]']},
),
],
)
@pytest.mark.asyncio
async def test_model_preset_mutation_routes(
monkeypatch,
request_path: str,
route_path: str,
function_name: str,
expected_query: dict[str, list[str]],
) -> None:
captured: dict[str, object] = {}
def mutate(query):
captured["query"] = query
return {"routed": function_name}
monkeypatch.setattr(f"nanobot.webui.settings_routes.{function_name}", mutate)
request = SimpleNamespace(path=request_path, headers=Headers())
response = await _router().dispatch(None, request, route_path)
assert response is not None
assert response.status_code == 200
assert json.loads(response.body)["routed"] == function_name
assert captured["query"] == expected_query