Skip to content

Commit

Permalink
fix: custom runtime image won't work for go (#3464)
Browse files Browse the repository at this point in the history
* fix request param for container_image;
add test for go;

* fix go version issue

* update test to detect go version
  • Loading branch information
xingyaoww committed Aug 20, 2024
1 parent a7dfd5b commit c8452f5
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 8 deletions.
2 changes: 1 addition & 1 deletion openhands/runtime/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def _init_user(self, username: str, user_id: int) -> None:

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,
)
Expand Down
42 changes: 35 additions & 7 deletions tests/unit/test_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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)

0 comments on commit c8452f5

Please sign in to comment.