OpenHands/tests/e2e/test_local_runtime.py
Xingyao Wang c2f46200c0
chore(lint): Apply comprehensive linting and formatting fixes (#10287)
Co-authored-by: openhands <openhands@all-hands.dev>
2025-08-13 21:13:19 +02:00

62 lines
2.2 KiB
Python

import os
import shutil
import subprocess
import tempfile
def test_headless_mode_with_dummy_agent_no_browser():
"""E2E test: build a docker image from python:3.13, install openhands from source,
and run a local runtime task in headless mode.
"""
repo_root = os.path.abspath(os.path.join(os.path.dirname(__file__), '../../'))
dockerfile = """
FROM python:3.13-slim
WORKDIR /src
RUN apt-get update && apt-get install -y git build-essential tmux
COPY . /src
RUN pip install --upgrade pip setuptools wheel
RUN pip install .
ENV PYTHONUNBUFFERED=1
ENV RUNTIME=local
ENV RUN_AS_OPENHANDS=false
ENV ENABLE_BROWSER=false
ENV AGENT_ENABLE_BROWSING=false
ENV SKIP_DEPENDENCY_CHECK=1
CMD ["python", "-m", "openhands.core.main", "-c", "DummyAgent", "-t", "Hello world"]
"""
with tempfile.TemporaryDirectory() as tmpdir:
dockerfile_path = os.path.join(tmpdir, 'Dockerfile')
with open(dockerfile_path, 'w') as f:
f.write(dockerfile)
# Copy the repo into the temp dir for docker build context
build_context = os.path.join(tmpdir, 'context')
shutil.copytree(repo_root, build_context, dirs_exist_ok=True)
image_tag = 'openhands-e2e-local-runtime-test'
build_cmd = [
'docker',
'build',
'-t',
image_tag,
'-f',
dockerfile_path,
build_context,
]
run_cmd = ['docker', 'run', '--rm', image_tag]
# Build the image
build_proc = subprocess.run(build_cmd, capture_output=True, text=True)
print('Docker build stdout:', build_proc.stdout)
print('Docker build stderr:', build_proc.stderr)
assert build_proc.returncode == 0, 'Docker build failed'
# Run the container
run_proc = subprocess.run(run_cmd, capture_output=True, text=True)
print('Docker run stdout:', run_proc.stdout)
print('Docker run stderr:', run_proc.stderr)
assert run_proc.returncode == 0, (
f'Docker run failed with code {run_proc.returncode}'
)
assert 'Warning: Observation mismatch' not in run_proc.stdout