Refactor config to dataclasses (#1552)

* mypy is invaluable

* fix config, add test

* Add new-style toml support

* add singleton, small doc fixes

* fix some cases of loading toml, clean up, try to make it clearer

* Add defaults_dict for UI

* allow config to be mutable
error handling
fix toml parsing

* remove debug stuff

* Adapt Makefile

* Add defaults for temperature and top_p

* update to CodeActAgent

* comments

* fix unit tests

* implement groups of llm settings (CLI)

* fix merge issue

* small fix sandboxes, small refactoring

* adapt LLM init to accept overrides at runtime

* reading config is enough

* Encapsulate minimally embeddings initialization

* agent bug fix; fix tests

* fix sandboxes tests

* refactor globals in sandboxes to properties
This commit is contained in:
Engel Nyst
2024-05-09 22:48:29 +02:00
committed by GitHub
parent 73693ba416
commit 446eaec1e6
49 changed files with 964 additions and 533 deletions

View File

@@ -2,27 +2,44 @@ from pathlib import Path
import pytest
from opendevin import config
from opendevin.core.config import config
from opendevin.events.action import files
from opendevin.schema import ConfigType
SANDBOX_PATH_PREFIX = '/workspace'
def test_resolve_path():
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 files.resolve_path(Path(SANDBOX_PATH_PREFIX) / 'test.txt', '/workspace') == \
Path(config.get(ConfigType.WORKSPACE_BASE)) / 'test.txt'
assert files.resolve_path(Path(SANDBOX_PATH_PREFIX) / 'subdir' / 'test.txt',
'/workspace') == Path(config.get(ConfigType.WORKSPACE_BASE)) / 'subdir' / 'test.txt'
assert files.resolve_path(Path(SANDBOX_PATH_PREFIX) / 'subdir' / '..' / 'test.txt',
'/workspace') == Path(config.get(ConfigType.WORKSPACE_BASE)) / 'test.txt'
assert (
files.resolve_path('test.txt', '/workspace')
== Path(config.workspace_base) / 'test.txt'
)
assert (
files.resolve_path('subdir/test.txt', '/workspace')
== Path(config.workspace_base) / 'subdir' / 'test.txt'
)
assert (
files.resolve_path(Path(SANDBOX_PATH_PREFIX) / 'test.txt', '/workspace')
== Path(config.workspace_base) / 'test.txt'
)
assert (
files.resolve_path(
Path(SANDBOX_PATH_PREFIX) / 'subdir' / 'test.txt', '/workspace'
)
== Path(config.workspace_base) / 'subdir' / 'test.txt'
)
assert (
files.resolve_path(
Path(SANDBOX_PATH_PREFIX) / 'subdir' / '..' / 'test.txt', '/workspace'
)
== Path(config.workspace_base) / 'test.txt'
)
with pytest.raises(PermissionError):
files.resolve_path(Path(SANDBOX_PATH_PREFIX) / '..' / 'test.txt', '/workspace')
with pytest.raises(PermissionError):
files.resolve_path(Path('..') / 'test.txt', '/workspace')
with pytest.raises(PermissionError):
files.resolve_path(Path('/') / 'test.txt', '/workspace')
assert files.resolve_path('test.txt', '/workspace/test') == \
Path(config.get(ConfigType.WORKSPACE_BASE)) / 'test' / 'test.txt'
assert (
files.resolve_path('test.txt', '/workspace/test')
== Path(config.workspace_base) / 'test' / 'test.txt'
)