|
|
@@ -80,7 +80,7 @@ class TestStuckDetector:
|
|
|
code=code_snippet,
|
|
|
)
|
|
|
ipython_observation._cause = ipython_action._id
|
|
|
- event_stream.add_event(ipython_observation, EventSource.USER)
|
|
|
+ event_stream.add_event(ipython_observation, EventSource.ENVIRONMENT)
|
|
|
|
|
|
def _impl_unterminated_string_error_events(
|
|
|
self, event_stream: EventStream, random_line: bool, incidents: int = 4
|
|
|
@@ -96,7 +96,7 @@ class TestStuckDetector:
|
|
|
code=code_snippet,
|
|
|
)
|
|
|
ipython_observation._cause = ipython_action._id
|
|
|
- event_stream.add_event(ipython_observation, EventSource.USER)
|
|
|
+ event_stream.add_event(ipython_observation, EventSource.ENVIRONMENT)
|
|
|
|
|
|
def test_history_too_short(
|
|
|
self, stuck_detector: StuckDetector, event_stream: EventStream
|
|
|
@@ -106,7 +106,7 @@ class TestStuckDetector:
|
|
|
observation = NullObservation(content='')
|
|
|
observation._cause = message_action.id
|
|
|
event_stream.add_event(message_action, EventSource.USER)
|
|
|
- event_stream.add_event(observation, EventSource.USER)
|
|
|
+ event_stream.add_event(observation, EventSource.ENVIRONMENT)
|
|
|
|
|
|
cmd_action = CmdRunAction(command='ls')
|
|
|
event_stream.add_event(cmd_action, EventSource.AGENT)
|
|
|
@@ -114,7 +114,7 @@ class TestStuckDetector:
|
|
|
command_id=1, command='ls', content='file1.txt\nfile2.txt'
|
|
|
)
|
|
|
cmd_observation._cause = cmd_action._id
|
|
|
- event_stream.add_event(cmd_observation, EventSource.USER)
|
|
|
+ event_stream.add_event(cmd_observation, EventSource.ENVIRONMENT)
|
|
|
|
|
|
# stuck_detector.state.history.set_event_stream(event_stream)
|
|
|
|
|
|
@@ -131,7 +131,7 @@ class TestStuckDetector:
|
|
|
|
|
|
# 2 events
|
|
|
event_stream.add_event(hello_action, EventSource.USER)
|
|
|
- event_stream.add_event(hello_observation, EventSource.USER)
|
|
|
+ event_stream.add_event(hello_observation, EventSource.ENVIRONMENT)
|
|
|
|
|
|
cmd_action_1 = CmdRunAction(command='ls')
|
|
|
event_stream.add_event(cmd_action_1, EventSource.AGENT)
|
|
|
@@ -139,7 +139,7 @@ class TestStuckDetector:
|
|
|
content='', command='ls', command_id=cmd_action_1._id
|
|
|
)
|
|
|
cmd_observation_1._cause = cmd_action_1._id
|
|
|
- event_stream.add_event(cmd_observation_1, EventSource.USER)
|
|
|
+ event_stream.add_event(cmd_observation_1, EventSource.ENVIRONMENT)
|
|
|
# 4 events
|
|
|
|
|
|
cmd_action_2 = CmdRunAction(command='ls')
|
|
|
@@ -148,13 +148,13 @@ class TestStuckDetector:
|
|
|
content='', command='ls', command_id=cmd_action_2._id
|
|
|
)
|
|
|
cmd_observation_2._cause = cmd_action_2._id
|
|
|
- event_stream.add_event(cmd_observation_2, EventSource.USER)
|
|
|
+ event_stream.add_event(cmd_observation_2, EventSource.ENVIRONMENT)
|
|
|
# 6 events
|
|
|
|
|
|
# random user message just because we can
|
|
|
message_null_observation = NullObservation(content='')
|
|
|
event_stream.add_event(message_action, EventSource.USER)
|
|
|
- event_stream.add_event(message_null_observation, EventSource.USER)
|
|
|
+ event_stream.add_event(message_null_observation, EventSource.ENVIRONMENT)
|
|
|
# 8 events
|
|
|
|
|
|
assert stuck_detector.is_stuck() is False
|
|
|
@@ -166,7 +166,7 @@ class TestStuckDetector:
|
|
|
content='', command='ls', command_id=cmd_action_3._id
|
|
|
)
|
|
|
cmd_observation_3._cause = cmd_action_3._id
|
|
|
- event_stream.add_event(cmd_observation_3, EventSource.USER)
|
|
|
+ event_stream.add_event(cmd_observation_3, EventSource.ENVIRONMENT)
|
|
|
# 10 events
|
|
|
|
|
|
assert len(collect_events(event_stream)) == 10
|
|
|
@@ -191,7 +191,7 @@ class TestStuckDetector:
|
|
|
content='', command='ls', command_id=cmd_action_4._id
|
|
|
)
|
|
|
cmd_observation_4._cause = cmd_action_4._id
|
|
|
- event_stream.add_event(cmd_observation_4, EventSource.USER)
|
|
|
+ event_stream.add_event(cmd_observation_4, EventSource.ENVIRONMENT)
|
|
|
# 12 events
|
|
|
|
|
|
assert len(collect_events(event_stream)) == 12
|
|
|
@@ -223,14 +223,14 @@ class TestStuckDetector:
|
|
|
hello_observation = NullObservation(content='')
|
|
|
event_stream.add_event(hello_action, EventSource.USER)
|
|
|
hello_observation._cause = hello_action._id
|
|
|
- event_stream.add_event(hello_observation, EventSource.USER)
|
|
|
+ event_stream.add_event(hello_observation, EventSource.ENVIRONMENT)
|
|
|
# 2 events
|
|
|
|
|
|
cmd_action_1 = CmdRunAction(command='invalid_command')
|
|
|
event_stream.add_event(cmd_action_1, EventSource.AGENT)
|
|
|
error_observation_1 = ErrorObservation(content='Command not found')
|
|
|
error_observation_1._cause = cmd_action_1._id
|
|
|
- event_stream.add_event(error_observation_1, EventSource.USER)
|
|
|
+ event_stream.add_event(error_observation_1, EventSource.ENVIRONMENT)
|
|
|
# 4 events
|
|
|
|
|
|
cmd_action_2 = CmdRunAction(command='invalid_command')
|
|
|
@@ -239,26 +239,26 @@ class TestStuckDetector:
|
|
|
content='Command still not found or another error'
|
|
|
)
|
|
|
error_observation_2._cause = cmd_action_2._id
|
|
|
- event_stream.add_event(error_observation_2, EventSource.USER)
|
|
|
+ event_stream.add_event(error_observation_2, EventSource.ENVIRONMENT)
|
|
|
# 6 events
|
|
|
|
|
|
message_null_observation = NullObservation(content='')
|
|
|
event_stream.add_event(message_action, EventSource.USER)
|
|
|
- event_stream.add_event(message_null_observation, EventSource.USER)
|
|
|
+ event_stream.add_event(message_null_observation, EventSource.ENVIRONMENT)
|
|
|
# 8 events
|
|
|
|
|
|
cmd_action_3 = CmdRunAction(command='invalid_command')
|
|
|
event_stream.add_event(cmd_action_3, EventSource.AGENT)
|
|
|
error_observation_3 = ErrorObservation(content='Different error')
|
|
|
error_observation_3._cause = cmd_action_3._id
|
|
|
- event_stream.add_event(error_observation_3, EventSource.USER)
|
|
|
+ event_stream.add_event(error_observation_3, EventSource.ENVIRONMENT)
|
|
|
# 10 events
|
|
|
|
|
|
cmd_action_4 = CmdRunAction(command='invalid_command')
|
|
|
event_stream.add_event(cmd_action_4, EventSource.AGENT)
|
|
|
error_observation_4 = ErrorObservation(content='Command not found')
|
|
|
error_observation_4._cause = cmd_action_4._id
|
|
|
- event_stream.add_event(error_observation_4, EventSource.USER)
|
|
|
+ event_stream.add_event(error_observation_4, EventSource.ENVIRONMENT)
|
|
|
# 12 events
|
|
|
|
|
|
with patch('logging.Logger.warning') as mock_warning:
|
|
|
@@ -366,7 +366,7 @@ class TestStuckDetector:
|
|
|
code='print("hello',
|
|
|
)
|
|
|
ipython_observation_1._cause = ipython_action_1._id
|
|
|
- event_stream.add_event(ipython_observation_1, EventSource.USER)
|
|
|
+ event_stream.add_event(ipython_observation_1, EventSource.ENVIRONMENT)
|
|
|
|
|
|
ipython_action_2 = IPythonRunCellAction(code='print("hello')
|
|
|
event_stream.add_event(ipython_action_2, EventSource.AGENT)
|
|
|
@@ -375,7 +375,7 @@ class TestStuckDetector:
|
|
|
code='print("hello',
|
|
|
)
|
|
|
ipython_observation_2._cause = ipython_action_2._id
|
|
|
- event_stream.add_event(ipython_observation_2, EventSource.USER)
|
|
|
+ event_stream.add_event(ipython_observation_2, EventSource.ENVIRONMENT)
|
|
|
|
|
|
ipython_action_3 = IPythonRunCellAction(code='print("hello')
|
|
|
event_stream.add_event(ipython_action_3, EventSource.AGENT)
|
|
|
@@ -384,7 +384,7 @@ class TestStuckDetector:
|
|
|
code='print("hello',
|
|
|
)
|
|
|
ipython_observation_3._cause = ipython_action_3._id
|
|
|
- event_stream.add_event(ipython_observation_3, EventSource.USER)
|
|
|
+ event_stream.add_event(ipython_observation_3, EventSource.ENVIRONMENT)
|
|
|
|
|
|
ipython_action_4 = IPythonRunCellAction(code='print("hello')
|
|
|
event_stream.add_event(ipython_action_4, EventSource.AGENT)
|
|
|
@@ -393,7 +393,7 @@ class TestStuckDetector:
|
|
|
code='print("hello',
|
|
|
)
|
|
|
ipython_observation_4._cause = ipython_action_4._id
|
|
|
- event_stream.add_event(ipython_observation_4, EventSource.USER)
|
|
|
+ event_stream.add_event(ipython_observation_4, EventSource.ENVIRONMENT)
|
|
|
|
|
|
with patch('logging.Logger.warning') as mock_warning:
|
|
|
assert stuck_detector.is_stuck() is False
|
|
|
@@ -406,7 +406,7 @@ class TestStuckDetector:
|
|
|
message_action._source = EventSource.USER
|
|
|
event_stream.add_event(message_action, EventSource.USER)
|
|
|
message_observation = NullObservation(content='')
|
|
|
- event_stream.add_event(message_observation, EventSource.USER)
|
|
|
+ event_stream.add_event(message_observation, EventSource.ENVIRONMENT)
|
|
|
|
|
|
cmd_action_1 = CmdRunAction(command='ls')
|
|
|
event_stream.add_event(cmd_action_1, EventSource.AGENT)
|
|
|
@@ -414,7 +414,7 @@ class TestStuckDetector:
|
|
|
command_id=1, command='ls', content='file1.txt\nfile2.txt'
|
|
|
)
|
|
|
cmd_observation_1._cause = cmd_action_1._id
|
|
|
- event_stream.add_event(cmd_observation_1, EventSource.USER)
|
|
|
+ event_stream.add_event(cmd_observation_1, EventSource.ENVIRONMENT)
|
|
|
|
|
|
read_action_1 = FileReadAction(path='file1.txt')
|
|
|
event_stream.add_event(read_action_1, EventSource.AGENT)
|
|
|
@@ -422,7 +422,7 @@ class TestStuckDetector:
|
|
|
content='File content', path='file1.txt'
|
|
|
)
|
|
|
read_observation_1._cause = read_action_1._id
|
|
|
- event_stream.add_event(read_observation_1, EventSource.USER)
|
|
|
+ event_stream.add_event(read_observation_1, EventSource.ENVIRONMENT)
|
|
|
|
|
|
cmd_action_2 = CmdRunAction(command='ls')
|
|
|
event_stream.add_event(cmd_action_2, EventSource.AGENT)
|
|
|
@@ -430,7 +430,7 @@ class TestStuckDetector:
|
|
|
command_id=2, command='ls', content='file1.txt\nfile2.txt'
|
|
|
)
|
|
|
cmd_observation_2._cause = cmd_action_2._id
|
|
|
- event_stream.add_event(cmd_observation_2, EventSource.USER)
|
|
|
+ event_stream.add_event(cmd_observation_2, EventSource.ENVIRONMENT)
|
|
|
|
|
|
read_action_2 = FileReadAction(path='file1.txt')
|
|
|
event_stream.add_event(read_action_2, EventSource.AGENT)
|
|
|
@@ -438,12 +438,12 @@ class TestStuckDetector:
|
|
|
content='File content', path='file1.txt'
|
|
|
)
|
|
|
read_observation_2._cause = read_action_2._id
|
|
|
- event_stream.add_event(read_observation_2, EventSource.USER)
|
|
|
+ event_stream.add_event(read_observation_2, EventSource.ENVIRONMENT)
|
|
|
|
|
|
# one more message to break the pattern
|
|
|
message_null_observation = NullObservation(content='')
|
|
|
event_stream.add_event(message_action, EventSource.USER)
|
|
|
- event_stream.add_event(message_null_observation, EventSource.USER)
|
|
|
+ event_stream.add_event(message_null_observation, EventSource.ENVIRONMENT)
|
|
|
|
|
|
cmd_action_3 = CmdRunAction(command='ls')
|
|
|
event_stream.add_event(cmd_action_3, EventSource.AGENT)
|
|
|
@@ -451,7 +451,7 @@ class TestStuckDetector:
|
|
|
command_id=3, command='ls', content='file1.txt\nfile2.txt'
|
|
|
)
|
|
|
cmd_observation_3._cause = cmd_action_3._id
|
|
|
- event_stream.add_event(cmd_observation_3, EventSource.USER)
|
|
|
+ event_stream.add_event(cmd_observation_3, EventSource.ENVIRONMENT)
|
|
|
|
|
|
read_action_3 = FileReadAction(path='file1.txt')
|
|
|
event_stream.add_event(read_action_3, EventSource.AGENT)
|
|
|
@@ -459,7 +459,7 @@ class TestStuckDetector:
|
|
|
content='File content', path='file1.txt'
|
|
|
)
|
|
|
read_observation_3._cause = read_action_3._id
|
|
|
- event_stream.add_event(read_observation_3, EventSource.USER)
|
|
|
+ event_stream.add_event(read_observation_3, EventSource.ENVIRONMENT)
|
|
|
|
|
|
with patch('logging.Logger.warning') as mock_warning:
|
|
|
assert stuck_detector.is_stuck() is True
|
|
|
@@ -475,7 +475,7 @@ class TestStuckDetector:
|
|
|
event_stream.add_event(hello_action, EventSource.USER)
|
|
|
hello_observation = NullObservation(content='')
|
|
|
hello_observation._cause = hello_action._id
|
|
|
- event_stream.add_event(hello_observation, EventSource.USER)
|
|
|
+ event_stream.add_event(hello_observation, EventSource.ENVIRONMENT)
|
|
|
|
|
|
cmd_action_1 = CmdRunAction(command='ls')
|
|
|
event_stream.add_event(cmd_action_1, EventSource.AGENT)
|
|
|
@@ -483,7 +483,7 @@ class TestStuckDetector:
|
|
|
command_id=cmd_action_1.id, command='ls', content='file1.txt\nfile2.txt'
|
|
|
)
|
|
|
cmd_observation_1._cause = cmd_action_1._id
|
|
|
- event_stream.add_event(cmd_observation_1, EventSource.USER)
|
|
|
+ event_stream.add_event(cmd_observation_1, EventSource.ENVIRONMENT)
|
|
|
|
|
|
read_action_1 = FileReadAction(path='file1.txt')
|
|
|
event_stream.add_event(read_action_1, EventSource.AGENT)
|
|
|
@@ -491,7 +491,7 @@ class TestStuckDetector:
|
|
|
content='File content', path='file1.txt'
|
|
|
)
|
|
|
read_observation_1._cause = read_action_1._id
|
|
|
- event_stream.add_event(read_observation_1, EventSource.USER)
|
|
|
+ event_stream.add_event(read_observation_1, EventSource.ENVIRONMENT)
|
|
|
|
|
|
cmd_action_2 = CmdRunAction(command='pwd')
|
|
|
event_stream.add_event(cmd_action_2, EventSource.AGENT)
|
|
|
@@ -499,7 +499,7 @@ class TestStuckDetector:
|
|
|
command_id=2, command='pwd', content='/home/user'
|
|
|
)
|
|
|
cmd_observation_2._cause = cmd_action_2._id
|
|
|
- event_stream.add_event(cmd_observation_2, EventSource.USER)
|
|
|
+ event_stream.add_event(cmd_observation_2, EventSource.ENVIRONMENT)
|
|
|
|
|
|
read_action_2 = FileReadAction(path='file2.txt')
|
|
|
event_stream.add_event(read_action_2, EventSource.AGENT)
|
|
|
@@ -507,11 +507,11 @@ class TestStuckDetector:
|
|
|
content='Another file content', path='file2.txt'
|
|
|
)
|
|
|
read_observation_2._cause = read_action_2._id
|
|
|
- event_stream.add_event(read_observation_2, EventSource.USER)
|
|
|
+ event_stream.add_event(read_observation_2, EventSource.ENVIRONMENT)
|
|
|
|
|
|
message_null_observation = NullObservation(content='')
|
|
|
event_stream.add_event(message_action, EventSource.USER)
|
|
|
- event_stream.add_event(message_null_observation, EventSource.USER)
|
|
|
+ event_stream.add_event(message_null_observation, EventSource.ENVIRONMENT)
|
|
|
|
|
|
cmd_action_3 = CmdRunAction(command='pwd')
|
|
|
event_stream.add_event(cmd_action_3, EventSource.AGENT)
|
|
|
@@ -519,7 +519,7 @@ class TestStuckDetector:
|
|
|
command_id=cmd_action_3.id, command='pwd', content='/home/user'
|
|
|
)
|
|
|
cmd_observation_3._cause = cmd_action_3._id
|
|
|
- event_stream.add_event(cmd_observation_3, EventSource.USER)
|
|
|
+ event_stream.add_event(cmd_observation_3, EventSource.ENVIRONMENT)
|
|
|
|
|
|
read_action_3 = FileReadAction(path='file2.txt')
|
|
|
event_stream.add_event(read_action_3, EventSource.AGENT)
|
|
|
@@ -527,7 +527,7 @@ class TestStuckDetector:
|
|
|
content='Another file content', path='file2.txt'
|
|
|
)
|
|
|
read_observation_3._cause = read_action_3._id
|
|
|
- event_stream.add_event(read_observation_3, EventSource.USER)
|
|
|
+ event_stream.add_event(read_observation_3, EventSource.ENVIRONMENT)
|
|
|
|
|
|
assert stuck_detector.is_stuck() is False
|
|
|
|
|
|
@@ -572,7 +572,7 @@ class TestStuckDetector:
|
|
|
exit_code=0,
|
|
|
)
|
|
|
cmd_output_observation._cause = cmd_kill_action._id
|
|
|
- event_stream.add_event(cmd_output_observation, EventSource.USER)
|
|
|
+ event_stream.add_event(cmd_output_observation, EventSource.ENVIRONMENT)
|
|
|
|
|
|
message_action_7 = MessageAction(content="I'm doing well, thanks for asking.")
|
|
|
event_stream.add_event(message_action_7, EventSource.AGENT)
|