fix: distinguish image connection and generation checks

This commit is contained in:
Codex
2026-08-01 23:55:56 +08:00
parent 52d877836c
commit 922f8f4f2a
5 changed files with 134 additions and 18 deletions
+65
View File
@@ -1,6 +1,7 @@
import pytest
from app.integrations.openai_compatible import OpenAICompatibleGateway
from app.runtime_settings import RuntimeSettingsTestResult, test_model_pool_item as run_model_pool_test
def image_values(profile: str, model_id: str) -> dict:
@@ -110,3 +111,67 @@ async def test_aigc_media_polls_task_until_result_url(monkeypatch) -> None:
assert result["state"] == "success"
assert result["data"] == [{"url": "https://cdn.example.com/final.png"}]
@pytest.mark.asyncio
async def test_aigc_media_connection_accepts_model_list_omission(monkeypatch) -> None:
class FakeResponse:
def raise_for_status(self) -> None:
return None
def json(self) -> dict:
return {"data": [{"id": "language-model-only"}]}
class FakeClient:
async def __aenter__(self):
return self
async def __aexit__(self, *args) -> None:
return None
async def get(self, *args, **kwargs) -> FakeResponse:
return FakeResponse()
monkeypatch.setattr("app.runtime_settings.httpx.AsyncClient", lambda **kwargs: FakeClient())
result = await run_model_pool_test(
image_values("gpt_image_2", "gpt-image-2"),
"image",
)
assert result.ok is True
assert result.details["id_advertised"] is False
assert result.details["verification"] == "connectivity_only"
assert "最终可用性以“试生成”为准" in result.message
@pytest.mark.asyncio
async def test_generation_endpoint_records_definitive_model_result(monkeypatch) -> None:
from app.api.settings import test_model_generation
class FakeStore:
def __init__(self) -> None:
self.recorded: list[RuntimeSettingsTestResult] = []
def merged_values(self) -> dict:
return image_values("gpt_image_2", "gpt-image-2")
def record_test(self, result: RuntimeSettingsTestResult, values: dict) -> None:
self.recorded.append(result)
async def fake_generation(values: dict, model_id: str) -> RuntimeSettingsTestResult:
return RuntimeSettingsTestResult(
target=f"generation:{model_id}",
ok=True,
message="端到端可用",
)
monkeypatch.setattr("app.api.settings.test_image_generation", fake_generation)
store = FakeStore()
result = await test_model_generation("image", store=store)
assert result.ok is True
assert [item.target for item in store.recorded] == ["generation:image", "model:image"]
assert store.recorded[1].ok is True
assert "真实生图端到端验证" in store.recorded[1].message