mirror of
https://github.com/OpenHands/OpenHands.git
synced 2025-12-26 05:48:36 +08:00
Fix resolver test (#8530)
This commit is contained in:
parent
f7cb2d0f64
commit
1f827170f4
@ -10,9 +10,8 @@ import openhands
|
||||
def assert_sandbox_config(
|
||||
config: SandboxConfig,
|
||||
base_container_image = SandboxConfig.model_fields["base_container_image"].default,
|
||||
runtime_container_image = "ghcr.io/all-hands-ai/runtime:0.38.0-nikolaik",
|
||||
runtime_container_image = f'ghcr.io/all-hands-ai/runtime:mock-nikolaik', # Default to mock version
|
||||
local_runtime_url = SandboxConfig.model_fields["local_runtime_url"].default,
|
||||
user_id = SandboxConfig.model_fields["user_id"].default,
|
||||
):
|
||||
"""Helper function to assert the properties of the SandboxConfig object."""
|
||||
assert isinstance(config, SandboxConfig)
|
||||
@ -22,17 +21,21 @@ def assert_sandbox_config(
|
||||
assert config.use_host_network is False
|
||||
assert config.timeout == 300
|
||||
assert config.local_runtime_url == local_runtime_url
|
||||
assert config.user_id == user_id
|
||||
|
||||
def test_setup_sandbox_config_default():
|
||||
"""Test default configuration when no images provided and not experimental"""
|
||||
config = IssueResolver._setup_sandbox_config(
|
||||
base_container_image=None,
|
||||
runtime_container_image=None,
|
||||
is_experimental=False,
|
||||
)
|
||||
with mock.patch('openhands.__version__', 'mock'):
|
||||
config = IssueResolver._setup_sandbox_config(
|
||||
base_container_image=None,
|
||||
runtime_container_image=None,
|
||||
is_experimental=False,
|
||||
)
|
||||
|
||||
assert_sandbox_config(
|
||||
config,
|
||||
runtime_container_image='ghcr.io/all-hands-ai/runtime:mock-nikolaik'
|
||||
)
|
||||
|
||||
assert_sandbox_config(config)
|
||||
|
||||
def test_setup_sandbox_config_both_images():
|
||||
"""Test that providing both container images raises ValueError"""
|
||||
@ -74,46 +77,47 @@ def test_setup_sandbox_config_runtime_only():
|
||||
|
||||
def test_setup_sandbox_config_experimental():
|
||||
"""Test configuration when experimental mode is enabled"""
|
||||
config = IssueResolver._setup_sandbox_config(
|
||||
base_container_image=None,
|
||||
runtime_container_image=None,
|
||||
is_experimental=True,
|
||||
)
|
||||
with mock.patch('openhands.__version__', 'mock'):
|
||||
config = IssueResolver._setup_sandbox_config(
|
||||
base_container_image=None,
|
||||
runtime_container_image=None,
|
||||
is_experimental=True,
|
||||
)
|
||||
|
||||
assert_sandbox_config(
|
||||
config,
|
||||
runtime_container_image=None
|
||||
)
|
||||
assert_sandbox_config(
|
||||
config,
|
||||
runtime_container_image=None
|
||||
)
|
||||
|
||||
@mock.patch("openhands.resolver.resolve_issue.os.getuid", return_value=0)
|
||||
@mock.patch("openhands.resolver.resolve_issue.get_unique_uid", return_value=1001)
|
||||
def test_setup_sandbox_config_gitlab_ci(mock_get_unique_uid, mock_getuid):
|
||||
"""Test GitLab CI specific configuration when running as root"""
|
||||
with mock.patch.object(IssueResolver, "GITLAB_CI", True):
|
||||
config = IssueResolver._setup_sandbox_config(
|
||||
base_container_image=None,
|
||||
runtime_container_image=None,
|
||||
is_experimental=False,
|
||||
)
|
||||
|
||||
assert_sandbox_config(
|
||||
config,
|
||||
local_runtime_url="http://localhost",
|
||||
user_id=1001
|
||||
)
|
||||
with mock.patch('openhands.__version__', 'mock'):
|
||||
with mock.patch.object(IssueResolver, "GITLAB_CI", True):
|
||||
config = IssueResolver._setup_sandbox_config(
|
||||
base_container_image=None,
|
||||
runtime_container_image=None,
|
||||
is_experimental=False,
|
||||
)
|
||||
|
||||
assert_sandbox_config(
|
||||
config,
|
||||
local_runtime_url="http://localhost"
|
||||
)
|
||||
|
||||
@mock.patch("openhands.resolver.resolve_issue.os.getuid", return_value=1000)
|
||||
def test_setup_sandbox_config_gitlab_ci_non_root(mock_getuid):
|
||||
"""Test GitLab CI configuration when not running as root"""
|
||||
with mock.patch.object(IssueResolver, "GITLAB_CI", True):
|
||||
config = IssueResolver._setup_sandbox_config(
|
||||
base_container_image=None,
|
||||
runtime_container_image=None,
|
||||
is_experimental=False,
|
||||
)
|
||||
with mock.patch('openhands.__version__', 'mock'):
|
||||
with mock.patch.object(IssueResolver, "GITLAB_CI", True):
|
||||
config = IssueResolver._setup_sandbox_config(
|
||||
base_container_image=None,
|
||||
runtime_container_image=None,
|
||||
is_experimental=False,
|
||||
)
|
||||
|
||||
assert_sandbox_config(
|
||||
config,
|
||||
local_runtime_url="http://localhost",
|
||||
user_id=1000
|
||||
)
|
||||
assert_sandbox_config(
|
||||
config,
|
||||
local_runtime_url="http://localhost"
|
||||
)
|
||||
Loading…
x
Reference in New Issue
Block a user