Refactor actions and observations (#1479)

* refactor actions and events

* remove type_key

* remove stream

* move import

* move import

* fix NullObs

* reorder imports

* fix lint

* fix dataclasses

* remove blank fields

* fix nullobs

* fix sidebar labels

* fix test compilation

* switch to asdict

* lint

* fix whitespace

* fix executable

* delint

* fix run

* remove NotImplementeds

* fix path prefix

* remove null files

* add debug

* add more debug info

* fix dataclass on null

* remove debug

* revert sandbox

* fix merge issues

* fix tyeps

* Update opendevin/events/action/browse.py
This commit is contained in:
Robert Brennan
2024-05-02 11:44:54 -04:00
committed by GitHub
parent f19333aa6e
commit ce7c7eaae4
57 changed files with 489 additions and 236 deletions

View File

@@ -3,25 +3,26 @@ from pathlib import Path
import pytest
from opendevin import config
from opendevin.action import fileop
from opendevin.events.action import files
from opendevin.schema import ConfigType
SANDBOX_PATH_PREFIX = '/workspace'
def test_resolve_path():
assert fileop.resolve_path('test.txt', '/workspace') == Path(config.get(ConfigType.WORKSPACE_BASE)) / 'test.txt'
assert fileop.resolve_path('subdir/test.txt', '/workspace') == \
assert files.resolve_path('test.txt', '/workspace') == Path(config.get(ConfigType.WORKSPACE_BASE)) / 'test.txt'
assert files.resolve_path('subdir/test.txt', '/workspace') == \
Path(config.get(ConfigType.WORKSPACE_BASE)) / 'subdir' / 'test.txt'
assert fileop.resolve_path(Path(fileop.SANDBOX_PATH_PREFIX) / 'test.txt', '/workspace') == \
assert files.resolve_path(Path(SANDBOX_PATH_PREFIX) / 'test.txt', '/workspace') == \
Path(config.get(ConfigType.WORKSPACE_BASE)) / 'test.txt'
assert fileop.resolve_path(Path(fileop.SANDBOX_PATH_PREFIX) / 'subdir' / 'test.txt',
assert files.resolve_path(Path(SANDBOX_PATH_PREFIX) / 'subdir' / 'test.txt',
'/workspace') == Path(config.get(ConfigType.WORKSPACE_BASE)) / 'subdir' / 'test.txt'
assert fileop.resolve_path(Path(fileop.SANDBOX_PATH_PREFIX) / 'subdir' / '..' / 'test.txt',
assert files.resolve_path(Path(SANDBOX_PATH_PREFIX) / 'subdir' / '..' / 'test.txt',
'/workspace') == Path(config.get(ConfigType.WORKSPACE_BASE)) / 'test.txt'
with pytest.raises(PermissionError):
fileop.resolve_path(Path(fileop.SANDBOX_PATH_PREFIX) / '..' / 'test.txt', '/workspace')
files.resolve_path(Path(SANDBOX_PATH_PREFIX) / '..' / 'test.txt', '/workspace')
with pytest.raises(PermissionError):
fileop.resolve_path(Path('..') / 'test.txt', '/workspace')
files.resolve_path(Path('..') / 'test.txt', '/workspace')
with pytest.raises(PermissionError):
fileop.resolve_path(Path('/') / 'test.txt', '/workspace')
assert fileop.resolve_path('test.txt', '/workspace/test') == \
files.resolve_path(Path('/') / 'test.txt', '/workspace')
assert files.resolve_path('test.txt', '/workspace/test') == \
Path(config.get(ConfigType.WORKSPACE_BASE)) / 'test' / 'test.txt'

View File

@@ -5,12 +5,12 @@ import pytest
from agenthub.dummy_agent.agent import DummyAgent
from opendevin import config
from opendevin.action.github import GitHubPushAction, GitHubSendPRAction
from opendevin.controller.agent_controller import AgentController
from opendevin.events.action.github import GitHubPushAction, GitHubSendPRAction
from opendevin.events.observation.commands import CmdOutputObservation
from opendevin.events.observation.error import AgentErrorObservation
from opendevin.events.observation.message import AgentMessageObservation
from opendevin.llm.llm import LLM
from opendevin.observation.error import AgentErrorObservation
from opendevin.observation.message import AgentMessageObservation
from opendevin.observation.run import CmdOutputObservation
from opendevin.schema.config import ConfigType

View File

@@ -1,4 +1,4 @@
from opendevin.action import (
from opendevin.events.action import (
Action,
AddTaskAction,
AgentFinishAction,

View File

@@ -1,4 +1,4 @@
from opendevin.observation import (
from opendevin.events.observation import (
CmdOutputObservation,
Observation,
observation_from_dict,