Fix failing unit test on main (#7909)

Co-authored-by: openhands <openhands@all-hands.dev>
This commit is contained in:
Rohit Malhotra 2025-04-17 14:43:09 -04:00 committed by GitHub
parent cc8b677f3e
commit c2e1babd76
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 13 deletions

View File

@ -877,7 +877,7 @@ async def test_context_window_exceeded_error_handling(
async def test_run_controller_with_context_window_exceeded_with_truncation(
mock_agent, mock_runtime, mock_memory, test_event_stream
):
"""Tests that the controller can make progress after handling context window exceeded errors, as long as enable_history_truncation is ON"""
"""Tests that the controller can make progress after handling context window exceeded errors, as long as enable_history_truncation is ON."""
class StepState:
def __init__(self):
@ -1236,6 +1236,12 @@ async def test_condenser_metrics_included():
# Attach the condenser to the agent
agent.condenser = condenser
# Mock the system message to avoid ID issues
system_message = SystemMessageAction(content='Test system message')
system_message._source = EventSource.AGENT
system_message._id = -1
agent.get_system_message.return_value = system_message
# Mock agent step to return a CondensationAction
action = CondensationAction(
forgotten_events_start_id=1,
@ -1296,10 +1302,10 @@ async def test_condenser_metrics_included():
@pytest.mark.asyncio
async def test_first_user_message_with_identical_content(test_event_stream, mock_agent):
"""
Test that _first_user_message correctly identifies the first user message
even when multiple messages have identical content but different IDs.
Also verifies that the result is properly cached.
"""Test that _first_user_message correctly identifies the first user message.
This test verifies that messages with identical content but different IDs are properly
distinguished, and that the result is correctly cached.
The issue we're checking is that the comparison (action == self._first_user_message())
should correctly differentiate between messages with the same content but different IDs.

View File

@ -11,7 +11,7 @@ from openhands.core.config import AppConfig
from openhands.core.main import run_controller
from openhands.core.schema.agent import AgentState
from openhands.events.action.agent import RecallAction
from openhands.events.action.message import MessageAction
from openhands.events.action.message import MessageAction, SystemMessageAction
from openhands.events.event import EventSource
from openhands.events.observation.agent import (
RecallObservation,
@ -67,8 +67,6 @@ def mock_agent():
agent.llm.config = AppConfig().get_llm_config()
# Add a proper system message mock
from openhands.events.action.message import SystemMessageAction
system_message = SystemMessageAction(content='Test system message')
system_message._source = EventSource.AGENT
system_message._id = -1 # Set invalid ID to avoid the ID check
@ -78,7 +76,6 @@ def mock_agent():
@pytest.mark.asyncio
async def test_memory_on_event_exception_handling(memory, event_stream, mock_agent):
"""Test that exceptions in Memory.on_event are properly handled via status callback."""
# Create a mock runtime
runtime = MagicMock(spec=Runtime)
runtime.event_stream = event_stream
@ -108,7 +105,6 @@ async def test_memory_on_workspace_context_recall_exception_handling(
memory, event_stream, mock_agent
):
"""Test that exceptions in Memory._on_workspace_context_recall are properly handled via status callback."""
# Create a mock runtime
runtime = MagicMock(spec=Runtime)
runtime.event_stream = event_stream
@ -270,9 +266,7 @@ REPOSITORY INSTRUCTIONS: This is a test repository.
@pytest.mark.asyncio
async def test_memory_with_agent_microagents():
"""
Test that Memory processes microagent based on trigger words from agent messages.
"""
"""Test that Memory processes microagent based on trigger words from agent messages."""
# Create a mock event stream
event_stream = MagicMock(spec=EventStream)