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

This commit is contained in:
2026-11-19 12:55:35 +01:00
parent cb3135bc8c
commit 762614353c
18 changed files with 335 additions and 231 deletions
+41 -22
View File
@@ -13,11 +13,13 @@ Run each arm of each case once; the table shows a direction, not a significance.
"""
import concurrent.futures
import dataclasses
import functools
import json
import pathlib
import re
import subprocess
import sys
import typing
BENCH = pathlib.Path(__file__).resolve().parent
REPO = BENCH.parent
@@ -52,6 +54,17 @@ VERDICTS = ("pass", "partial", "fail")
JUDGE = Arm("claude-opus-5-5", "medium")
@dataclasses.dataclass(frozen=True)
class Bench:
"""What a bench's steps act on, which the script's entry point hands them."""
# The repo whose archived chunks the bench reruns.
repo: pathlib.Path
# Each case's start commit and the commit it merged at, by todo item.
cases: dict
# Runs claude and the tests, as subprocess.run does.
process: typing.Callable
@dataclasses.dataclass(frozen=True)
class Outcome:
cost: float
@@ -124,51 +137,51 @@ def git(repo, *args):
return subprocess.run(["git", "-C", str(repo), *args], check=True, capture_output=True, text=True).stdout
def fresh_clone(base, dest):
"""A clone of this repo at base, with no remote to push to."""
subprocess.run(["git", "clone", "-q", "--no-local", str(REPO), str(dest)], check=True)
def fresh_clone(repo, base, dest):
"""A clone of repo at base, with no remote to push to."""
subprocess.run(["git", "clone", "-q", "--no-local", str(repo), str(dest)], check=True)
git(dest, "checkout", "-q", "--detach", base)
git(dest, "remote", "remove", "origin")
def run(work, name):
def run(bench, work, name):
"""One worker run of <case>-<arm>-<n>; the files it leaves are in the module docstring."""
case, arm, _ = split_name(name)
base = CASES[case][0]
base = bench.cases[case][0]
clone = work / name
if clone.exists():
raise ValueError(f"{name} already ran: remove {clone}")
fresh_clone(base, clone)
prompt = (BENCH / "advisor-run-prompt.md").read_text().format(base=base, item=case, text=item_text(git(REPO, "show", f"{base}:todo.md"), case))
fresh_clone(bench.repo, base, clone)
prompt = (BENCH / "advisor-run-prompt.md").read_text().format(base=base, item=case, text=item_text(git(bench.repo, "show", f"{base}:todo.md"), case))
with (work / f"{name}.jsonl").open("w") as out:
subprocess.run(
bench.process(
["claude", "-p", prompt, *ARMS[arm].flags(), "--setting-sources", "project", "--permission-mode", "bypassPermissions",
"--no-session-persistence", "--output-format", "stream-json", "--verbose"],
cwd=clone, stdout=out, stderr=subprocess.STDOUT)
read_result((work / f"{name}.jsonl").read_text().splitlines())
save_change(work, name, clone, CASES[case])
save_change(bench, work, name, clone, bench.cases[case])
return f"{name}: ran"
def save_change(work, name, clone, commits):
def save_change(bench, work, name, clone, commits):
"""Save the clone's change since the case's start commit as <name>.diff, and as <name>.tests the result of the tests of the packages that the clone's change or the merged change touches."""
base, merged = commits
git(clone, "add", "--all")
(work / f"{name}.diff").write_text(git(clone, "diff", "--cached", base))
changed = [*git(clone, "diff", "--cached", "--name-only", base).split(), *git(REPO, "diff", "--name-only", base, merged).split()]
changed = [*git(clone, "diff", "--cached", "--name-only", base).split(), *git(bench.repo, "diff", "--name-only", base, merged).split()]
targets = [target for target in suite_targets(changed) if (clone / target).exists()] or ["bin"]
tests = subprocess.run([str(RUN_HEAVY), *SUITE, *targets], cwd=clone, capture_output=True, text=True)
tests = bench.process([str(RUN_HEAVY), *SUITE, *targets], cwd=clone, capture_output=True, text=True)
(work / f"{name}.tests").write_text(f"exit {tests.returncode}\n{tests.stdout[-1500:]}")
def grade(work, name, cases=None):
"""Have the judge rule on one run's diff, blind to its arm, and save the verdict beside it. cases stands in for CASES where another bench grades its own."""
def grade(bench, work, name):
"""Have the judge rule on one run's diff, blind to its arm, and save the verdict beside it."""
case = split_name(name)[0]
base, merged = (cases or CASES)[case]
base, merged = bench.cases[case]
prompt = (BENCH / "advisor-judge-prompt.md").read_text().format(
text=item_text(git(REPO, "show", f"{base}:todo.md"), case), reference=git(REPO, "diff", base, merged, "--", ".", ":!todo.md", ":!docs", ":!CHANGELOG.md"),
text=item_text(git(bench.repo, "show", f"{base}:todo.md"), case), reference=git(bench.repo, "diff", base, merged, "--", ".", ":!todo.md", ":!docs", ":!CHANGELOG.md"),
diff=(work / f"{name}.diff").read_text(), tests=(work / f"{name}.tests").read_text())
reply = subprocess.run(
reply = bench.process(
["claude", "-p", prompt, *JUDGE.flags(), "--setting-sources", "", "--no-session-persistence", "--output-format", "json", "--tools", ""],
capture_output=True, text=True, check=True).stdout
verdict = verdict_of(reply)
@@ -196,15 +209,21 @@ def rows_of(work):
return rows
def main(argv):
def steps_of(bench):
"""The steps main runs by name, each on bench."""
return {"run": functools.partial(run, bench), "grade": functools.partial(grade, bench)}
def main(argv, steps, say):
"""Runs the step argv names on each run it names, and hands say each result line; or hands say the summary."""
work, step, names = pathlib.Path(argv[0]), argv[1], argv[2:]
if step == "summary":
print(summary(rows_of(work)))
say(summary(rows_of(work)))
return
with concurrent.futures.ThreadPoolExecutor(max_workers=3) as pool:
for result in pool.map(lambda name: attempted({"run": run, "grade": grade}[step], work, name), names):
print(result, flush=True)
for result in pool.map(lambda name: attempted(steps[step], work, name), names):
say(result)
if __name__ == "__main__":
main(sys.argv[1:])
main(sys.argv[1:], steps_of(Bench(REPO, CASES, subprocess.run)), functools.partial(print, flush=True))