feat(ai): enforce direct image edit contract

This commit is contained in:
chengma
2026-07-20 17:52:59 +08:00
parent 61db0f4ed6
commit 2a2cbad7bd
11 changed files with 382 additions and 94 deletions
+34
View File
@@ -635,6 +635,40 @@ class AppConfigTests(TempDirMixin, unittest.TestCase):
),
)
def test_image_model_config_check_keeps_legacy_models_but_blocks_them_for_generation(self):
with self.make_temp_dir() as temp_dir:
models_path = os.path.join(temp_dir, "ai_models.json")
config = appconfig.default_ai_models_config()
legacy_image = config["models"][1]
legacy_image.update(
{
"url": "https://legacy.example.com/v1/chat/completions",
"model": "legacy-image",
"api_key": "sk-legacy-secret",
"api_type": "auto",
}
)
appconfig.save_ai_models_config(config, path=models_path)
loaded = appconfig.get_model("Nano Banana 2", path=models_path)
self.assertEqual("auto", loaded["api_type"])
result = appconfig.check_image_model_config("Nano Banana 2", path=models_path)
self.assertFalse(result["ok"])
self.assertTrue(result["check_only"])
self.assertIn("OpenAI 图片编辑接口", result["error"])
self.assertNotIn("sk-legacy-secret", result["error"])
appconfig.update_ai_model(
"Nano Banana 2",
path=models_path,
api_type="images_edits",
)
self.assertTrue(
appconfig.check_image_model_config("Nano Banana 2", path=models_path)["ok"]
)
self.assert_removed(temp_dir)
def test_ai_model_test_uses_resolved_base_url(self):
with self.make_temp_dir() as temp_dir:
models_path = os.path.join(temp_dir, "ai_models.json")