Skip to content

Commit 59e7751

Browse files
Ethan-Kuang-6666Yi Kuang
andauthored
fix(run): pass the startup_command as a dict to env.execute() function. (#880)
Co-authored-by: Yi Kuang <y24kuang@uwaterloo.ca>
1 parent 67995b2 commit 59e7751

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

src/minisweagent/run/benchmarks/swebench.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def get_sb_environment(config: dict, instance: dict) -> Environment:
8888
env = get_environment(env_config)
8989
if startup_command := config.get("run", {}).get("env_startup_command"):
9090
startup_command = Template(startup_command, undefined=StrictUndefined).render(**instance)
91-
out = env.execute(startup_command)
91+
out = env.execute({"command": startup_command})
9292
if out["returncode"] != 0:
9393
raise RuntimeError(f"Error executing startup command: {out}")
9494
return env

tests/run/test_swebench.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import json
22
import re
3-
from unittest.mock import patch
3+
from unittest.mock import MagicMock, patch
44

55
import pytest
66
from pydantic import BaseModel
@@ -9,6 +9,7 @@
99
from minisweagent.models.test_models import DeterministicModel, make_output
1010
from minisweagent.run.benchmarks.swebench import (
1111
filter_instances,
12+
get_sb_environment,
1213
get_swebench_docker_image_name,
1314
main,
1415
remove_from_preds_file,
@@ -103,6 +104,20 @@ def test_get_image_name_with_complex_instance_id():
103104
assert get_swebench_docker_image_name(instance) == expected
104105

105106

107+
def test_get_sb_environment_runs_startup_command_as_dict():
108+
"""startup_command must be passed to env.execute() as a dict, not a bare string."""
109+
fake_env = MagicMock()
110+
fake_env.execute.return_value = {"returncode": 0, "output": ""}
111+
instance = {"instance_id": "repo1__test1", "image_name": "custom/image:tag"}
112+
# The startup_command with {{instance_id}} tested the Jinja render as well.
113+
config = {"run": {"env_startup_command": "echo {{instance_id}}"}}
114+
115+
with patch("minisweagent.run.benchmarks.swebench.get_environment", return_value=fake_env):
116+
get_sb_environment(config, instance)
117+
118+
fake_env.execute.assert_called_once_with({"command": "echo repo1__test1"})
119+
120+
106121
def test_filter_instances_no_filters():
107122
"""Test filter_instances with no filtering applied"""
108123
instances = [{"instance_id": "repo1__test1"}, {"instance_id": "repo2__test2"}, {"instance_id": "repo3__test3"}]

0 commit comments

Comments
 (0)