From c8452f5813cf13b6653638cb54cdfd75fec4726e Mon Sep 17 00:00:00 2001 From: Xingyao Wang Date: Tue, 20 Aug 2024 23:38:59 +0800 Subject: [PATCH] fix: custom runtime image won't work for go (#3464) * fix request param for container_image; add test for go; * fix go version issue * update test to detect go version --- openhands/runtime/client/client.py | 2 +- tests/unit/test_runtime.py | 42 +++++++++++++++++++++++++----- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/openhands/runtime/client/client.py b/openhands/runtime/client/client.py index ff25e0d4af..3e89fb6fe4 100644 --- a/openhands/runtime/client/client.py +++ b/openhands/runtime/client/client.py @@ -170,7 +170,7 @@ class RuntimeClient: def _init_bash_shell(self, work_dir: str, username: str) -> None: self.shell = pexpect.spawn( - f'su - {username}', + f'su {username}', encoding='utf-8', echo=False, ) diff --git a/tests/unit/test_runtime.py b/tests/unit/test_runtime.py index 2265830486..16acd2f049 100644 --- a/tests/unit/test_runtime.py +++ b/tests/unit/test_runtime.py @@ -83,17 +83,24 @@ def enable_auto_lint(request): return request.param -@pytest.fixture(scope='module') +@pytest.fixture(scope='module', params=None) def container_image(request): time.sleep(1) env_image = os.environ.get('SANDBOX_CONTAINER_IMAGE') if env_image: - return [env_image] - return [ - 'nikolaik/python-nodejs:python3.11-nodejs22', - 'python:3.11-bookworm', - 'node:22-bookworm', - ] + request.param = env_image + else: + if request.param is None: + request.param = request.config.getoption('--container-image') + if request.param is None: + request.param = pytest.param( + 'nikolaik/python-nodejs:python3.11-nodejs22', + 'python:3.11-bookworm', + 'node:22-bookworm', + 'golang:1.23-bookworm', + ) + print(f'Container image: {request.param}') + return request.param async def _load_runtime( @@ -1390,3 +1397,24 @@ async def test_nodejs_22_version(temp_dir, box_class, container_image): await runtime.close() await asyncio.sleep(1) + + +@pytest.mark.asyncio +async def test_go_version(temp_dir, box_class, container_image): + """Make sure Go is available in bash.""" + if container_image not in [ + 'golang:1.23-bookworm', + ]: + pytest.skip('This test is only for go-related images') + + runtime = await _load_runtime(temp_dir, box_class, container_image=container_image) + + action = CmdRunAction(command='go version') + logger.info(action, extra={'msg_type': 'ACTION'}) + obs = await runtime.run_action(action) + logger.info(obs, extra={'msg_type': 'OBSERVATION'}) + assert obs.exit_code == 0 + assert 'go1.23' in obs.content # Check for specific version + + await runtime.close() + await asyncio.sleep(1)