Skip to content

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]

CI: Add network interface; tighten testing for enigma

Kilian Lieret57fc573fd154
diff --git a/.github/workflows/pytest.yaml b/.github/workflows/pytest.yaml
index 19eb15a1..c7f91591 100644
--- a/.github/workflows/pytest.yaml
+++ b/.github/workflows/pytest.yaml
@@ -42,6 +42,9 @@ jobs:
- name: Pull enigma docker container
run: |
docker pull sweagent/enigma:latest
+ - name: Set up network for CTF challenges
+ run: |
+ docker network create ctfnet
- name: Create keys.cfg
run: |
touch keys.cfg
@@ -60,8 +63,7 @@ jobs:
with:
name: trajectories
path: |
- trajectories
- !trajectories/demonstrations/**
+ trajectories/runner/
- name: Explicitly convert coverage to xml
run: coverage xml
- name: Upload coverage reports to Codecov
diff --git a/tests/test_replay_ctf.py b/tests/test_replay_ctf.py
index 53c46b68..02a1ad5c 100644
--- a/tests/test_replay_ctf.py
+++ b/tests/test_replay_ctf.py
@@ -1,16 +1,70 @@
from __future__ import annotations
+import copy
import sys
+from typing import Any
import pytest
from run_replay import get_args, main
-_TEST_OUTPUTS = {
- "pwn/warmup.traj": r"Closed connection to pwn.chal.csaw.io port 8000\nFLAG{LET_US_BEGIN_CSAW_2016}",
- "forensics/flash.traj": r"the black flag waved night and day from the",
+LOG_NOT_CONTAINS_DEFAULT = [
+ "Traceback",
+ "Exception",
+ "socket.gaierror",
+]
+
+
+class ReplayRunValidator:
+ def __init__(
+ self,
+ *,
+ log_contains: list[str] | None = None,
+ log_not_contains: list[str] | None = None,
+ expected_traj: str | None = None,
+ ):
+ if log_contains is None:
+ log_contains = []
+ if log_not_contains is None:
+ log_not_contains = copy.copy(LOG_NOT_CONTAINS_DEFAULT)
+ self._log_contains = log_contains
+ self._log_not_contains = log_not_contains + LOG_NOT_CONTAINS_DEFAULT
+ self._expected_traj = expected_traj
+
+ def _sanitize_observation(self, observation: str) -> str:
+ # exclude everything that looks like a path
+ return "\n".join(line for line in observation.splitlines() if "/" not in line).strip()
+
+ def _sanitize_traj(self, traj: dict[str, Any]) -> dict[str, Any]:
+ traj = copy.deepcopy(traj)
+ # can restore later
+ observations = [self._sanitize_observation(t["observation"]) for t in traj["trajectory"]]
+ return {"trajectory": observations}
+
+ def __call__(self, stdout: str, traj: str | None = None) -> None:
+ for log in self._log_contains:
+ assert log in stdout, log
+ for log in self._log_not_contains:
+ assert log not in stdout, log
+ if self._expected_traj is not None:
+ assert traj == self._expected_traj
+
+
+_REPLAY_TESTS = {
+ "pwn/warmup.traj": ReplayRunValidator(
+ log_contains=[
+ "File updated.",
+ "Opening connection to pwn.chal.csaw.io on port 8000: Done",
+ "Receiving all data",
+ ],
+ ),
+ "forensics/flash.traj": ReplayRunValidator(
+ log_contains=["the black flag waved night and day from the"],
+ ),
# "web/i_got_id_demo.traj": r"4365",
- "misc/networking_1.traj": r"Password: \nflag{d316759c281bf925d600be698a4973d5}",
+ "misc/networking_1.traj": ReplayRunValidator(
+ log_contains=["Password: "],
+ ),
}
@@ -44,6 +98,6 @@ def test_ctf_traj_replay(test_ctf_trajectories_path, traj_rel_path, ctf_data_pat
]
args, remaining_args = get_args(args)
main(**vars(args), forward_args=remaining_args)
- # captured = capsys.readouterr()
- # if traj_rel_path in _TEST_OUTPUTS:
- # assert _TEST_OUTPUTS[traj_rel_path] in captured.out
+ captured = capsys.readouterr()
+ if traj_rel_path in _REPLAY_TESTS:
+ _REPLAY_TESTS[traj_rel_path](stdout=captured.out)