From efec39560d80ebebd4750c6f965910d2d7f7b369 Mon Sep 17 00:00:00 2001 From: Etienne Filhol Date: Wed, 2 Dec 2026 14:03:05 +0100 Subject: [PATCH] fix(catalogue): handle patch encodings and discard stale check rewards --- .../benchmarks/swe-bench-verified/driver.py | 2 +- .../benchmarks/terminal-bench/driver.py | 4 +++- .../terminal-bench/upstream-settings.json | 2 +- app/tests/test_standard_check_safety.py | 23 +++++++++++++++++++ app/tests/test_swebench_patch.py | 14 +++++------ 5 files changed, 35 insertions(+), 10 deletions(-) diff --git a/app/nullius/catalogue/benchmarks/swe-bench-verified/driver.py b/app/nullius/catalogue/benchmarks/swe-bench-verified/driver.py index 3ea800c14..360802e73 100644 --- a/app/nullius/catalogue/benchmarks/swe-bench-verified/driver.py +++ b/app/nullius/catalogue/benchmarks/swe-bench-verified/driver.py @@ -94,7 +94,7 @@ def score(unit, dir, transcript, answer, verified=None): if not verified: return {"reward": 0.0, "passed": False, "detail": {"why": "the instance's tests did not run"}} log = os.path.join(verified["dir"], "test-stdout.txt") - with open(os.path.join(verified["dir"], "model.patch")) as f: + with open(os.path.join(verified["dir"], "model.patch"), encoding="utf-8", errors="replace") as f: patch = f.read() report = get_eval_report(make_test_spec(row(unit)), {"instance_id": unit, "model_patch": patch or None}, log, True) with open(os.path.join(verified["dir"], "report.json"), "w") as f: diff --git a/app/nullius/catalogue/benchmarks/terminal-bench/driver.py b/app/nullius/catalogue/benchmarks/terminal-bench/driver.py index a6da1f8cc..852adf07a 100644 --- a/app/nullius/catalogue/benchmarks/terminal-bench/driver.py +++ b/app/nullius/catalogue/benchmarks/terminal-bench/driver.py @@ -240,7 +240,9 @@ def setup(unit, dir): **({"internet": True} if unit in INTERNET else {}), **({"agent_seconds": agent} if agent else {}), # the task's own agent timeout, not the run's "prepare": PREPARE, - "verify": {"copy": {f"{unit}/tests": "/tests"}, "run": ["bash", "/tests/test.sh"], "collect": LOGS, + "verify": {"copy": {f"{unit}/tests": "/tests"}, + "run": ["bash", "-c", f"rm -f {LOGS}/reward.txt {LOGS}/reward.json && exec bash /tests/test.sh"], + "collect": LOGS, "seconds": (t.get("verifier") or {}).get("timeout_sec") or 900, "network": True, **({"keep_processes": True} if unit in KEEP_PROCESSES else {})}} diff --git a/app/nullius/catalogue/benchmarks/terminal-bench/upstream-settings.json b/app/nullius/catalogue/benchmarks/terminal-bench/upstream-settings.json index ac5ba7deb..a77eaf1b6 100644 --- a/app/nullius/catalogue/benchmarks/terminal-bench/upstream-settings.json +++ b/app/nullius/catalogue/benchmarks/terminal-bench/upstream-settings.json @@ -30,7 +30,7 @@ {"entry": "task.toml", "setting": "environment.gpus", "values": "0 for every task", "default": "0", "nullius": "fixed:0 - no task asks for one"}, {"entry": "task.toml", "setting": "environment.allow_internet", "values": "true for every task", "default": "true", - "nullius": "fixed:false for the agent - its only way out is its model, through the relay; the tests get a network after it ends; said in the limitations"}, + "nullius": "fixed:per-task - public internet for the 38 tasks in the driver's INTERNET list during the agent or reference solution; the other 51 keep only their model route; the tests get a network after it ends"}, {"entry": "harbor run", "setting": "--override-cpus/-memory/-storage/-gpus, -e (docker, daytona, modal ...)", "values": "", "default": "none, docker", "nullius": "not offered - where and on what the container runs, not what is measured; the standard's backends are local and docker"} ] diff --git a/app/tests/test_standard_check_safety.py b/app/tests/test_standard_check_safety.py index e97f54a86..473a97742 100644 --- a/app/tests/test_standard_check_safety.py +++ b/app/tests/test_standard_check_safety.py @@ -461,6 +461,29 @@ def test_a_service_task_keeps_its_processes_and_the_rest_do_not(self): self.assertIs(self.setup_of("hf-model-inference")["verify"]["keep_processes"], True) self.assertIs(self.setup_of("install-windows-3.11")["verify"]["keep_processes"], True) + def test_a_reward_left_by_the_agent_does_not_count(self): + logs = os.path.join(self.tmp, "verifier") + os.makedirs(logs) + script = os.path.join(self.tmp, "test.sh") + step = self.setup_of("regex-log")["verify"] + command = step["run"][-1].replace(step["collect"], logs).replace("/tests/test.sh", script) + for tests, expected in (("exit 1\n", 0.0), (f"echo 1 > {logs}/reward.txt\n", 1.0)): + with self.subTest(tests=tests): + for name in ("reward.txt", "reward.json"): + with open(os.path.join(logs, name), "w") as f: + f.write("1\n") + with open(script, "w") as f: + f.write(tests) + checked = subprocess.run([*step["run"][:-1], command], capture_output=True, timeout=30) + self.assertEqual(checked.returncode, 1 if expected == 0 else 0) + self.assertFalse(os.path.exists(os.path.join(logs, "reward.json"))) + request = {"op": "score", "unit": "regex-log", "dir": self.tmp, + "transcript": [], "answer": "", "verified": {"dir": logs}} + scored = subprocess.run(["python3", os.path.join(TB, "driver.py")], + input=json.dumps(request) + "\n", capture_output=True, text=True, check=True) + result = json.loads(scored.stdout) + self.assertEqual((result["reward"], result["passed"]), (expected, bool(expected))) + def test_all_tasks_have_image_pins_and_only_downloading_tasks_get_internet(self): data = runpy.run_path(os.path.join(TB, "driver.py"), run_name="metadata") self.assertEqual((len(data["ALL"]), len(data["INTERNET"]), len(data["OFFLINE"])), (89, 38, 51)) diff --git a/app/tests/test_swebench_patch.py b/app/tests/test_swebench_patch.py index cdd6c4533..d2be7527b 100644 --- a/app/tests/test_swebench_patch.py +++ b/app/tests/test_swebench_patch.py @@ -112,6 +112,13 @@ def test_missing_patch_is_not_treated_as_a_submission(self): self.driver.score("unit", str(self.root), [], "", verified={"dir": self.driver.RESULTS}) self.grade.assert_not_called() + def test_change_in_another_encoding_is_still_scored(self): + (self.repo / "edit").write_bytes(b"caf\xe9\n") + patch = self.capture() + self.assertIn(b"caf\xe9", patch.read_bytes()) + self.driver.score("unit", str(self.root), [], "", verified={"dir": self.driver.RESULTS}) + self.assertTrue(self.grade.call_args.args[1]["model_patch"]) + class ProCheck(unittest.TestCase): """SWE-bench Pro's check on a made-up task folder: its upstream's capture first, the patch in the collected @@ -209,10 +216,3 @@ def test_check_tells_the_jvm_of_the_proxy_it_is_given(self): self.assertEqual((self.repo / "jvm").read_text(), f"-Xmx1g -Dhttp.proxyHost={host} -Dhttp.proxyPort={port} -Dhttps.proxyHost={host} -Dhttps.proxyPort={port} " "-Daether.connector.http.useSystemProperties=true") - - def test_change_in_another_encoding_is_still_scored(self): - (self.repo / "edit").write_bytes(b"caf\xe9\n") - patch = self.capture() - self.assertIn(b"caf\xe9", patch.read_bytes()) - self.driver.score("unit", str(self.root), [], "", verified={"dir": self.driver.RESULTS}) - self.assertTrue(self.grade.call_args.args[1]["model_patch"])