Skip to content

test: Add comprehensive tests for events_to_messages conversions - #81

Merged
xingyaoww merged 1 commit into
mainfrom
openhands/add-events-to-messages-tests
Sep 3, 2025
Merged

xingyaoww merged 1 commit into
mainfrom
openhands/add-events-to-messages-tests

Conversation

@xingyaoww

Copy link
Copy Markdown
Contributor

Summary

This PR adds comprehensive tests for the events_to_messages conversions in openhands/sdk/event/base.py to address issue #50.

Changes

  • Created test directory structure: Added tests/sdk/event/ directory with proper __init__.py
  • Added comprehensive test suite: Created test_events_to_messages.py with 9 test methods covering:
    • Single MessageEvent, ActionEvent, and ObservationEvent conversions
    • Parallel function calling with same llm_response_id (following LiteLLM patterns)
    • Sequential function calls with different llm_response_ids
    • Mixed event types in sequence
    • Complex scenarios with both parallel and sequential calls
    • Error handling for invalid parallel call structures
    • AgentErrorEvent conversions

Test Coverage

The tests cover the expected input/output patterns from the LiteLLM documentation, ensuring that:

  1. Single function calls are properly converted to individual assistant messages with tool calls
  2. Parallel function calls (same llm_response_id) are correctly grouped into a single assistant message with multiple tool calls
  3. Sequential function calls (different llm_response_ids) are converted to separate assistant messages
  4. Mixed event types are handled correctly in sequence
  5. Error conditions are properly validated (e.g., non-empty thoughts in parallel calls)

Testing

All tests pass successfully:

$ uv run pytest tests/sdk/event/test_events_to_messages.py -v
========== 9 passed in 1.35s ==========

Pre-commit hooks also pass:

  • Ruff format ✅
  • Ruff lint ✅
  • PEP8 style check ✅
  • Type check with Pyright ✅

Fixes

Closes #50

@xingyaoww can click here to continue refining the PR

- Add tests for single MessageEvent, ActionEvent, and ObservationEvent conversions
- Add tests for parallel function calling with same llm_response_id
- Add tests for sequential function calls with different llm_response_ids
- Add tests for mixed event types in sequence
- Add tests for complex scenarios with both parallel and sequential calls
- Add error handling tests for invalid parallel call structures
- All tests cover expected input/output patterns from LiteLLM docs
- Fixes issue #50

Co-authored-by: openhands <openhands@all-hands.dev>
@xingyaoww xingyaoww changed the title Add comprehensive tests for events_to_messages conversions test: Add comprehensive tests for events_to_messages conversions Sep 3, 2025
@xingyaoww
xingyaoww merged commit 969863e into main Sep 3, 2025
@xingyaoww
xingyaoww deleted the openhands/add-events-to-messages-tests branch September 3, 2025 19:28
StressTestor pushed a commit to StressTestor/software-agent-sdk that referenced this pull request Jun 1, 2026
)

Co-authored-by: openhands <openhands@all-hands.dev>
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.

Add tests for events_to_messages conversions in openhands/core/event/base.py

2 participants