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:
+62
-69
@@ -42,8 +42,11 @@ project's config names as `bench-tasks`, in the order of their names. Each holds
|
||||
- `acceptance`, a folder of tests Haiku never sees, each at the path it takes from the tree's top. The test command must run them.
|
||||
A feature counts where, at the base and at the head, the test command fails with the acceptance tests in the tree, and passes
|
||||
once the reference patch is applied too. The bench passes over any other feature, and the report says which and why. Haiku
|
||||
works in a copy of the side's tree without the `bench-tasks` folder, and a build passes where the test command exits 0 over the
|
||||
tree it left, with the acceptance tests put over it. The table then has a row per feature and side, and `-` for the reads. Gremlins
|
||||
works in a copy of the side's tree without the `bench-tasks` folder. A build passes where the test command exits 0 over the
|
||||
side's tree with each file that is no test as Haiku left it, and the acceptance tests put over that. The reference patch is
|
||||
checked the same way, so a test or a `testdata` file it adds doesn't count either. Keep the folder where the project's own test
|
||||
command doesn't find the acceptance tests, which fail by design: outside the checkout, or in a folder the test runner skips, as Go
|
||||
skips `testdata`. The table then has a row per feature and side, and `-` for the reads. Gremlins
|
||||
doesn't run, so --seed, --bugs and --prefix don't go with it.
|
||||
|
||||
It prints the base and the head, then a table: a row per bug and side with how many fixes passed and the medians, over the runs
|
||||
@@ -67,8 +70,8 @@ passed, so the pass rate's noise is unmeasured.
|
||||
|
||||
With --record-figures, a bench that finishes appends its figures to the project's comprehension history: an entry with the
|
||||
table's header and its three All rows. The entry's heading gives the current UTC time, then `task-bench of <branch>: head
|
||||
<commit> against base <commit>`, where <branch> is the branch checked out, whatever --head names. A bench of features is
|
||||
`task-bench features of <branch>: ...` there. No tool reads the entry as a
|
||||
<commit> against base <commit>`, where <branch> is the branch checked out, whatever --head names. For a bench of
|
||||
features the heading reads `task-bench features of <branch>: ...` instead. No tool reads the entry as a
|
||||
ruling or a scoring run. The bench's last line says where the entry went. A bench that fails or stops doesn't record anything.
|
||||
|
||||
`task-bench gather`, run in the same checkout, turns the digest into plan items. It starts a claude on the project's rung, the
|
||||
@@ -82,7 +85,7 @@ not, unless a bench or a gather is using it. So gather a bench before the next o
|
||||
Exit 1, saying why, on an unknown or repeated argument, a missing --image or --test, a --seed, --bugs or --runs that is no whole
|
||||
number from 1, a --tasks that is neither bugs nor features, or no token; and where git, docker or Gremlins fails, the seats' places
|
||||
don't name any Go file, the tests fail at a side without a bug, or no mutant becomes a bug. With --tasks features it exits 1 on a
|
||||
--seed, --bugs or --prefix; where the config sets no `bench-tasks`, or the folder holds no feature or one that lacks a part,
|
||||
--seed, --bugs or --prefix; where no config names the checkout or its config sets no `bench-tasks`, or the folder holds no feature or one that lacks a part,
|
||||
each before docker runs; and where the tests fail at a side without the acceptance tests, or no feature counts. Where the API refuses a run, the bench stops there and exits 1 too, after the table of
|
||||
the runs that finished.
|
||||
With --record-figures it also exits 1, saying why: before it plants a bug, where no config names the checkout or the history
|
||||
@@ -104,11 +107,11 @@ import time
|
||||
import typing
|
||||
import uuid
|
||||
|
||||
from task_bench.tasks import Asked, Bench, BUG, committed, FEATURE, Kind, KINDS, on_disk, Planned, Task, tests_in_copy, with_acceptance
|
||||
from task_bench.tasks import Asked, Bench, BUG, check_made, committed, FEATURE, Kind, KINDS, on_disk, Planned, Task, tests_in_copy
|
||||
from task_bench.plant import bug_at_sides, drawn, killed_mutants, Mutant, place_files, task_text
|
||||
from task_bench.runs import checked_tree, closed, Containers, docker_cli, fix_attempted, MEMORY_MIB, opened, ran_tests, TimedOut, TOKEN, WORK
|
||||
from claude_code.reply import Claude
|
||||
from task_bench.bench_folder import clear_left, held
|
||||
from task_bench.runs import closed, Containers, docker_cli, fix_attempted, MEMORY_MIB, opened, ran_tests, TimedOut, TOKEN, WORK
|
||||
from task_bench.digest import counted, digest, Run, TaskRuns
|
||||
from machine_load.slots import CPUS_PER_SLOT
|
||||
from git_cli.git_repo import default_ref, Git, top
|
||||
@@ -116,7 +119,7 @@ from task_bench.gather import DIGEST, gather, run_claude
|
||||
from claude_code.entries import entry_from, json_objects
|
||||
from mutate_changes.tool_process import failed, Ran, run_tool
|
||||
from failure import Failure
|
||||
from task_bench.feature_tasks import feature_tasks, kept_features
|
||||
from task_bench.feature_tasks import feature_tasks, Features, read_features
|
||||
from task_bench.figures import figures, Result, Side, SIDES, table
|
||||
from git_cli import git_repo
|
||||
from review_rules.review_folder import made_review_folder, REPORTS
|
||||
@@ -133,7 +136,7 @@ COUNTS = {"--bugs": "5", "--runs": "5", "--seed": "1"}
|
||||
TASKS = "--tasks"
|
||||
# Opens the report's last line, which names the bench's folder.
|
||||
KEPT = "The digest, and each run's result and stream, until `task-bench gather` files plan items from them or the next bench starts: "
|
||||
# The options that choose the bugs to plant.
|
||||
# The options only a bench of bugs takes: two choose the bugs to plant, and --prefix runs Gremlins.
|
||||
OF_BUGS = ("--seed", "--bugs", "--prefix")
|
||||
|
||||
|
||||
@@ -157,9 +160,7 @@ def main(argv: list[str], env: typing.Mapping[str, str], read: typing.Callable[[
|
||||
if isinstance(given, Failure):
|
||||
print(f"{given.reason}; {USAGE}", file=sys.stderr)
|
||||
return 1
|
||||
# Only bugs are planted at the seats' places.
|
||||
places = read(home) if KINDS[given[TASKS]] is BUG else ""
|
||||
report = places if isinstance(places, Failure) else bench(given, env, places, home)
|
||||
report = bench(given, env, read, home)
|
||||
if isinstance(report, Failure):
|
||||
print(report.reason, file=sys.stderr)
|
||||
return 1
|
||||
@@ -189,12 +190,12 @@ def options(argv: list[str], env: typing.Mapping[str, str]) -> dict[str, str] |
|
||||
return Failure(f"{name} is missing")
|
||||
if given.setdefault(TASKS, "bugs") not in KINDS:
|
||||
return Failure(f"{TASKS} takes {' or '.join(KINDS)}, not {given[TASKS]}")
|
||||
features = KINDS[given[TASKS]] is FEATURE
|
||||
of_features = KINDS[given[TASKS]] is FEATURE
|
||||
for name in OF_BUGS:
|
||||
if features and name in given:
|
||||
return Failure(f"{name} chooses the bugs to plant, so it doesn't go with {TASKS} features")
|
||||
if of_features and name in given:
|
||||
return Failure(f"{name} is for a bench of bugs, so it doesn't go with {TASKS} features")
|
||||
for name, default in COUNTS.items():
|
||||
if features and name in OF_BUGS:
|
||||
if of_features and name in OF_BUGS:
|
||||
continue
|
||||
if not given.setdefault(name, default).isdecimal() or int(given[name]) < 1:
|
||||
return Failure(f"{name} takes a whole number from 1, not {given[name]}")
|
||||
@@ -208,9 +209,14 @@ def progress(line: str) -> None:
|
||||
print(line, file=sys.stderr)
|
||||
|
||||
|
||||
def bench(given: dict[str, str], env: typing.Mapping[str, str], places: str, home: pathlib.Path, say: typing.Callable[[str], None] = progress) -> list[str] | Failure:
|
||||
"""The report of one bench of the checkout the process runs in, with `places` what `larv-review places` prints there; say
|
||||
tells the caller the bench's progress."""
|
||||
def bench(given: dict[str, str], env: typing.Mapping[str, str], read: typing.Callable[[pathlib.Path], str | Failure], home: pathlib.Path) -> list[str] | Failure:
|
||||
"""The report of one bench of the checkout the process runs in, where `read` reads what `larv-review places` prints. It tells
|
||||
its progress on stderr."""
|
||||
# Only bugs are planted at the seats' places. Each kind reads what it makes its tasks from before anything is copied or built,
|
||||
# so a fault there stops the bench at once.
|
||||
tasks_from = read(home) if KINDS[given[TASKS]] is BUG else read_features(home)
|
||||
if isinstance(tasks_from, Failure):
|
||||
return tasks_from
|
||||
git = functools.partial(git_repo.git, env=env)
|
||||
checkout = top(git)
|
||||
if isinstance(checkout, Failure):
|
||||
@@ -218,7 +224,7 @@ def bench(given: dict[str, str], env: typing.Mapping[str, str], places: str, hom
|
||||
sides = commits(given, checkout, git)
|
||||
if isinstance(sides, Failure):
|
||||
return sides
|
||||
say(f"task-bench: base {sides['base'][:12]}, head {sides['head'][:12]}.")
|
||||
progress(f"task-bench: base {sides['base'][:12]}, head {sides['head'][:12]}.")
|
||||
review = made_review_folder(checkout, home)
|
||||
if isinstance(review, Failure):
|
||||
return review
|
||||
@@ -226,18 +232,13 @@ def bench(given: dict[str, str], env: typing.Mapping[str, str], places: str, hom
|
||||
if isinstance(folder, Failure):
|
||||
return folder
|
||||
clear_left(home / REPORTS)
|
||||
run = functools.partial(bench_in, folder, given, env, places, checkout, sides, git, say, home)
|
||||
run = functools.partial(bench_in, folder, given, env, tasks_from, checkout, sides, git)
|
||||
return recorded_bench(run, folder, git, home, time.time) if RECORD in given else run()
|
||||
|
||||
|
||||
def bench_in(folder: pathlib.Path, given: dict[str, str], env: typing.Mapping[str, str], places: str, checkout: str, sides: dict[Side, str], git: Git, say: typing.Callable[[str], None], home: pathlib.Path) -> list[str] | Failure:
|
||||
"""The report of a bench of the commits sides names, which empties folder and keeps its runs there. home holds the config
|
||||
that names the features' folder."""
|
||||
kind = KINDS[given.get(TASKS, "bugs")]
|
||||
# Read before anything is copied or built, so a folder at fault stops the bench at once.
|
||||
kept = kept_features(home) if kind is FEATURE else None
|
||||
if isinstance(kept, Failure):
|
||||
return kept
|
||||
def bench_in(folder: pathlib.Path, given: dict[str, str], env: typing.Mapping[str, str], tasks_from: str | Features, checkout: str, sides: dict[Side, str], git: Git) -> list[str] | Failure:
|
||||
"""The report of a bench of the commits sides names, which empties folder and keeps its runs there. The bench plants bugs at
|
||||
the places tasks_from names, where it is what `larv-review places` prints, and has Haiku build the features it holds otherwise."""
|
||||
containers = Containers(docker_cli(env), f"task-bench-{uuid.uuid4().hex[:12]}", given["--test"], int(env.get(SHARE_VARIABLE) or MEMORY_MIB), f"{os.getuid()}:{os.getgid()}")
|
||||
shutil.rmtree(folder, ignore_errors=True)
|
||||
trees: dict[Side, str] = {}
|
||||
@@ -246,34 +247,39 @@ def bench_in(folder: pathlib.Path, given: dict[str, str], env: typing.Mapping[st
|
||||
if isinstance(tree, Failure):
|
||||
return tree
|
||||
trees[side] = tree
|
||||
planned: typing.Callable[[Bench], Planned | Failure]
|
||||
if kept:
|
||||
# Haiku's copy leaves the features' folder out, with its acceptance tests and reference patches.
|
||||
if kept.folder.is_relative_to(checkout):
|
||||
for tree in trees.values():
|
||||
shutil.rmtree(pathlib.Path(tree, kept.folder.relative_to(checkout)), ignore_errors=True)
|
||||
asked = Asked(kind, int(given["--runs"]))
|
||||
planned = functools.partial(feature_tasks, found=kept.features, folder=kept.folder)
|
||||
planned: typing.Callable[[Bench], Planned | Failure] | Failure
|
||||
if isinstance(tasks_from, Features):
|
||||
asked, planned = Asked(FEATURE, int(given["--runs"])), features_planner(tasks_from, checkout, trees)
|
||||
else:
|
||||
mutants = killed_at_places(given, env, places, trees["base"])
|
||||
if isinstance(mutants, Failure):
|
||||
return mutants
|
||||
asked = Asked(kind, int(given["--runs"]), int(given["--seed"]), int(given["--bugs"]))
|
||||
planned = functools.partial(planted_tasks, mutants=mutants)
|
||||
asked, planned = Asked(BUG, int(given["--runs"])), bugs_planner(given, env, tasks_from, trees["base"])
|
||||
if isinstance(planned, Failure):
|
||||
return planned
|
||||
try:
|
||||
found = opened(containers, given["--image"]) or benched(Bench(checkout, sides, trees, asked, containers, folder, git, say), planned)
|
||||
found = opened(containers, given["--image"]) or benched(Bench(checkout, sides, trees, asked, containers, folder, git, progress), planned)
|
||||
finally:
|
||||
closed(containers)
|
||||
return found if isinstance(found, Failure) else [*found, f"{KEPT}{folder}"]
|
||||
|
||||
|
||||
def killed_at_places(given: dict[str, str], env: typing.Mapping[str, str], places: str, base: str) -> list[Mutant] | Failure:
|
||||
"""The mutants the tests kill in the Go files of the tree at base that hold a place in places."""
|
||||
def features_planner(features: Features, checkout: str, trees: dict[Side, str]) -> typing.Callable[[Bench], Planned | Failure]:
|
||||
"""What plans a bench of features in trees, each side's. It takes the features' folder, with its acceptance tests and
|
||||
reference patches, out of trees first, so Haiku's copy leaves it out."""
|
||||
if features.folder.is_relative_to(checkout):
|
||||
for tree in trees.values():
|
||||
# A side older than the folder, or a folder not yet committed, leaves none to take out.
|
||||
shutil.rmtree(pathlib.Path(tree, features.folder.relative_to(checkout)), ignore_errors=True)
|
||||
return functools.partial(feature_tasks, found=features.found, folder=features.folder)
|
||||
|
||||
|
||||
def bugs_planner(given: dict[str, str], env: typing.Mapping[str, str], places: str, base: str) -> typing.Callable[[Bench], Planned | Failure] | Failure:
|
||||
"""What plans a bench of bugs: of the mutants the tests kill in the Go files of the tree at base that hold a place in places,
|
||||
those --seed draws first become bugs, until --bugs of them have."""
|
||||
files = [path for path in place_files(places) if pathlib.Path(base, path).is_file()]
|
||||
if not files:
|
||||
return Failure("The places the seats found hard don't name any Go file that the base holds, so there is nowhere to plant a bug.")
|
||||
run = functools.partial(run_tool, prefix=given.get("--prefix"), env=env, killpg=os.killpg)
|
||||
return killed_mutants(base, files, run, CPUS_PER_SLOT)
|
||||
mutants = killed_mutants(base, files, run, CPUS_PER_SLOT)
|
||||
return mutants if isinstance(mutants, Failure) else functools.partial(planted_tasks, mutants=mutants, seed=int(given["--seed"]), bugs=int(given["--bugs"]))
|
||||
|
||||
|
||||
def commits(given: dict[str, str], checkout: str, git: Git) -> dict[Side, str] | Failure:
|
||||
@@ -320,7 +326,7 @@ def benched(bench: Bench, planned: typing.Callable[[Bench], Planned | Failure])
|
||||
if fixes.stopped and not fixes.results:
|
||||
return fixes.stopped
|
||||
names = {task.number: task.name for task in tasks}
|
||||
if failure := kept(bench, tasks, names, fixes.results):
|
||||
if failure := kept(bench, plan, names, fixes.results):
|
||||
return failure
|
||||
if fixes.stopped:
|
||||
return stopped_report(fixes.stopped, fixes.results, total, names, bench.folder, bench.asked.kind)
|
||||
@@ -336,12 +342,9 @@ def baseline_failure(bench: Bench) -> Failure | None:
|
||||
return None
|
||||
|
||||
|
||||
def planted_tasks(bench: Bench, mutants: list[Mutant]) -> Planned | Failure:
|
||||
"""The mutants that become bugs, in the order the seed draws them, until the bench has as many as asked for; with a line that
|
||||
says so where it has fewer."""
|
||||
seed, bugs = bench.asked.seed, bench.asked.bugs
|
||||
# A bench of bugs is asked with both.
|
||||
assert seed is not None and bugs is not None
|
||||
def planted_tasks(bench: Bench, mutants: list[Mutant], seed: int, bugs: int) -> Planned | Failure:
|
||||
"""The mutants that become bugs, in the order seed draws them, until the bench has as many as bugs; with a line that says so
|
||||
where it has fewer."""
|
||||
tasks: list[Task] = []
|
||||
for mutant in drawn(mutants, seed):
|
||||
if len(tasks) == bugs:
|
||||
@@ -352,7 +355,7 @@ def planted_tasks(bench: Bench, mutants: list[Mutant]) -> Planned | Failure:
|
||||
tasks += [task] if task else []
|
||||
if not tasks:
|
||||
return Failure(f"None of the {len(mutants)} mutants the tests kill becomes a bug: each is on a line the head changed, or the test it fails doesn't print a message.")
|
||||
return Planned(tasks, [] if len(tasks) == bugs else [f"Planted {len(tasks)} of the {bugs} bugs asked for: no other mutant the tests kill becomes one."])
|
||||
return Planned(tasks, [] if len(tasks) == bugs else [f"Planted {len(tasks)} of the {bugs} bugs asked for: no other mutant the tests kill becomes one."], {"seed": seed})
|
||||
|
||||
|
||||
def ran_fixes(bench: Bench, tasks: list[Task], total: int) -> Fixes:
|
||||
@@ -367,13 +370,12 @@ def ran_fixes(bench: Bench, tasks: list[Task], total: int) -> Fixes:
|
||||
return Fixes(results, None)
|
||||
|
||||
|
||||
def kept(bench: Bench, tasks: list[Task], names: dict[int, str], results: list[Result]) -> Failure | None:
|
||||
"""Writes results.json and the digest into the bench's folder. names holds each task's name by its number."""
|
||||
def kept(bench: Bench, plan: Planned, names: dict[int, str], results: list[Result]) -> Failure | None:
|
||||
"""Writes results.json and the digest of the plan's tasks into the bench's folder. names holds each task's name by its number."""
|
||||
in_a_tree = lambda path: any(pathlib.Path(tree, path).is_file() for tree in bench.trees.values())
|
||||
noun = bench.asked.kind.noun
|
||||
seed = {} if bench.asked.seed is None else {"seed": bench.asked.seed}
|
||||
recorded_runs = json.dumps({"sides": bench.sides, **seed, f"{noun}s": names, "runs": [recorded(result, noun) for result in results]}, indent="\t") + "\n"
|
||||
digest_text = digest(bench.sides, table(results, names, noun), [digested(task, results, bench.folder, noun) for task in tasks], in_a_tree, noun)
|
||||
recorded_runs = json.dumps({"sides": bench.sides, **plan.drawn_by, f"{noun}s": names, "runs": [recorded(result, noun) for result in results]}, indent="\t") + "\n"
|
||||
digest_text = digest(bench.sides, table(results, names, noun), [digested(task, results, bench.folder, noun) for task in plan.tasks], in_a_tree, noun)
|
||||
try:
|
||||
(bench.folder / "results.json").write_text(recorded_runs, encoding="utf-8")
|
||||
(bench.folder / DIGEST).write_text(digest_text, encoding="utf-8", errors="replace")
|
||||
@@ -466,7 +468,7 @@ def fixed(task: Task, side: Side, number: int, containers: Containers, folder: p
|
||||
found = figures(events, task.file and os.path.join(WORK, task.file))
|
||||
if isinstance(found, Failure):
|
||||
return found
|
||||
checked = on_disk(f"make the tree that checks {kind.noun} {task.number}'s fix at the {side}", lambda: check_made(task, side, str(copy), str(check)))
|
||||
checked = on_disk(f"make the tree that checks {kind.noun} {task.number}'s fix at the {side}", lambda: check_made(task.trees[side], str(copy), str(check), task.acceptance))
|
||||
if isinstance(checked, Failure):
|
||||
return checked
|
||||
ran = ran_tests(containers, str(check))
|
||||
@@ -478,15 +480,6 @@ def fixed(task: Task, side: Side, number: int, containers: Containers, folder: p
|
||||
shutil.rmtree(check, ignore_errors=True)
|
||||
|
||||
|
||||
def check_made(task: Task, side: Side, copy: str, check: str) -> None:
|
||||
"""Makes at check the tree that checks what Haiku left in copy: `checked_tree`'s, then a feature's acceptance tests over it.
|
||||
|
||||
Raises OSError where a file cannot be copied."""
|
||||
checked_tree(task.trees[side], copy, check)
|
||||
if task.acceptance:
|
||||
with_acceptance(check, task.acceptance)
|
||||
|
||||
|
||||
def stream_of(result: Result, folder: pathlib.Path, noun: str) -> pathlib.Path:
|
||||
"""The file that holds the stream of the run result names, of a task the bench calls by noun. Its name without the suffix is
|
||||
the run's id in the digest."""
|
||||
|
||||
Reference in New Issue
Block a user