feat(ai): enforce direct image edit contract
This commit is contained in:
+74
-1
@@ -2232,6 +2232,7 @@ class GuiTests(TempDirMixin, unittest.TestCase):
|
||||
with self.make_temp_dir() as temp_dir:
|
||||
cfg = self.make_config(temp_dir)
|
||||
models_path = cfg["ai_models_path"]
|
||||
statuses = []
|
||||
appconfig.save_ai_models_config(
|
||||
{
|
||||
"models": [
|
||||
@@ -2264,7 +2265,11 @@ class GuiTests(TempDirMixin, unittest.TestCase):
|
||||
path=models_path,
|
||||
)
|
||||
|
||||
tab = SettingsTab(config=cfg, ai_models_path=models_path)
|
||||
tab = SettingsTab(
|
||||
config=cfg,
|
||||
ai_models_path=models_path,
|
||||
status_callback=statuses.append,
|
||||
)
|
||||
self.addCleanup(tab.close)
|
||||
|
||||
self.assertEqual(2, tab.model_combo.count())
|
||||
@@ -2523,6 +2528,74 @@ class GuiTests(TempDirMixin, unittest.TestCase):
|
||||
|
||||
self.assert_removed(temp_dir)
|
||||
|
||||
def test_settings_tab_image_model_only_offers_image_edit_and_checks_locally(self):
|
||||
with self.make_temp_dir() as temp_dir:
|
||||
cfg = self.make_config(temp_dir)
|
||||
models_path = cfg["ai_models_path"]
|
||||
statuses = []
|
||||
appconfig.save_ai_models_config(
|
||||
{
|
||||
"models": [
|
||||
{
|
||||
"name": "Text A",
|
||||
"category": "text",
|
||||
"enabled": True,
|
||||
"url": "https://example.invalid/v1",
|
||||
"model": "text-model",
|
||||
"api_key": "sk-text",
|
||||
"api_type": "chat",
|
||||
"connect_timeout_seconds": 30,
|
||||
"timeout_seconds": 0,
|
||||
"extra_body": {},
|
||||
},
|
||||
{
|
||||
"name": "Legacy Image",
|
||||
"category": "image",
|
||||
"enabled": True,
|
||||
"url": "https://example.invalid/v1/chat/completions",
|
||||
"model": "image-model",
|
||||
"api_key": "sk-image",
|
||||
"api_type": "auto",
|
||||
"connect_timeout_seconds": 30,
|
||||
"timeout_seconds": 0,
|
||||
"extra_body": {},
|
||||
},
|
||||
]
|
||||
},
|
||||
path=models_path,
|
||||
)
|
||||
tab = SettingsTab(
|
||||
config=cfg,
|
||||
ai_models_path=models_path,
|
||||
status_callback=statuses.append,
|
||||
)
|
||||
self.addCleanup(tab.close)
|
||||
tab.model_combo.setCurrentIndex(tab.model_combo.findData("Legacy Image"))
|
||||
|
||||
self.assertIn("当前图片模型不支持 OpenAI 图片编辑接口", tab.model_combo.currentText())
|
||||
self.assertEqual("auto", tab.api_type_combo.currentData())
|
||||
self.assertEqual("检查图片配置", tab.test_connection_button.text())
|
||||
self.assertIn("当前不支持", tab.api_type_combo.currentText())
|
||||
|
||||
class FakeSignal:
|
||||
def connect(self, callback):
|
||||
self.callback = callback
|
||||
|
||||
class FakeThread:
|
||||
def __init__(self):
|
||||
self.finished = FakeSignal()
|
||||
|
||||
def start(self):
|
||||
pass
|
||||
|
||||
with mock.patch("app.gui.run_worker", return_value=FakeThread()):
|
||||
tab.test_connection()
|
||||
|
||||
self.assertTrue(tab.test_worker.check_image_config)
|
||||
self.assertIn("正在检查图片模型配置", statuses[-1])
|
||||
|
||||
self.assert_removed(temp_dir)
|
||||
|
||||
def test_settings_tab_saves_role_generation_path_and_port_config(self):
|
||||
with self.make_temp_dir() as temp_dir:
|
||||
cfg = self.make_config(temp_dir)
|
||||
|
||||
Reference in New Issue
Block a user