|
|
@@ -4,6 +4,7 @@ import pytest
|
|
|
|
|
|
from opendevin.controller.agent_controller import AgentController
|
|
|
from opendevin.events.action import CmdRunAction, FileReadAction, MessageAction
|
|
|
+from opendevin.events.action.commands import CmdKillAction
|
|
|
from opendevin.events.observation import (
|
|
|
CmdOutputObservation,
|
|
|
FileReadObservation,
|
|
|
@@ -21,6 +22,9 @@ class TestAgentController:
|
|
|
controller._is_stuck = AgentController._is_stuck.__get__(
|
|
|
controller, AgentController
|
|
|
)
|
|
|
+ controller._eq_no_pid = AgentController._eq_no_pid.__get__(
|
|
|
+ controller, AgentController
|
|
|
+ )
|
|
|
controller.delegate = None
|
|
|
controller.state = Mock()
|
|
|
controller.state.history = []
|
|
|
@@ -75,7 +79,7 @@ class TestAgentController:
|
|
|
),
|
|
|
(
|
|
|
CmdRunAction(command='invalid_command'),
|
|
|
- ErrorObservation(content='Command not found'),
|
|
|
+ ErrorObservation(content='Command still not found or another error'),
|
|
|
),
|
|
|
# user message shouldn't break detection
|
|
|
(message_action, NullObservation(content='')),
|
|
|
@@ -115,8 +119,9 @@ class TestAgentController:
|
|
|
),
|
|
|
(
|
|
|
CmdRunAction(command='ls'),
|
|
|
+ # command_id is ignored for the eq check, it's a pid
|
|
|
CmdOutputObservation(
|
|
|
- command_id=1, command='ls', content='file1.txt\nfile2.txt'
|
|
|
+ command_id=2, command='ls', content='file1.txt\nfile2.txt'
|
|
|
),
|
|
|
),
|
|
|
(
|
|
|
@@ -128,7 +133,7 @@ class TestAgentController:
|
|
|
(
|
|
|
CmdRunAction(command='ls'),
|
|
|
CmdOutputObservation(
|
|
|
- command_id=1, command='ls', content='file1.txt\nfile2.txt'
|
|
|
+ command_id=3, command='ls', content='file1.txt\nfile2.txt'
|
|
|
),
|
|
|
),
|
|
|
(
|
|
|
@@ -160,7 +165,8 @@ class TestAgentController:
|
|
|
),
|
|
|
(
|
|
|
CmdRunAction(command='pwd'),
|
|
|
- CmdOutputObservation(command_id=1, command='pwd', content='/home/user'),
|
|
|
+ # command_id is ignored for the eq check, it's the pid
|
|
|
+ CmdOutputObservation(command_id=2, command='pwd', content='/home/user'),
|
|
|
),
|
|
|
(
|
|
|
FileReadAction(path='file2.txt'),
|
|
|
@@ -170,7 +176,7 @@ class TestAgentController:
|
|
|
(message_action, NullObservation(content='')),
|
|
|
(
|
|
|
CmdRunAction(command='pwd'),
|
|
|
- CmdOutputObservation(command_id=1, command='pwd', content='/home/user'),
|
|
|
+ CmdOutputObservation(command_id=3, command='pwd', content='/home/user'),
|
|
|
),
|
|
|
(
|
|
|
FileReadAction(path='file2.txt'),
|
|
|
@@ -195,22 +201,88 @@ class TestAgentController:
|
|
|
),
|
|
|
(
|
|
|
CmdRunAction(command='ls'),
|
|
|
+ # command_id is ignored for the eq check, it's just the pid
|
|
|
CmdOutputObservation(
|
|
|
- command_id=1, command='ls', content='file1.txt\nfile2.txt'
|
|
|
+ command_id=2, command='ls', content='file1.txt\nfile2.txt'
|
|
|
),
|
|
|
),
|
|
|
- # message from the user
|
|
|
+ # message from the user shouldn't interfere with the detection
|
|
|
(message_action, NullObservation(content='')),
|
|
|
(
|
|
|
CmdRunAction(command='ls'),
|
|
|
CmdOutputObservation(
|
|
|
- command_id=1, command='ls', content='file1.txt\nfile2.txt'
|
|
|
+ command_id=3, command='ls', content='file1.txt\nfile2.txt'
|
|
|
),
|
|
|
),
|
|
|
(
|
|
|
CmdRunAction(command='ls'),
|
|
|
CmdOutputObservation(
|
|
|
- command_id=1, command='ls', content='file1.txt\nfile2.txt'
|
|
|
+ command_id=4, command='ls', content='file1.txt\nfile2.txt'
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ ]
|
|
|
+ with patch('logging.Logger.warning') as mock_warning:
|
|
|
+ assert controller._is_stuck() is True
|
|
|
+ mock_warning.assert_called_once_with('Action, Observation loop detected')
|
|
|
+
|
|
|
+ def test_is_stuck_four_tuples_cmd_kill_and_output(self, controller):
|
|
|
+ message_action = MessageAction(content='Done', wait_for_response=False)
|
|
|
+ message_action._source = EventSource.USER
|
|
|
+ controller.state.history = [
|
|
|
+ (
|
|
|
+ MessageAction(content='Hello', wait_for_response=False),
|
|
|
+ Observation(content='Response 1'),
|
|
|
+ ),
|
|
|
+ (
|
|
|
+ CmdKillAction(
|
|
|
+ command_id=1,
|
|
|
+ thought='It looks like storybook is stuck, lets kill it',
|
|
|
+ ),
|
|
|
+ CmdOutputObservation(
|
|
|
+ content='Background command storybook has been killed.',
|
|
|
+ command_id=1,
|
|
|
+ command='storybook',
|
|
|
+ exit_code=0,
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ (
|
|
|
+ # command_id is ignored for the eq check, it's the pid
|
|
|
+ CmdKillAction(
|
|
|
+ command_id=2,
|
|
|
+ thought='It looks like storybook is stuck, lets kill it',
|
|
|
+ ),
|
|
|
+ # command_id here too
|
|
|
+ CmdOutputObservation(
|
|
|
+ content='Background command storybook has been killed.',
|
|
|
+ command_id=2,
|
|
|
+ command='storybook',
|
|
|
+ exit_code=0,
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ # message from the user, shouldn't be counted
|
|
|
+ (message_action, NullObservation(content='')),
|
|
|
+ (
|
|
|
+ CmdKillAction(
|
|
|
+ command_id=3,
|
|
|
+ thought='It looks like storybook is stuck, lets kill it',
|
|
|
+ ),
|
|
|
+ CmdOutputObservation(
|
|
|
+ content='Background command storybook has been killed.',
|
|
|
+ command_id=3,
|
|
|
+ command='storybook',
|
|
|
+ exit_code=0,
|
|
|
+ ),
|
|
|
+ ),
|
|
|
+ (
|
|
|
+ CmdKillAction(
|
|
|
+ command_id=4,
|
|
|
+ thought='It looks like storybook is stuck, lets kill it',
|
|
|
+ ),
|
|
|
+ CmdOutputObservation(
|
|
|
+ content='Background command storybook has been killed.',
|
|
|
+ command_id=4,
|
|
|
+ command='storybook',
|
|
|
+ exit_code=0,
|
|
|
),
|
|
|
),
|
|
|
]
|