Skip to content

[Openhands] we should add test to test this init_state will actually modify state in-place - #769

Closed
github-actions[bot] wants to merge 1 commit into
mainfrom
openhands/todo/init-state-in-place-test
Closed

github-actions[bot] wants to merge 1 commit into
mainfrom
openhands/todo/init-state-in-place-test

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

Overview

This PR addresses the TODO comment in openhands/sdk/agent/agent.py at line 88, which requested tests to verify that Agent.init_state() modifies the ConversationState object in-place.

Changes

  • ✅ Created comprehensive test suite in tests/sdk/agent/test_init_state_in_place.py
  • ✅ Removed TODO comment from openhands/sdk/agent/agent.py

Test Coverage

The new test suite verifies:

  1. Object Identity Preservation: State object is modified in-place, not replaced
  2. Events List Modification: Events list is modified in-place
  3. System Prompt Addition: init_state adds a SystemPromptEvent
  4. Duplicate Prevention: Doesn't add duplicate system prompts
  5. State Attribute Preservation: Original state attributes are preserved
  6. Bash Tool Handling: Handles missing bash tool gracefully

Test Results

All 5 tests pass successfully:

tests/sdk/agent/test_init_state_in_place.py::TestInitStateInPlace::test_init_state_modifies_state_in_place PASSED
tests/sdk/agent/test_init_state_in_place.py::TestInitStateInPlace::test_init_state_calls_super PASSED
tests/sdk/agent/test_init_state_in_place.py::TestInitStateInPlace::test_init_state_does_not_add_duplicate_system_prompt PASSED
tests/sdk/agent/test_init_state_in_place.py::TestInitStateInPlace::test_init_state_preserves_state_attributes PASSED
tests/sdk/agent/test_init_state_in_place.py::TestInitStateInPlace::test_init_state_without_bash_tool PASSED

Related

Addresses TODO from openhands/sdk/agent/agent.py:88-89

- Created comprehensive test suite in test_init_state_in_place.py
- Tests verify that Agent.init_state() modifies ConversationState in-place
- Tests cover:
  - Object identity preservation
  - Events list modification in-place
  - System prompt addition
  - Duplicate system prompt prevention
  - State attribute preservation
  - Handling of missing bash tool
- Removed TODO comment from agent.py (line 88-89)

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.

2 participants