Add unit tests for OpenAIChatAgent#408
Conversation
51 tests covering init, schema sanitization, tool formatting, OAI→MCP conversion, system messages, format_blocks, format_tool_results, error handling, and get_response/invoke params passthrough. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Solid coverage — 51 tests across 9 classes with fully mocked OpenAI client is the right approach for a unit test suite at this layer. A couple of observations:
Minor: The Overall the test plan is well-structured and the async handling via |
Summary
hud/agents/tests/test_openai_chat.py_sanitize_schema_for_openai: anyOf nullables, prefixItems→array, nested recursion, key allowlist), tool schema formatting to OpenAI function format,_oai_to_mcpconversion, system message formatting,format_blocks(text/image/mixed),format_tool_results(text/image/empty/structured content), error handling (API errors, JSON truncation), andget_response/_invoke_chat_completionparams passthroughTest plan
uv run pytest hud/agents/tests/test_openai_chat.py -q→ 51 passed, 0 failedpytest-asyncio(auto mode viaasyncio_mode = "auto"in pyproject.toml)🤖 Generated with Claude Code
Note
Low Risk
Low risk: adds a new test module only, with no production code changes. Main risk is tightening behavior expectations that could require follow-up fixes if current behavior differs.
Overview
Adds
hud/agents/tests/test_openai_chat.py, a comprehensive unit test suite forOpenAIChatAgent.The tests cover initialization paths (HUD gateway vs. explicit
api_key/base_url/openai_client,completion_kwargs, and checkpoint injection), schema sanitization and tool schema conversion to OpenAI function format, plus message/result formatting (get_system_messages,format_blocks,format_tool_results) including image handling.Also adds coverage for
get_response/_invoke_chat_completionbehavior: tool call parsing, passthrough of allowed completion kwargs (while protectingmodel/messages/tools), finish-reason handling, and graceful error responses for API failures/truncated JSON.Reviewed by Cursor Bugbot for commit 4ec040c. Bugbot is set up for automated code reviews on this repo. Configure here.