SWE-agent takes a GitHub issue and tries to automatically fix it, using your LM of choice. It can also be employed for offensive cybersecurity or competitive coding challenges. [NeurIPS 2024]
Merge branch 'main' of github.com:princeton-nlp/swe-agent into reviewer
Kilian Lieretf19f1f8d3ebe
diff --cc sweagent/environment/utils.pyindex 35edf1d7,bea2656c..567f8d8c--- a/sweagent/environment/utils.py+++ b/sweagent/environment/utils.py@@@ -249,7 -237,8 +248,8 @@@ def read_with_timeout_experimental(contif time.time() >= end_time:msg = f"Timeout reached while reading from subprocess.\nCurrent buffer: {buffer.decode()}"raise TimeoutError(msg)- decoded = buffer.decode()+- decoded = buffer.decode("utf-8", errors="backslashreplace")++ decoded = buffer.decode("utf-8", errors="backslashreplace").replace('\r\n', '\n')body = "\n".join(line for line in decoded.splitlines() if not line.startswith(PROCESS_DONE_MARKER_START))_results = PROCESS_DONE_REGEX.search(decoded)if _results is None:diff --cc tests/conftest.pyindex e9f43aa5,c5d5b5ad..d7f2ae5f--- a/tests/conftest.py+++ b/tests/conftest.py@@@ -53,49 -46,6 +53,49 @@@ def test_trajectory_path(test_trajectorreturn traj- @pytest.fixture()+ @pytest.fixturedef test_trajectory(test_trajectory_path):return json.loads(test_trajectory_path.read_text())++[email protected](scope="module")+def test_env_args(+ tmpdir_factory,+) -> Generator[EnvironmentArguments]:+ """This will use a persistent container"""+ local_repo_path = tmpdir_factory.getbasetemp() / "test-repo"+ clone_cmd = ["git", "clone", "https://github.com/swe-agent/test-repo", local_repo_path]+ subprocess.run(clone_cmd, check=True)+ data_path = local_repo_path / "problem_statements" / "1.md"+ test_env_args = EnvironmentArguments(+ data_path=str(data_path),+ repo_path=str(local_repo_path),+ image_name="sweagent/swe-agent:latest",+ container_name="test-container-this-is-a-random-string",+ verbose=True,+ )+ yield test_env_args+ # Cleanup (after session ends)+ client = docker.from_env()+ # fixme (?): What happens if user changed container_name?+ try:+ assert test_env_args.container_name is not None # mypy+ container = client.containers.get(test_env_args.container_name)+ container.remove(force=True)+ except docker.errors.NotFound:+ # Can happen if this fixture never runs because we only do a partial+ # test run+ pass+++@contextmanager+def swe_env_context(env_args):+ """Context manager to make sure we close the shell on the container+ so that we can reuse it.+ """++ env = SWEEnv(env_args)+ try:+ yield env+ finally:+ env.close()diff --cc tests/test_env.pyindex 6db7fc39,a543e3d4..5e88b8bf--- a/tests/test_env.py+++ b/tests/test_env.py@@@ -11,12 -13,52 +11,12 @@@ import yamimport dockerimport docker.errorsfrom sweagent import CONFIG_DIR-from sweagent.environment.swe_env import EnvHook, EnvironmentArguments, SWEEnv--[email protected](scope="module")-def test_env_args(- tmpdir_factory,-):- """This will use a persistent container"""- local_repo_path = tmpdir_factory.getbasetemp() / "test-repo"- clone_cmd = ["git", "clone", "https://github.com/swe-agent/test-repo", local_repo_path]- subprocess.run(clone_cmd, check=True)- data_path = local_repo_path / "problem_statements" / "1.md"- test_env_args = EnvironmentArguments(- data_path=str(data_path),- repo_path=str(local_repo_path),- image_name="sweagent/swe-agent:latest",- container_name="test-container-this-is-a-random-string",- verbose=True,- )- yield test_env_args- # Cleanup (after session ends)- client = docker.from_env()- # fixme (?): What happens if user changed container_name?- try:- container = client.containers.get(test_env_args.container_name)- container.remove(force=True)- except docker.errors.NotFound:- # Can happen if this fixture never runs because we only do a partial- # test run- pass-+from sweagent.environment.swe_env import EnvHook, EnvironmentArguments-@contextmanager-def swe_env_context(env_args):- """Context manager to make sure we close the shell on the container- so that we can reuse it.- """-- env = SWEEnv(env_args)- try:- yield env- finally:- env.close()+from .conftest import swe_env_context- @pytest.mark.slow()+ @pytest.mark.slowdef test_init_swe_env(test_env_args):with swe_env_context(test_env_args) as env:env.reset()@@@ -73,15 -115,7 +73,15 @@@ def test_execute_setup_script(tmp_pathenv.reset()- @pytest.mark.slow()+def test_read_file(tmp_path, test_env_args):+ with swe_env_context(test_env_args) as env:+ env.reset()+ content = env.read_file(Path("tests/filetoread.txt"))+ assert content.splitlines()[-1].strip() == "SWEEnv.read_file"++- @pytest.mark.slow()+ @pytest.mark.slowdef test_execute_environment(tmp_path, test_env_args, capsys):test_env = {"python": "3.6",diff --cc tests/test_run.pyindex b3513024,b5bfa5ad..f9643faa--- a/tests/test_run.py+++ b/tests/test_run.py@@@ -134,26 -137,7 +134,26 @@@ def test_exception_raised(test_script_amain.main()- @pytest.mark.slow()+ "config_file_name", ["config/default_retry.yaml", "tests/test_data/config_files/default_retry_no_breviewer.yaml"]+)+def test_retry_from_config(test_script_args: ScriptArguments, config_file_name):+ agent = AgentArguments(+ model=ModelArguments(+ model_name="instant_empty_submit",+ ),+ config_file=config_file_name,+ )+ assert agent.config is not None+ assert agent.config.review_loop_config is not None+ # Note: Not enough to just replace `config_file`+ test_script_args = replace(test_script_args, agent=agent)+ main = Main(test_script_args)+ main.main()++- @pytest.mark.slow()+ @pytest.mark.slowclass CreateFakeLogFile(MainHook):"""Testing the skip functionality"""