feat(settings): rename custom gateway models

This commit is contained in:
chengma
2026-07-21 09:23:08 +08:00
parent 0da2d8a3c0
commit d76a1de864
6 changed files with 238 additions and 3 deletions
+42
View File
@@ -565,6 +565,48 @@ class AppConfigTests(TempDirMixin, unittest.TestCase):
self.assert_removed(temp_dir)
def test_rename_ai_model_preserves_fields_and_rejects_invalid_name(self):
with self.make_temp_dir() as temp_dir:
models_path = os.path.join(temp_dir, "ai_models.json")
appconfig.add_ai_model(
{
"name": "Text 2",
"category": "text",
"enabled": False,
"url": "https://example.invalid/v1/chat/completions",
"model": "demo-model",
"api_key": "sk-1234567890",
"api_type": "chat",
"connect_timeout_seconds": 12,
"timeout_seconds": 45,
"extra_body": {"temperature": 0},
},
path=models_path,
)
before = appconfig.get_model("Text 2", path=models_path)
renamed = appconfig.rename_ai_model(
"Text 2",
" 文本模型 ",
path=models_path,
)
self.assertEqual("文本模型", renamed["name"])
self.assertEqual(
{**before, "name": "文本模型"},
appconfig.get_model("文本模型", path=models_path),
)
with self.assertRaisesRegex(appconfig.ConfigError, "模型名称不能为空"):
appconfig.rename_ai_model("文本模型", " ", path=models_path)
with self.assertRaisesRegex(appconfig.ConfigError, "模型名称已存在"):
appconfig.rename_ai_model(
"文本模型",
"GPT-5.5 文本",
path=models_path,
)
self.assert_removed(temp_dir)
def test_ai_model_constraints_and_connection_validation(self):
with self.make_temp_dir() as temp_dir:
models_path = os.path.join(temp_dir, "ai_models.json")