Skip to content

test: cover response_api content-format guards and system-image rejection - #35

Open
devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1789677975-test-response-api-guards
Open

devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1789677975-test-response-api-guards

Conversation

@devin-ai-integration

Copy link
Copy Markdown

Summary

Closes the coverage gap flagged by the code scan in src/agentlab/llm/response_api.py: the defensive guards in the message builders and ClaudeResponseModel had no tests, so a regression that silently drops malformed content (instead of raising) would pass CI.

Tests added in tests/llm/test_response_api.py, next to the existing builder tests:

  • test_message_builder_rejects_unsupported_content — parametrized over all three builders (OpenAIResponseAPIMessageBuilder, AnthropicAPIMessageBuilder, OpenAIChatCompletionAPIMessageBuilder); a content item with neither text nor image must raise ValueError("Unsupported content type: ...").
  • test_openai_response_api_message_builder_assistant_text_is_output_text — assistant-role text maps to output_text (non-assistant stays input_text, already covered).
  • test_add_image_url_appends_png_base64_content — add_image_url appends {"image": "data:image/png;base64,..."} and the payload decodes back to the original image.
  • test_filter_system_messages_splits_system_and_other_messages / test_filter_system_messages_rejects_image_in_system_message — sys vs other split (including raw dict messages) and the TypeError guard.

Tests only; no production code touched.

Note for reviewers

The image guard in filter_system_messages checks c.get("type") == "image", but MessageBuilder.add_image stores {"image": ...} with no "type" key:

# add_image  -> {"image": "data:image/png;base64,..."}   # guard does NOT fire
# guard      -> if c.get("type") == "image": raise TypeError(...)

So the guard only fires for content built with an explicit "type" key, which is what the new test does. The test documents current behavior rather than the (arguably intended) behavior; fixing the guard to also match "image" in c would change runtime behavior for any agent that attaches images to system messages, so it is left out of this test-only PR. Happy to follow up if you want the guard tightened.

Verification

pytest tests/llm/test_response_api.py -m 'not pricy' → 17 passed. black --check clean on the changed file.

Devin-Org: engineering

Link to Devin session: https://app.devin.ai/sessions/4d335c1680c6462ab3a460c4f6b98a6f
Open in Devin Desktop: https://app.devin.ai/desktop/session/4d335c1680c6462ab3a460c4f6b98a6f?variant=devin

@devin-ai-integration

Copy link
Copy Markdown
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants