forked from princeton-nlp/SWE-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of github.com:replayio/SWE-agent into dominik/pro…
…-864-6a-test-initial-runtime-data-hypotheses
- Loading branch information
Showing
9 changed files
with
201 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
# Requirements | ||
|
||
* You are provided `tdd_*` tools to reproduce the issue with one or more golden tests and also check for regressions. | ||
* The output of the last reproduction is always provided to you. | ||
* Failed tests also provide a `CALL_GRAPH_ON_EXCEPTION` containing the entire call hierarchy of all functions from that test. | ||
* Don't submit until the reproduction command proves your fix. | ||
|
||
* IMPORTANT: Always FIRST RUN the `tdd_repro` command to reproduce the issue. | ||
* This provides you with in-depth test failure and runtime information. | ||
* This includes `CALL_GRAPH_ON_EXCEPTION`: It contains the entire call hierarchy of all functions from that test. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
from __future__ import annotations | ||
import os | ||
from typing import Tuple | ||
|
||
from sweagent.utils.log import get_logger | ||
from sweagent.agent.model_cache import json_serialize_file, json_deserialize_file, json_serialize_str, json_deserialize_str, hash_string | ||
|
||
ManualTDDInputEnvVar = "MANUAL_TDD_INPUT_DIRECTORY" | ||
|
||
logger = get_logger("manual_tdd_input") | ||
|
||
class ManualInput: | ||
base_dir: str | None | ||
instance_id: str | None | ||
conversation_path: str | None | ||
continuation_label: str | None | ||
|
||
def __init__(self, conversation_path: str | None, continuation_label: str | None): | ||
self.conversation_path = conversation_path | ||
self.continuation_label = continuation_label | ||
self.base_dir = None | ||
if ManualTDDInputEnvVar in os.environ: | ||
logger.warning("⚠ ManualInput is enabled") | ||
self.base_dir = os.environ[ManualTDDInputEnvVar] | ||
|
||
def enabled(self) -> bool: | ||
return self.base_dir is not None | ||
|
||
def set_instance_id(self, instance_id: str) -> None: | ||
self.instance_id = instance_id | ||
|
||
def _get_conversation_dir(self) -> str: | ||
if self.conversation_path is None: | ||
return os.path.join(self.base_dir, self.instance_id) | ||
return os.path.join(self.base_dir, self.instance_id, self.conversation_path) | ||
|
||
def load_continuation_file(self) -> str | None: | ||
if not self.enabled(): | ||
return None | ||
|
||
try: | ||
with open(os.path.join(self._get_conversation_dir(), f"{self.continuation_label}.md"), "r") as f: | ||
return f.read() | ||
except FileNotFoundError: | ||
return None | ||
|
||
def save_conversation(self, conversation: list[dict[str, str]], patch: str | None) -> None: | ||
if not self.enabled(): | ||
return None | ||
|
||
parent_dir = self._get_conversation_dir() | ||
|
||
# if continuation_label is left off, we're storing the root conversation | ||
if self.continuation_label is None: | ||
self.continuation_label = "root" | ||
|
||
content = json_serialize_str(conversation) | ||
hash = hash_string(content) | ||
|
||
new_subdir = os.path.join(parent_dir, f"{self.continuation_label}-{hash}") | ||
os.makedirs(new_subdir, exist_ok=True) | ||
|
||
with open(os.path.join(new_subdir, "conversation.json"), "w") as f: | ||
f.write(content) | ||
|
||
if patch is not None and patch.strip() != "": | ||
with open(os.path.join(new_subdir, "patch.diff"), "w") as f: | ||
f.write(patch) | ||
|
||
subdir_to_print = new_subdir[len(self.base_dir):] | ||
logger.info(f"Conversation saved to ${ManualTDDInputEnvVar}%s", subdir_to_print) | ||
|
||
def load_conversation(self) -> Tuple[list[dict[str, str]], str] | None: | ||
if not self.enabled(): | ||
return None | ||
|
||
dir = self._get_conversation_dir() | ||
if not os.path.exists(dir): | ||
return None | ||
|
||
conversation_file_path = os.path.join(dir, "conversation.json") | ||
if not os.path.exists(conversation_file_path): | ||
return None | ||
|
||
with open(conversation_file_path, "r") as f: | ||
conversation = json_deserialize_str(f.read()) | ||
|
||
patch_file_path = os.path.join(dir, "patch.diff") | ||
|
||
# a missing patch isn't an error (will happen with the first tdd_repro call) | ||
if os.path.exists(patch_file_path): | ||
with open(patch_file_path, "r") as f: | ||
patch = f.read() | ||
else: | ||
patch = None | ||
|
||
dir_to_print = dir[len(self.base_dir):] | ||
logger.info("Conversation loaded from ${ManualTDDInputEnvVar}%s", dir_to_print) | ||
|
||
return conversation, patch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters