Skip to content

πŸ™Œ OpenHands: AI-Driven Development

fix: custom runtime image won't work for go (#3464)

Xingyao Wangc8452f5813cf
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
[email protected](scope='module')
[email protected](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)
+
+
+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)