π OpenHands: AI-Driven Development
Fix workspace paths defaults (#1845)
Engel Nystb3a45ed7fe52
diff --git a/opendevin/core/config.py b/opendevin/core/config.pyindex a9f1fd2f31..994436816c 100644--- a/opendevin/core/config.py+++ b/opendevin/core/config.py@@ -73,8 +73,8 @@ class AppConfig(metaclass=Singleton):runtime: str = 'server'file_store: str = 'memory'file_store_path: str = '/tmp/file_store'- workspace_base: str = os.getcwd()- workspace_mount_path: str = os.getcwd()+ workspace_base: str = os.path.join(os.getcwd(), 'workspace')+ workspace_mount_path: str | None = Noneworkspace_mount_path_in_sandbox: str = '/workspace'workspace_mount_rewrite: str | None = Nonecache_dir: str = '/tmp/cache'@@ -264,6 +264,11 @@ def finalize_config(config: AppConfig):More tweaks to the config after it's been loaded."""+ # Set workspace_mount_path if not set by the user+ if config.workspace_mount_path is None:+ config.workspace_mount_path = os.path.abspath(config.workspace_base)+ config.workspace_base = os.path.abspath(config.workspace_base)+# In local there is no sandbox, the workspace will have the same pwd as the hostif config.sandbox_type == 'local':config.workspace_mount_path_in_sandbox = config.workspace_mount_pathdiff --git a/tests/unit/test_config.py b/tests/unit/test_config.pyindex 84c8b2af57..8b8cdb3d62 100644--- a/tests/unit/test_config.py+++ b/tests/unit/test_config.py@@ -28,6 +28,20 @@ def setup_env():os.remove('new_style_config.toml')+def temp_toml_file(tmp_path):+ # Fixture to create a temporary directory and TOML file for testing+ tmp_toml_file = os.path.join(tmp_path, 'config.toml')+ yield tmp_toml_file+++def default_config(monkeypatch):+ # Fixture to provide a default AppConfig instance+ AppConfig.reset()+ yield AppConfig()++def test_compat_env_to_config(monkeypatch, setup_env):# Use `monkeypatch` to set environment variables for this specific testmonkeypatch.setenv('WORKSPACE_BASE', '/repos/opendevin/workspace')@@ -49,20 +63,6 @@ def test_compat_env_to_config(monkeypatch, setup_env):assert config.agent.memory_max_threads == 4-def temp_toml_file(tmp_path):- # Fixture to create a temporary directory and TOML file for testing- tmp_toml_file = os.path.join(tmp_path, 'config.toml')- yield tmp_toml_file---def default_config(monkeypatch):- # Fixture to provide a default AppConfig instance- AppConfig.reset()- yield AppConfig()--def test_load_from_old_style_env(monkeypatch, default_config):# Test loading configuration from old-style environment variables using monkeypatchmonkeypatch.setenv('LLM_API_KEY', 'test-api-key')@@ -171,3 +171,42 @@ def test_finalize_config(default_config):default_config.workspace_mount_path_in_sandbox== default_config.workspace_mount_path)+++# tests for workspace, mount path, path in sandbox, cache dir+def test_workspace_mount_path_default(default_config):+ assert default_config.workspace_mount_path is None+ finalize_config(default_config)+ assert default_config.workspace_mount_path == os.path.abspath(+ default_config.workspace_base+ )+++def test_workspace_mount_path_in_sandbox_local(default_config):+ assert default_config.workspace_mount_path_in_sandbox == '/workspace'+ default_config.sandbox_type = 'local'+ finalize_config(default_config)+ assert (+ default_config.workspace_mount_path_in_sandbox+ == default_config.workspace_mount_path+ )+++def test_workspace_mount_rewrite(default_config, monkeypatch):+ default_config.workspace_base = '/home/user/project'+ default_config.workspace_mount_rewrite = '/home/user:/sandbox'+ monkeypatch.setattr('os.getcwd', lambda: '/current/working/directory')+ finalize_config(default_config)+ assert default_config.workspace_mount_path == '/sandbox/project'+++def test_embedding_base_url_default(default_config):+ default_config.llm.base_url = 'https://api.exampleapi.com'+ finalize_config(default_config)+ assert default_config.llm.embedding_base_url == 'https://api.exampleapi.com'+++def test_cache_dir_creation(default_config, tmpdir):+ default_config.cache_dir = str(tmpdir.join('test_cache'))+ finalize_config(default_config)+ assert os.path.exists(default_config.cache_dir)