fix(settings): use a setup template for ShengSuanYun

This commit is contained in:
Xubin Ren committed 2026-11-14 20:44:28 +08:00
1 parent eb1df4d7b1
commit 221e121387
13 files changed
+142 -239

No files matched your search

+41
View File
@@ -17,6 +17,7 @@ from nanobot.llm_usage.models import LLMCallRecord
from nanobot.providers.base import LLMUsage
from nanobot.providers.oauth_model_catalog import OAuthModelCatalogSnapshot
from nanobot.providers.registry import ProviderModelSpec, find_by_name
from nanobot.providers.routing import resolve_provider_route
from nanobot.session.manager import SessionManager
from nanobot.session.model_selection import SESSION_MODEL_PRESET_METADATA_KEY
from nanobot.webui.settings_api import (
@@ -2885,6 +2886,46 @@ def test_custom_connection_api_create_edit_and_preset_ceiling(tmp_path, monkeypa
assert load_config(config_path).providers.model_extra[key].api is None
@pytest.mark.parametrize("legacy_key", ["shengsuanyun_router", "shengsuanyun-router"])
def test_setup_template_keeps_existing_provider_with_matching_name(tmp_path, monkeypatch, legacy_key):
config_path = tmp_path / "config.json"
legacy_config = {
"providers": {legacy_key: {
"apiBase": "https://legacy.example/api",
"apiKey": "legacy-key",
"api": {"supportedApis": ["anthropic_messages"]},
}},
"agents": {"defaults": {"model": "anthropic/old-model", "provider": legacy_key}},
}
config_path.write_text(json.dumps(legacy_config), encoding="utf-8")
before = load_config(config_path)
monkeypatch.setattr("nanobot.config.loader._current_config_path", config_path)
payload = create_provider_settings({
"name": ["ShengSuanYun Router 2"],
"apiBase": ["https://router.shengsuanyun.com/api/v1"],
"apiKey": ["new-key"],
"api": [json.dumps({
"supportedApis": ["chat_completions", "responses"], "preferredApi": "chat_completions",
})],
})
key = payload["created_provider"]
saved = load_config(config_path)
assert saved.get_provider_name() == legacy_key
assert saved.get_provider() == before.get_provider()
assert resolve_provider_route(saved, preset=saved.resolve_preset()).backend == "anthropic"
def fake_get(url: str, **kwargs):
assert url == "https://router.shengsuanyun.com/api/v1/models"
assert kwargs["headers"]["Authorization"] == "Bearer new-key"
return httpx.Response(200, json={"data": [{"id": "deepseek/deepseek-v4-flash"}]},
request=httpx.Request("GET", url))
monkeypatch.setattr("nanobot.webui.settings_api.httpx.get", fake_get)
catalog = provider_models_payload({"provider": [key]})
assert catalog["models"][0]["id"] == "deepseek/deepseek-v4-flash"
@pytest.mark.parametrize("api", [
{"supportedApis": []},
{"supportedApis": ["responses"], "preferredApi": "anthropic_messages"},