Answer principles round 2: 0 🔴, 2 🟡 (0 misread); workflow-bench hands its effects in as arguments, and no Python file of the repo patches a global
CI / tests (pull_request) Successful in 3m46s
CI / tests (pull_request) Successful in 3m46s
This commit is contained in:
@@ -3,7 +3,6 @@ import pathlib
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
import unittest.mock
|
||||
import uuid
|
||||
|
||||
import advisor_bench
|
||||
@@ -62,17 +61,9 @@ class Orchestration(unittest.TestCase):
|
||||
self.calls, self.heavy = [], []
|
||||
self.start_result = {"subtype": "error_max_budget_usd", "is_error": True, "total_cost_usd": 1.0}
|
||||
self.compact_result, self.strong_result = {}, {}
|
||||
real_run = subprocess.run
|
||||
for patch in (
|
||||
unittest.mock.patch.object(advisor_bench, "REPO", self.repo),
|
||||
unittest.mock.patch.object(handoff_bench, "CASES", {"7": (self.base, merged)}),
|
||||
unittest.mock.patch.object(handoff_bench, "START_BUDGET", 0.25),
|
||||
unittest.mock.patch.object(handoff_bench, "CLAUDE_PROJECTS", self.projects),
|
||||
unittest.mock.patch.object(handoff_bench.uuid, "uuid4", return_value=SESSION),
|
||||
unittest.mock.patch.object(advisor_bench.subprocess, "run", side_effect=lambda args, **kwargs: self.fake(real_run, args, **kwargs)),
|
||||
):
|
||||
patch.start()
|
||||
self.addCleanup(patch.stop)
|
||||
# The prompts the judge was given.
|
||||
self.judged = []
|
||||
self.handoff = handoff_bench.Handoff(advisor_bench.Bench(self.repo, {"7": (self.base, merged)}, self.fake), 0.25, self.projects, lambda: SESSION)
|
||||
self.transcript = self.projects / "slug" / f"{SESSION}.jsonl"
|
||||
|
||||
def commit(self, files):
|
||||
@@ -83,7 +74,11 @@ class Orchestration(unittest.TestCase):
|
||||
commit(self.repo, "a commit")
|
||||
return advisor_bench.git(self.repo, "rev-parse", "HEAD").strip()
|
||||
|
||||
def fake(self, real_run, args, **kwargs):
|
||||
def fake(self, args, **kwargs):
|
||||
"""Stands in for subprocess.run where the bench runs claude or the tests."""
|
||||
if args[0] == "claude" and "--tools" in args:
|
||||
self.judged.append(args[2])
|
||||
return subprocess.CompletedProcess(args, 0, stdout=json.dumps({"result": '{"verdict": "pass"}'}), stderr="")
|
||||
if args[0] == "claude":
|
||||
cwd = pathlib.Path(kwargs["cwd"])
|
||||
# What the run found as it began: the session's transcript and the files under bin/pkg.
|
||||
@@ -92,7 +87,7 @@ class Orchestration(unittest.TestCase):
|
||||
if "--max-budget-usd" in args:
|
||||
(cwd / "bin/pkg/mod.py").write_text("x = 3\n")
|
||||
# Against the bench rules, the worker commits a part of its change.
|
||||
real_run(["git", "-C", str(cwd), "add", "bin/pkg/mod.py"], check=True)
|
||||
subprocess.run(["git", "-C", str(cwd), "add", "bin/pkg/mod.py"], check=True)
|
||||
commit(cwd, "against the rules")
|
||||
(cwd / "bin/pkg/new.py").write_text("n = 1\n")
|
||||
self.transcript.parent.mkdir(parents=True)
|
||||
@@ -113,14 +108,14 @@ class Orchestration(unittest.TestCase):
|
||||
if args[0] == str(advisor_bench.RUN_HEAVY):
|
||||
self.heavy.append(args)
|
||||
return subprocess.CompletedProcess(args, 0, stdout="3 passed\n", stderr="")
|
||||
return real_run(args, **kwargs)
|
||||
raise AssertionError(f"the bench ran {args}")
|
||||
|
||||
def started(self):
|
||||
handoff_bench.start(self.work, "7-1")
|
||||
handoff_bench.start(self.handoff, self.work, "7-1")
|
||||
self.calls.clear()
|
||||
|
||||
def test_start_runs_the_weak_worker_to_its_budget_and_saves_the_tree_and_the_session(self):
|
||||
self.assertEqual(handoff_bench.start(self.work, "7-1"), "7-1: started")
|
||||
self.assertEqual(handoff_bench.start(self.handoff, self.work, "7-1"), "7-1: started")
|
||||
(claude, kwargs, _), = self.calls
|
||||
self.assertEqual(kwargs["cwd"], self.work / "7-1")
|
||||
self.assertEqual((kwargs["stdin"], kwargs["stderr"]), (subprocess.DEVNULL, subprocess.STDOUT))
|
||||
@@ -142,21 +137,21 @@ class Orchestration(unittest.TestCase):
|
||||
def test_start_refuses_a_worker_that_finished_within_its_budget(self):
|
||||
self.start_result = {}
|
||||
with self.assertRaisesRegex(ValueError, "^the weak worker finished within its budget, or its run failed, so there is no handoff to bench$"):
|
||||
handoff_bench.start(self.work, "7-1")
|
||||
handoff_bench.start(self.handoff, self.work, "7-1")
|
||||
|
||||
def test_start_refuses_a_name_that_already_started(self):
|
||||
(self.work / "7-1").mkdir()
|
||||
with self.assertRaisesRegex(ValueError, "already started"):
|
||||
handoff_bench.start(self.work, "7-1")
|
||||
handoff_bench.start(self.handoff, self.work, "7-1")
|
||||
|
||||
def test_start_refuses_a_session_whose_transcript_it_cannot_find(self):
|
||||
self.transcript = self.work / "elsewhere" / f"{SESSION}.jsonl"
|
||||
with self.assertRaisesRegex(ValueError, "found 0"):
|
||||
handoff_bench.start(self.work, "7-1")
|
||||
handoff_bench.start(self.handoff, self.work, "7-1")
|
||||
|
||||
def test_the_resume_arm_resumes_the_weak_workers_session_on_the_strong_rung(self):
|
||||
self.started()
|
||||
self.assertEqual(handoff_bench.run(self.work, "7-resume-1"), "7-resume-1: ran")
|
||||
self.assertEqual(handoff_bench.run(self.handoff, self.work, "7-resume-1"), "7-resume-1: ran")
|
||||
(claude, kwargs, _), = self.calls
|
||||
self.assertEqual(kwargs["cwd"], self.work / "7-1")
|
||||
self.assertEqual(claude[:2] + claude[3:], [
|
||||
@@ -174,7 +169,7 @@ class Orchestration(unittest.TestCase):
|
||||
|
||||
def test_the_compact_arm_has_the_weak_model_compact_the_session_before_the_strong_one_resumes_it(self):
|
||||
self.started()
|
||||
handoff_bench.run(self.work, "7-compact-1")
|
||||
handoff_bench.run(self.handoff, self.work, "7-compact-1")
|
||||
(compact, _, _), (claude, _, found) = self.calls
|
||||
self.assertEqual(compact[:2] + compact[3:], [
|
||||
"claude", "-p", *handoff_bench.WEAK.flags(), "--resume", str(SESSION), "--setting-sources", "project",
|
||||
@@ -187,7 +182,7 @@ class Orchestration(unittest.TestCase):
|
||||
|
||||
def test_the_brief_arm_starts_a_fresh_session_with_the_item_and_the_brief(self):
|
||||
self.started()
|
||||
self.assertEqual(handoff_bench.run(self.work, "7-brief-1"), "7-brief-1: ran")
|
||||
self.assertEqual(handoff_bench.run(self.handoff, self.work, "7-brief-1"), "7-brief-1: ran")
|
||||
(claude, kwargs, _), = self.calls
|
||||
self.assertEqual(kwargs["cwd"], self.work / "7-1")
|
||||
self.assertEqual(claude[:2] + claude[3:], [
|
||||
@@ -200,36 +195,36 @@ class Orchestration(unittest.TestCase):
|
||||
def test_each_arm_begins_on_the_tree_and_the_session_that_start_left(self):
|
||||
self.started()
|
||||
for arm in ("resume", "compact", "brief"):
|
||||
handoff_bench.run(self.work, f"7-{arm}-1")
|
||||
handoff_bench.run(self.handoff, self.work, f"7-{arm}-1")
|
||||
self.assertEqual([found for _, _, found in self.calls if found[0] != "weak\ncompacted\n"], [("weak\n", ["mod.py", "new.py"])] * 3)
|
||||
self.assertNotIn("done_1.py", (self.work / "7-brief-1.diff").read_text())
|
||||
|
||||
def test_run_refuses_an_arm_that_already_ran_or_never_started(self):
|
||||
with self.assertRaisesRegex(ValueError, "start 7-1 first"):
|
||||
handoff_bench.run(self.work, "7-brief-1")
|
||||
handoff_bench.run(self.handoff, self.work, "7-brief-1")
|
||||
self.started()
|
||||
handoff_bench.run(self.work, "7-brief-1")
|
||||
handoff_bench.run(self.handoff, self.work, "7-brief-1")
|
||||
with self.assertRaisesRegex(ValueError, "already ran"):
|
||||
handoff_bench.run(self.work, "7-brief-1")
|
||||
handoff_bench.run(self.handoff, self.work, "7-brief-1")
|
||||
|
||||
def test_run_refuses_an_unknown_arm(self):
|
||||
self.started()
|
||||
with self.assertRaisesRegex(ValueError, "arm"):
|
||||
handoff_bench.run(self.work, "7-sonnet-1")
|
||||
handoff_bench.run(self.handoff, self.work, "7-sonnet-1")
|
||||
|
||||
def test_run_refuses_an_arm_whose_run_ended_in_an_error_before_it_tests(self):
|
||||
self.started()
|
||||
self.strong_result = {"is_error": True, "result": "overloaded"}
|
||||
with unittest.mock.patch.object(advisor_bench, "save_change") as save_change:
|
||||
with self.assertRaisesRegex(ValueError, "ended in an error: overloaded"):
|
||||
handoff_bench.run(self.work, "7-brief-1")
|
||||
save_change.assert_not_called()
|
||||
with self.assertRaisesRegex(ValueError, "ended in an error: overloaded"):
|
||||
handoff_bench.run(self.handoff, self.work, "7-brief-1")
|
||||
self.assertEqual(self.heavy, [])
|
||||
self.assertFalse((self.work / "7-brief-1.diff").exists())
|
||||
|
||||
def test_run_refuses_a_compact_arm_whose_compaction_failed_before_the_strong_model_runs(self):
|
||||
self.started()
|
||||
self.compact_result = {"is_error": True, "result": "no conversation to compact"}
|
||||
with self.assertRaisesRegex(ValueError, "^the run ended in an error: no conversation to compact$"):
|
||||
handoff_bench.run(self.work, "7-compact-1")
|
||||
handoff_bench.run(self.handoff, self.work, "7-compact-1")
|
||||
self.assertEqual([args[2] for args, _, _ in self.calls], ["/compact"])
|
||||
self.assertFalse((self.work / "7-compact-1.jsonl").exists())
|
||||
|
||||
@@ -240,18 +235,20 @@ class Orchestration(unittest.TestCase):
|
||||
handoff_bench.outcome(self.work, "7-brief-1")
|
||||
|
||||
def test_main_grades_with_the_handoff_cases_and_prints_the_summary(self):
|
||||
with unittest.mock.patch("builtins.print") as printed:
|
||||
handoff_bench.main([str(self.work), "start", "7-1"])
|
||||
handoff_bench.main([str(self.work), "run", "7-brief-1"])
|
||||
self.assertEqual([call.args[0] for call in printed.call_args_list], ["7-1: started", "7-brief-1: ran"])
|
||||
with unittest.mock.patch.object(advisor_bench, "grade", return_value="7-brief-1: pass") as grade, unittest.mock.patch("builtins.print") as printed:
|
||||
handoff_bench.main([str(self.work), "grade", "7-brief-1"])
|
||||
grade.assert_called_once_with(self.work, "7-brief-1", handoff_bench.CASES)
|
||||
printed.assert_called_once_with("7-brief-1: pass", flush=True)
|
||||
steps, printed = handoff_bench.steps_of(self.handoff), []
|
||||
handoff_bench.main([str(self.work), "start", "7-1"], steps, printed.append)
|
||||
handoff_bench.main([str(self.work), "run", "7-brief-1"], steps, printed.append)
|
||||
self.assertEqual(printed, ["7-1: started", "7-brief-1: ran"])
|
||||
printed.clear()
|
||||
handoff_bench.main([str(self.work), "grade", "7-brief-1"], steps, printed.append)
|
||||
self.assertEqual(printed, ["7-brief-1: pass"])
|
||||
# The judge saw the handoff case's merged change, so the grade ran over the handoff's cases.
|
||||
(prompt,) = self.judged
|
||||
self.assertIn("-x = 1\n+x = 2\n", prompt)
|
||||
(self.work / "7-brief-1.verdict").write_text(json.dumps({"verdict": "pass"}))
|
||||
with unittest.mock.patch("builtins.print") as printed:
|
||||
handoff_bench.main([str(self.work), "summary"])
|
||||
self.assertIn("| brief | 1 | 1 | 0 | 0.50 | 12 |", printed.call_args.args[0])
|
||||
printed.clear()
|
||||
handoff_bench.main([str(self.work), "summary"], steps, printed.append)
|
||||
self.assertIn("| brief | 1 | 1 | 0 | 0.50 | 12 |", printed[-1])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user