Answer stability round 1: 0 🔴, 8 🟡 (0 misread); check a reference patch as a build is checked, test the rule at the head, split the bench's setup by kind

This commit is contained in:
2026-11-23 17:59:26 +01:00
parent 20105231fc
commit 5814a3e895
6 changed files with 197 additions and 124 deletions
+36 -23
View File
@@ -6,12 +6,13 @@ import pathlib
import shutil
import typing
from task_bench.tasks import Bench, committed, on_disk, Planned, Task, tests_in_copy, with_acceptance
from task_bench.tasks import Bench, check_made, committed, on_disk, Planned, Task
from project_config.settings import BENCH_TASKS, CONFIG
from failure import Failure
from project_config.main import located
from mutate_changes.tool_process import Ran
from task_bench.runs import ran_tests, TimedOut
from task_bench.figures import Side, SIDES
from task_bench.runs import TimedOut
SPEC = "spec.md"
PATCH = "reference.patch"
@@ -32,20 +33,20 @@ class NotApplied(Failure):
"""The reference patch doesn't apply to the tree."""
class Kept(typing.NamedTuple):
"""A project's features and the folder that keeps them."""
class Features(typing.NamedTuple):
"""A project's features, found in the folder that keeps them."""
folder: pathlib.Path
features: list[Feature]
found: list[Feature]
def kept_features(home: pathlib.Path) -> Kept | Failure:
def read_features(home: pathlib.Path) -> Features | Failure:
"""The features of the current directory's project, read from the folder its config names."""
folder = features_folder(home)
if isinstance(folder, Failure):
return folder
found = features(folder)
return found if isinstance(found, Failure) else Kept(folder, found)
return found if isinstance(found, Failure) else Features(folder, found)
def features_folder(home: pathlib.Path) -> pathlib.Path | Failure:
@@ -57,7 +58,7 @@ def features_folder(home: pathlib.Path) -> pathlib.Path | Failure:
def features(folder: pathlib.Path) -> list[Feature] | Failure:
"""The features folder holds, one in each folder there, in the order of their names. A Failure where it holds none, or one
"""The features that folder holds, one in each folder there, in the order of their names. A Failure where it holds none, or one
lacks a part."""
if not folder.is_dir():
return Failure(f"could not read the features in {folder}: it is no folder")
@@ -71,7 +72,7 @@ def features(folder: pathlib.Path) -> list[Feature] | Failure:
def feature_in(folder: pathlib.Path) -> Feature | Failure:
"""The feature folder holds. Raises OSError or UnicodeDecodeError where a part cannot be read."""
"""The feature that folder holds. Raises OSError or UnicodeDecodeError where a part cannot be read."""
spec, patch, acceptance = folder / SPEC, folder / PATCH, folder / ACCEPTANCE
for part in (spec, patch):
if not part.is_file():
@@ -103,11 +104,11 @@ def feature_tasks(bench: Bench, found: list[Feature], folder: pathlib.Path) -> P
bench.say(f"task-bench: passed over the feature {feature.name}: {why}.")
if not tasks:
return Failure(f"None of the {len(found)} features in {folder} counts. {' '.join(f'{name}: {why}.' for name, why in passed_over)}")
return Planned(tasks, [f"Passed over the feature {name}: {why}." for name, why in passed_over])
return Planned(tasks, [f"Passed over the feature {name}: {why}." for name, why in passed_over], {})
def committed_trees(bench: Bench) -> dict[Side, str] | Failure:
"""A copy of each side's tree, committed once. Every feature starts from it, since a feature adds nothing to the tree Haiku
"""A copy of each side's tree, committed once. Every feature starts from it, since a feature doesn't add anything to the tree Haiku
works in."""
trees: dict[Side, str] = {}
for side in SIDES:
@@ -124,24 +125,36 @@ def committed_trees(bench: Bench) -> dict[Side, str] | Failure:
def why_passed_over(bench: Bench, trees: dict[Side, str], feature: Feature) -> str | Failure | None:
"""Why feature doesn't count at the first side where it doesn't, in the committed trees; None where it counts at both. A
Failure where the tests could not run."""
def put(copy: str) -> Failure | None:
return on_disk(f"put {feature.name}'s acceptance tests into {copy}", lambda: with_acceptance(copy, feature.acceptance))
def built(copy: str) -> Failure | None:
# git has run in this bench already, so a failure here is the patch's.
applied = bench.git("apply", feature.patch, cwd=copy)
return NotApplied(applied.reason) if isinstance(applied, Failure) else put(copy)
for side, (prepare, is_built) in itertools.product(SIDES, ((put, False), (built, True))):
ran = tests_in_copy(bench.containers, trees[side], bench.folder, prepare)
for side, is_built in itertools.product(SIDES, (False, True)):
ran = checked_run(bench, trees[side], feature, is_built)
if isinstance(ran, NotApplied):
return f"its reference patch doesn't apply at the {side}"
if isinstance(ran, TimedOut):
return f"its acceptance tests don't end at the {side}"
return f"the tests run out of time at the {side}"
if isinstance(ran, Failure):
return ran
if not is_built and ran.code == 0:
return f"its acceptance tests pass at the {side} before it is built"
if is_built and ran.code:
return f"its acceptance tests fail with the reference patch at the {side}"
return f"the tests fail with its reference patch at the {side}"
return None
def checked_run(bench: Bench, tree: str, feature: Feature, is_built: bool) -> Ran | Failure:
"""The test command's run over the tree that checks a copy of tree, with the reference patch applied to the copy where
is_built. It is checked as a run of Haiku's is, so a patch that leans on a test or `testdata` file of its own fails, as a
build would. Both trees are removed afterwards."""
copy, check = bench.folder / "copy", bench.folder / "check"
try:
copied = on_disk(f"copy {tree} to check {feature.name} in it", lambda: shutil.copytree(tree, copy, symlinks=True))
if isinstance(copied, Failure):
return copied
# git has run in this bench already, so a failure here is the patch's.
applied = bench.git("apply", feature.patch, cwd=str(copy)) if is_built else None
if isinstance(applied, Failure):
return NotApplied(applied.reason)
made = on_disk(f"make the tree that checks {feature.name}", lambda: check_made(tree, str(copy), str(check), feature.acceptance))
return made or ran_tests(bench.containers, str(check))
finally:
shutil.rmtree(copy, ignore_errors=True)
shutil.rmtree(check, ignore_errors=True)