fix(webui): open the preset for blocked image input (#6724)

This commit is contained in:
chengyongru authored and GitHub committed 2026-11-19 18:39:00 +08:00
1 parent 607de63fb4
commit ce12bfdd0d
38 files changed
+430 -78

No files matched your search

+22
View File
@@ -123,10 +123,22 @@ async def test_no_image_capable_candidate_fails_without_sending_or_stripping(str
call = chain.chat_stream_with_retry if stream else chain.chat_with_retry
response = await call(messages=[{"role": "user", "content": [_IMAGE]}])
assert response.error_code == "unsupported_image"
assert LLMProvider.public_error_kind(response) == "unsupported_image"
assert response.error_should_retry is False
assert primary.calls == created == []
async def test_image_capable_fallback_reports_its_own_failure():
primary = ImageProvider(False)
fallback = ImageProvider(response=LLMResponse(
"upstream rejection", finish_reason="error", error_status_code=401, error_code="unsupported_image",
))
chain = FallbackProvider(primary, [ModelPresetConfig(model="vision")], lambda _: fallback)
response = await chain.chat_with_retry(messages=[{"role": "user", "content": [_IMAGE]}])
assert not primary.calls and len(fallback.calls) == 1
assert LLMProvider.public_error_kind(response) == "authentication"
@pytest.mark.parametrize("stream", [False, True])
async def test_declared_vision_does_not_hide_actual_upstream_rejection(stream):
upstream = LLMResponse("unsupported image format", finish_reason="error", error_status_code=400)
@@ -139,11 +151,21 @@ async def test_declared_vision_does_not_hide_actual_upstream_rejection(stream):
response = await call(messages=messages)
assert response.content == upstream.content
assert response.error_status_code == 400
assert LLMProvider.public_error_kind(response) == "image_request_rejected"
assert LLMProvider.public_error_kind(upstream) == "unknown"
assert len(primary.calls) == 1
assert created == []
assert messages == before
async def test_text_request_rejected_with_400_keeps_generic_diagnosis():
provider = ImageProvider(response=LLMResponse(
"invalid request", finish_reason="error", error_status_code=400,
))
response = await provider.chat_with_retry(messages=[{"role": "user", "content": "hi"}])
assert LLMProvider.public_error_kind(response) == "unknown"
def test_factory_resolves_independent_capabilities_and_refresh_signature():
config = Config.model_validate({
"agents": {"defaults": {"modelPreset": "text", "fallbackModels": ["vision", {"provider": "custom", "model": "inline"}]}},