Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/minisweagent/environments/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ def _check_finished(self, output: dict):
)

def cleanup(self):
"""Stop and remove the Docker container."""
"""Stop the Docker container."""
if getattr(self, "container_id", None) is not None: # if init fails early, container_id might not be set
cmd = f"(timeout 60 {self.config.executable} stop {self.container_id} || {self.config.executable} rm -f {self.container_id}) >/dev/null 2>&1 &"
cmd = f"(timeout 60 {self.config.executable} stop {self.container_id} || {self.config.executable} kill {self.container_id}) >/dev/null 2>&1 &"
subprocess.Popen(cmd, shell=True)

def __del__(self):
Expand Down
15 changes: 15 additions & 0 deletions tests/environments/test_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,21 @@ def test_docker_environment_config_defaults(executable):
assert config.executable == executable


def test_docker_cleanup_stops_or_kills_container():
"""Test that cleanup leaves removal policy to the configured run args."""
env = DockerEnvironment.__new__(DockerEnvironment)
env.container_id = "minisweagent-test"
env.config = DockerEnvironmentConfig(image="python:3.11", executable="docker")

with patch("subprocess.Popen") as popen:
env.cleanup()

popen.assert_called_once_with(
"(timeout 60 docker stop minisweagent-test || docker kill minisweagent-test) >/dev/null 2>&1 &",
shell=True,
)


@pytest.mark.slow
@pytest.mark.parametrize("executable", environment_params)
def test_docker_environment_basic_execution(executable):
Expand Down