Answer stability round 1: 0 🔴, 10 🟡 (0 misread); take the failed test's last message, fail on a docker run that never started, keep testdata as planted, show finished runs when the API refuses one, and test five survivors

This commit is contained in:
2026-11-21 02:41:36 +01:00
parent 1e96a397af
commit 8c1edf552a
9 changed files with 275 additions and 112 deletions
+43 -20
View File
@@ -30,13 +30,19 @@ DOCKERFILE = 'FROM {image}\nUSER root\nRUN curl -fsSL https://claude.ai/install.
BUILD_SECONDS = 20 * 60
# How long one fix, or one run of the tests, may take before its container is removed; the run then counts as not passed.
RUN_SECONDS = 30 * 60
# What `docker run` exits with where the container, or its command, never started.
NOT_STARTED = (125, 126, 127)
# The memory each container gets without run-heavy, which hands its slot's share in RUN_HEAVY_MEMORY, in MiB.
MEMORY_MIB = 4096
class TimedOut(Failure):
"""docker still ran when its time was up."""
class Docker(typing.Protocol):
"""Runs `docker <args>` and waits for it, at most `seconds`. Its output goes to `stdout` and its errors to `stderr` where the
call gives them, and into the Ran otherwise."""
"""Runs `docker <args>` and waits for it, at most `seconds`, and is TimedOut after that. Its output goes to `stdout` and its
errors to `stderr` where the call gives them, and into the Ran otherwise."""
def __call__(self, args: list[str], *, seconds: float, stdin: str | None = None, stdout: typing.IO[bytes] | None = None, stderr: typing.IO[bytes] | None = None) -> Ran | Failure: ...
@@ -48,7 +54,7 @@ def docker_cli(env: typing.Mapping[str, str], run: typing.Callable[..., subproce
except OSError as failure:
return Failure(f"docker could not start: {failure.strerror}")
except subprocess.TimeoutExpired:
return Failure(f"docker {args[0]} still ran after {round(seconds / 60)} min")
return TimedOut(f"docker {args[0]} still ran after {round(seconds / 60)} min")
return Ran(ran.returncode, (ran.stdout or b"").decode("utf-8", errors="replace"))
return docker
@@ -100,18 +106,16 @@ def opened(containers: Containers, image: str) -> Failure | None:
def closed(containers: Containers) -> None:
"""Removes what `opened` made and any container still running, where each exists; a bench that broke half-way leaves the rest."""
"""Removes what `opened` made and any container still running. A bench that broke half-way made only some of them, and removing
one that is missing doesn't stop the rest."""
for args in (["rm", "--force", containers.running], ["rm", "--force", containers.proxy], ["network", "rm", containers.name], ["image", "rm", containers.image]):
containers.docker(args, seconds=120)
def ran_tests(containers: Containers, tree: str) -> Ran | Failure:
"""The project's test command, run at the top of tree with no network; the tests pass where it exits 0. A Failure where it still
ran after RUN_SECONDS."""
ran = containers.docker(["run", "--rm", "--name", containers.running, "--network", "none", *in_tree(containers, tree), containers.image, "sh", "-c", containers.test], seconds=RUN_SECONDS)
if isinstance(ran, Failure):
containers.docker(["rm", "--force", containers.running], seconds=120)
return ran
"""The project's test command, run at the top of tree with no network; the tests pass where it exits 0. TimedOut where it still
ran after RUN_SECONDS, and a Failure where docker could not run it."""
return run_in_image(containers, ["--network", "none", *in_tree(containers, tree), containers.image, "sh", "-c", containers.test])
def fix_attempted(containers: Containers, copy: str, message: str, stream: pathlib.Path) -> Failure | None:
@@ -119,18 +123,32 @@ def fix_attempted(containers: Containers, copy: str, message: str, stream: pathl
errors beside it. A fix that still runs after RUN_SECONDS ends there, with the stream as far as it came.
The container's home is new and empty, so no instruction, memory, hook, skill or plugin of the caller loads; and docker hands the
token on by its name, so its value is on no command line. A Failure where docker itself could not run."""
args = ["run", "--rm", "--name", containers.running, "--network", containers.name, *in_tree(containers, copy), "--env", TOKEN, "--env", f"HTTPS_PROXY=http://{containers.proxy}:{PORT}", "--env", "CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1", containers.image, *CLAUDE, PROMPT.format(message=message)]
token on by its name, so its value is on no command line. A Failure where docker could not run claude."""
args = ["--network", containers.name, *in_tree(containers, copy), "--env", TOKEN, "--env", f"HTTPS_PROXY=http://{containers.proxy}:{PORT}", "--env", "CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1", containers.image, *CLAUDE, PROMPT.format(message=message)]
errors_file = stream.with_suffix(".stderr")
try:
with stream.open("wb") as out, stream.with_suffix(".stderr").open("wb") as errors:
ran = containers.docker(args, seconds=RUN_SECONDS, stdout=out, stderr=errors)
with stream.open("wb") as out, errors_file.open("wb") as errors:
ran = run_in_image(containers, args, stdout=out, stderr=errors)
except OSError as failure:
return Failure(f"could not write {stream}: {failure}")
# Out of time is the run's outcome, not the bench's failure.
if isinstance(ran, TimedOut) or not isinstance(ran, Failure):
return None
return Failure(f"{ran.reason}; its errors are in {errors_file}")
def run_in_image(containers: Containers, args: list[str], stdout: typing.IO[bytes] | None = None, stderr: typing.IO[bytes] | None = None) -> Ran | Failure:
"""One `docker run` as the bench's one running container, for at most RUN_SECONDS, after which the container is removed.
A run whose command never started is a Failure, since the next would end the same: counted as a fix that failed, it would fill
the table with runs that measured docker."""
ran = containers.docker(["run", "--rm", "--name", containers.running, *args], seconds=RUN_SECONDS, stdout=stdout, stderr=stderr)
if isinstance(ran, Failure):
containers.docker(["rm", "--force", containers.running], seconds=120)
# Out of time is the run's outcome, not the bench's failure.
return None if "still ran" in ran.reason else ran
return None
return ran
if ran.code in NOT_STARTED:
return Failure(f"docker run could not start its command, and exited {ran.code}: {ran.output.strip()}".removesuffix(": "))
return ran
def in_tree(containers: Containers, tree: str) -> list[str]:
@@ -140,19 +158,20 @@ def in_tree(containers: Containers, tree: str) -> list[str]:
def checked_tree(planted: str, copy: str, into: str) -> None:
"""Makes at `into` the tree the tests check a fix in: `planted`, the code with the bug as Haiku got it, with each file that is no
test as `copy` holds it after the fix. So a test Haiku changed, removed or added counts for nothing.
test as `copy` holds it after the fix. So a test Haiku changed, removed or added doesn't count, and neither does a file under
a `testdata` folder, where Go's tests keep the output they expect.
Raises OSError where a file cannot be copied."""
shutil.copytree(planted, into, symlinks=True)
before, after = set(entries(planted)), set(entries(copy))
for path in before - after:
if not is_test(path):
if not of_tests(path):
with contextlib.suppress(FileNotFoundError):
os.unlink(os.path.join(into, path))
for path in sorted(after):
target = os.path.join(into, path)
# A link is copied as a link, never followed; and one that would stand in for a folder of the planted tree is left out.
if is_test(path) or (os.path.isdir(target) and not os.path.islink(target)):
if of_tests(path) or (os.path.isdir(target) and not os.path.islink(target)):
continue
os.makedirs(os.path.dirname(target), exist_ok=True)
with contextlib.suppress(FileNotFoundError):
@@ -160,6 +179,10 @@ def checked_tree(planted: str, copy: str, into: str) -> None:
shutil.copy2(os.path.join(copy, path), target, follow_symlinks=False)
def of_tests(path: str) -> bool:
return is_test(path) or "testdata" in pathlib.PurePath(path).parts
def entries(top: str) -> list[str]:
"""Each file and link under top, by its path from top, without git's own under `.git`."""
found = []