feat(suite): confirm AI writing cost before request
This commit is contained in:
+31
-1
@@ -8,7 +8,7 @@ os.environ.setdefault("QT_QPA_PLATFORM", "offscreen")
|
||||
|
||||
from _helpers import REPO_ROOT # noqa: F401
|
||||
|
||||
from app import db, image_studio, image_studio_images, workers
|
||||
from app import cmhub_models, db, image_studio, image_studio_images, workers
|
||||
|
||||
if workers.QT_IMPORT_ERROR is not None:
|
||||
raise unittest.SkipTest("PySide6 未安装")
|
||||
@@ -18,6 +18,7 @@ from PySide6.QtWidgets import QApplication
|
||||
|
||||
from app.workers import BaseWorker, run_worker
|
||||
from app.gui.workers import (
|
||||
CMHubModelCatalogWorker,
|
||||
ImageStudioDownloadOriginalWorker,
|
||||
ImageStudioPullImagesWorker,
|
||||
ProductSuiteAiWriteWorker,
|
||||
@@ -230,6 +231,35 @@ class WorkerTests(unittest.TestCase):
|
||||
gen_title.assert_not_called()
|
||||
self.assertEqual(expected, result)
|
||||
|
||||
def test_cmhub_model_catalog_worker_caches_models_without_exposing_key(self):
|
||||
cmhub_models.clear_model_catalog_cache()
|
||||
self.addCleanup(cmhub_models.clear_model_catalog_cache)
|
||||
worker = CMHubModelCatalogWorker(
|
||||
"https://cmhub.example.com/",
|
||||
"sk-cmhub-secret",
|
||||
connect_timeout=7,
|
||||
use_system_proxy=True,
|
||||
)
|
||||
models = [{"alias": "vision-standard", "operation_type": "vision"}]
|
||||
|
||||
with mock.patch("app.gui.workers.ai.fetch_cmhub_models", return_value=models) as fetch:
|
||||
result = worker.execute()
|
||||
|
||||
fetch.assert_called_once_with(
|
||||
"https://cmhub.example.com",
|
||||
"sk-cmhub-secret",
|
||||
connect_timeout=7,
|
||||
use_system_proxy=True,
|
||||
)
|
||||
self.assertEqual(models, result["models"])
|
||||
self.assertEqual(
|
||||
models,
|
||||
cmhub_models.cached_model_catalog(
|
||||
"https://cmhub.example.com",
|
||||
"vision-standard",
|
||||
),
|
||||
)
|
||||
|
||||
def test_product_suite_history_export_worker_uses_round_export_service(self):
|
||||
worker = ProductSuiteHistoryExportWorker(
|
||||
7,
|
||||
|
||||
Reference in New Issue
Block a user