OpenHands/tests/test_fileops.py
Christian Balcom 24b71927c3
fix(backend) changes to improve Command-R+ behavior, plus file i/o error improvements, attempt 2 (#1417)
* Some improvements to prompts, some better exception handling for various file IO errors, added timeout and max return token configurations for the LLM api.

* More monologue prompt improvements

* Dynamically set username provided in prompt.

* Remove absolute paths from llm prompts, fetch working directory from sandbox when resolving paths in fileio operations, add customizable timeout for bash commands, mention said timeout in llm prompt.

* Switched ssh_box to disabling tty echo and removed the logic attempting to delete it from the response afterwards, fixed get_working_directory for ssh_box.

* Update prompts in integration tests to match monologue agent changes.

* Minor tweaks to make merge easier.

* Another minor prompt tweak, better invalid json handling.

* Fix lint error

* More catch-up to fix lint errors introduced by merge.

* Force WORKSPACE_MOUNT_PATH_IN_SANDBOX to match WORKSPACE_MOUNT_PATH in local sandbox mode, combine exception handlers in prompts.py.

---------

Co-authored-by: Jim Su <jimsu@protonmail.com>
Co-authored-by: Engel Nyst <enyst@users.noreply.github.com>
2024-04-28 21:58:53 -04:00

27 lines
1.5 KiB
Python

from opendevin import config
from opendevin.schema import ConfigType
from opendevin.action import fileop
from pathlib import Path
import pytest
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') == \
Path(config.get(ConfigType.WORKSPACE_BASE)) / 'subdir' / 'test.txt'
assert fileop.resolve_path(Path(fileop.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',
'/workspace') == Path(config.get(ConfigType.WORKSPACE_BASE)) / 'subdir' / 'test.txt'
assert fileop.resolve_path(Path(fileop.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')
with pytest.raises(PermissionError):
fileop.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') == \
Path(config.get(ConfigType.WORKSPACE_BASE)) / 'test' / 'test.txt'