update: terminal run command 改为异步

This commit is contained in:
seeker 2024-07-05 19:53:05 +08:00
parent 48062fff9f
commit ff5dbfbc52
4 changed files with 81 additions and 66 deletions

View file

@ -59,11 +59,11 @@ async def run(instance, swe_result_dir):
# 前处理
terminal = Terminal()
terminal.run_command(f"cd {repo_path} && git reset --hard && git clean -n -d && git clean -f -d")
terminal.run_command("BRANCH=$(git remote show origin | awk '/HEAD branch/ {print $NF}')")
logger.info(terminal.run_command("echo $BRANCH"))
logger.info(terminal.run_command('git checkout "$BRANCH"'))
logger.info(terminal.run_command("git branch"))
await terminal.run_command(f"cd {repo_path} && git reset --hard && git clean -n -d && git clean -f -d")
await terminal.run_command("BRANCH=$(git remote show origin | awk '/HEAD branch/ {print $NF}')")
logger.info(await terminal.run_command("echo $BRANCH"))
logger.info(await terminal.run_command('git checkout "$BRANCH"'))
logger.info(await terminal.run_command("git branch"))
user_requirement_and_issue = INSTANCE_TEMPLATE.format(
issue=instance["problem_statement"],

View file

@ -4,16 +4,17 @@ from metagpt.const import DATA_PATH, METAGPT_ROOT
from metagpt.tools.libs.terminal import Terminal
def test_terminal():
@pytest.mark.asyncio
async def test_terminal():
terminal = Terminal()
terminal.run_command(f"cd {METAGPT_ROOT}")
output = terminal.run_command("pwd")
await terminal.run_command(f"cd {METAGPT_ROOT}")
output = await terminal.run_command("pwd")
assert output.strip() == str(METAGPT_ROOT)
# pwd now should be METAGPT_ROOT, cd data should land in DATA_PATH
terminal.run_command("cd data")
output = terminal.run_command("pwd")
await terminal.run_command("cd data")
output = await terminal.run_command("pwd")
assert output.strip() == str(DATA_PATH)