test: tighten multimodal client response coverage

parent d02c15e0
......@@ -372,20 +372,23 @@ class DummyResponse:
def test_task5_handle_response_payload_returns_llm_text_without_artifact(tmp_path):
response = DummyResponse({
payload = {
"choices": [{"message": {"content": "hello from model"}}]
})
}
response = DummyResponse(payload)
result = handle_response_payload("llm", response, tmp_path)
assert result["text"] == "hello from model"
assert result["artifact_path"] is None
assert result["payload"] == payload
def test_task5_handle_response_payload_downloads_url_artifact(monkeypatch, tmp_path):
response = DummyResponse({
"data": [{"url": "http://example.invalid/audio.wav"}]
})
payload = {
"data": [{"url": "http://example.invalid/audio.wav", "text": "generated audio summary"}]
}
response = DummyResponse(payload)
monkeypatch.setattr(
"tools.manual_multimodal_test_client._download_artifact",
lambda url: b"wave-bytes",
......@@ -395,16 +398,39 @@ def test_task5_handle_response_payload_downloads_url_artifact(monkeypatch, tmp_p
assert result["artifact_path"].suffix == ".wav"
assert result["artifact_path"].read_bytes() == b"wave-bytes"
assert result["text"] == "generated audio summary"
assert result["payload"] == payload
def test_task5_handle_response_payload_decodes_base64_artifact(tmp_path):
response = DummyResponse({
"data": [{"b64_json": "aGVsbG8="}]
})
payload = {
"data": [{"b64_json": "aGVsbG8=", "caption": "inline audio artifact"}]
}
response = DummyResponse(payload)
result = handle_response_payload("audio-generation", response, tmp_path)
assert result["artifact_path"].read_bytes() == b"hello"
assert result["text"] == "inline audio artifact"
assert result["payload"] == payload
def test_task5_handle_response_payload_downloads_video_generation_artifact_as_mp4(monkeypatch, tmp_path):
payload = {
"data": [{"url": "http://example.invalid/video.mp4", "caption": "generated video summary"}]
}
response = DummyResponse(payload)
monkeypatch.setattr(
"tools.manual_multimodal_test_client._download_artifact",
lambda url: b"video-bytes",
)
result = handle_response_payload("video-generation", response, tmp_path)
assert result["artifact_path"].suffix == ".mp4"
assert result["artifact_path"].read_bytes() == b"video-bytes"
assert result["text"] == "generated video summary"
assert result["payload"] == payload
def test_task5_execute_request_forwards_method_url_timeout_and_kwargs(monkeypatch):
......@@ -436,3 +462,30 @@ def test_task5_execute_request_forwards_method_url_timeout_and_kwargs(monkeypatc
"json": {"prompt": "Ping"},
},
}
def test_task5_execute_request_filters_method_and_url_from_forwarded_kwargs(monkeypatch):
captured = {}
def fake_request(*, method, url, timeout, **kwargs):
captured["method"] = method
captured["url"] = url
captured["timeout"] = timeout
captured["kwargs"] = kwargs
return "response-object"
monkeypatch.setattr("tools.manual_multimodal_test_client.requests.request", fake_request)
result = execute_request({
"method": "GET",
"url": "http://127.0.0.1:6745/health",
"params": {"verbose": "1"},
})
assert result == "response-object"
assert captured["method"] == "GET"
assert captured["url"] == "http://127.0.0.1:6745/health"
assert captured["timeout"] == 300
assert captured["kwargs"] == {"params": {"verbose": "1"}}
assert "method" not in captured["kwargs"]
assert "url" not in captured["kwargs"]
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment