fix: parse nested image generation tasks
This commit is contained in:
@@ -1,6 +1,11 @@
|
||||
import pytest
|
||||
|
||||
from app.integrations.openai_compatible import OpenAICompatibleGateway
|
||||
from app.integrations.openai_compatible import (
|
||||
extract_task_id,
|
||||
safe_response_diagnostic,
|
||||
unwrap_media_status,
|
||||
)
|
||||
from app.runtime_settings import (
|
||||
RuntimeSettingsTestResult,
|
||||
_verify_generated_image,
|
||||
@@ -234,3 +239,44 @@ async def test_generated_image_url_rejects_html_placeholder(monkeypatch) -> None
|
||||
|
||||
with pytest.raises(ValueError, match="不是可识别的图片"):
|
||||
await _verify_generated_image(("url", "https://cdn.example.com/not-image"))
|
||||
|
||||
|
||||
def test_response_diagnostic_keeps_errors_but_redacts_payloads() -> None:
|
||||
diagnostic = safe_response_diagnostic(
|
||||
{
|
||||
"code": 402,
|
||||
"error": {"message": "insufficient balance"},
|
||||
"data": [{"b64_json": "secret-image-bytes", "url": "https://private.example"}],
|
||||
}
|
||||
)
|
||||
|
||||
rendered = str(diagnostic)
|
||||
assert "insufficient balance" in rendered
|
||||
assert "secret-image-bytes" not in rendered
|
||||
assert "https://private.example" not in rendered
|
||||
|
||||
|
||||
def test_extract_task_id_accepts_aggregator_nested_response() -> None:
|
||||
payload = {
|
||||
"code": 200,
|
||||
"data": {"task_id": 91584074, "task_ids": [91584074]},
|
||||
"msg": "Task created successfully",
|
||||
}
|
||||
|
||||
assert extract_task_id(payload) == 91584074
|
||||
|
||||
|
||||
def test_unwrap_media_status_accepts_nested_data() -> None:
|
||||
payload = {
|
||||
"code": 200,
|
||||
"data": {
|
||||
"state": "success",
|
||||
"is_final": True,
|
||||
"result_url": "https://cdn.example.com/result.png",
|
||||
},
|
||||
}
|
||||
|
||||
status = unwrap_media_status(payload)
|
||||
|
||||
assert status["is_final"] is True
|
||||
assert status["result_url"].endswith("result.png")
|
||||
|
||||
Reference in New Issue
Block a user