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:
@@ -47,13 +47,14 @@ def digest(sides: dict[Side, str], table: list[str], tasks: list[TaskRuns], is_f
|
|||||||
which the digest calls by noun. is_file says whether a path in the project names a file."""
|
which the digest calls by noun. is_file says whether a path in the project names a file."""
|
||||||
line = " A bug's name gives its line at the base." if noun == "bug" else ""
|
line = " A bug's name gives its line at the base." if noun == "bug" else ""
|
||||||
code = f"Base {sides['base']}, head {sides['head']}.{line} Each side's code without the {noun}s is in `trees/base` and `trees/head` in the bench's folder."
|
code = f"Base {sides['base']}, head {sides['head']}.{line} Each side's code without the {noun}s is in `trees/base` and `trees/head` in the bench's folder."
|
||||||
return "\n".join(["# task-bench digest", "", code, "", *table, *(line for task in tasks for line in ["", *told(task, is_file, noun)])]) + "\n"
|
return "\n".join(["# task-bench digest", "", code, "", *table, *(line for task in tasks for line in ["", *told(task, is_file)])]) + "\n"
|
||||||
|
|
||||||
|
|
||||||
def told(task: TaskRuns, is_file: typing.Callable[[str], bool], noun: str) -> list[str]:
|
def told(task: TaskRuns, is_file: typing.Callable[[str], bool]) -> list[str]:
|
||||||
|
"""The digest's section on task, a bug where it names the bug's file and a feature otherwise."""
|
||||||
passing, failing = [run for run in task.runs if run.passed], [run for run in task.runs if not run.passed]
|
passing, failing = [run for run in task.runs if run.passed], [run for run in task.runs if not run.passed]
|
||||||
passed = f"{len(passing)} of the {len(task.runs)} runs passed." if failing else f"The {counted(len(task.runs), 'run')} passed."
|
passed = f"{len(passing)} of the {len(task.runs)} runs passed." if failing else f"The {counted(len(task.runs), 'run')} passed."
|
||||||
# A feature is in no one file, so no file it read is beside the point.
|
# Only a bug has a file of its own. A feature has none, so no file a run read counts as a decoy.
|
||||||
misled = decoys([run.entries for run in failing], task.file, is_file) if task.file else []
|
misled = decoys([run.entries for run in failing], task.file, is_file) if task.file else []
|
||||||
if not task.file:
|
if not task.file:
|
||||||
found = ""
|
found = ""
|
||||||
@@ -75,7 +76,7 @@ def told(task: TaskRuns, is_file: typing.Callable[[str], bool], noun: str) -> li
|
|||||||
median = finished[(len(finished) - 1) // 2]
|
median = finished[(len(finished) - 1) // 2]
|
||||||
shown.append((median, f"the passing run with the median tokens, {median.tokens} tokens"))
|
shown.append((median, f"the passing run with the median tokens, {median.tokens} tokens"))
|
||||||
return [
|
return [
|
||||||
f"## {noun.capitalize()} {task.named}",
|
f"## {'Bug' if task.file else 'Feature'} {task.named}",
|
||||||
"",
|
"",
|
||||||
"The failing test printed, at the base:" if task.file else "The spec Haiku was told:",
|
"The failing test printed, at the base:" if task.file else "The spec Haiku was told:",
|
||||||
"",
|
"",
|
||||||
|
|||||||
@@ -6,12 +6,13 @@ import pathlib
|
|||||||
import shutil
|
import shutil
|
||||||
import typing
|
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 project_config.settings import BENCH_TASKS, CONFIG
|
||||||
from failure import Failure
|
from failure import Failure
|
||||||
from project_config.main import located
|
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.figures import Side, SIDES
|
||||||
from task_bench.runs import TimedOut
|
|
||||||
|
|
||||||
SPEC = "spec.md"
|
SPEC = "spec.md"
|
||||||
PATCH = "reference.patch"
|
PATCH = "reference.patch"
|
||||||
@@ -32,20 +33,20 @@ class NotApplied(Failure):
|
|||||||
"""The reference patch doesn't apply to the tree."""
|
"""The reference patch doesn't apply to the tree."""
|
||||||
|
|
||||||
|
|
||||||
class Kept(typing.NamedTuple):
|
class Features(typing.NamedTuple):
|
||||||
"""A project's features and the folder that keeps them."""
|
"""A project's features, found in the folder that keeps them."""
|
||||||
|
|
||||||
folder: pathlib.Path
|
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."""
|
"""The features of the current directory's project, read from the folder its config names."""
|
||||||
folder = features_folder(home)
|
folder = features_folder(home)
|
||||||
if isinstance(folder, Failure):
|
if isinstance(folder, Failure):
|
||||||
return folder
|
return folder
|
||||||
found = features(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:
|
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:
|
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."""
|
lacks a part."""
|
||||||
if not folder.is_dir():
|
if not folder.is_dir():
|
||||||
return Failure(f"could not read the features in {folder}: it is no folder")
|
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:
|
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
|
spec, patch, acceptance = folder / SPEC, folder / PATCH, folder / ACCEPTANCE
|
||||||
for part in (spec, patch):
|
for part in (spec, patch):
|
||||||
if not part.is_file():
|
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}.")
|
bench.say(f"task-bench: passed over the feature {feature.name}: {why}.")
|
||||||
if not tasks:
|
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 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:
|
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."""
|
works in."""
|
||||||
trees: dict[Side, str] = {}
|
trees: dict[Side, str] = {}
|
||||||
for side in SIDES:
|
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:
|
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
|
"""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."""
|
Failure where the tests could not run."""
|
||||||
def put(copy: str) -> Failure | None:
|
for side, is_built in itertools.product(SIDES, (False, True)):
|
||||||
return on_disk(f"put {feature.name}'s acceptance tests into {copy}", lambda: with_acceptance(copy, feature.acceptance))
|
ran = checked_run(bench, trees[side], feature, is_built)
|
||||||
|
|
||||||
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)
|
|
||||||
if isinstance(ran, NotApplied):
|
if isinstance(ran, NotApplied):
|
||||||
return f"its reference patch doesn't apply at the {side}"
|
return f"its reference patch doesn't apply at the {side}"
|
||||||
if isinstance(ran, TimedOut):
|
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):
|
if isinstance(ran, Failure):
|
||||||
return ran
|
return ran
|
||||||
if not is_built and ran.code == 0:
|
if not is_built and ran.code == 0:
|
||||||
return f"its acceptance tests pass at the {side} before it is built"
|
return f"its acceptance tests pass at the {side} before it is built"
|
||||||
if is_built and ran.code:
|
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
|
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)
|
||||||
|
|||||||
+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.
|
- `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
|
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
|
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
|
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
|
||||||
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
|
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.
|
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
|
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
|
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
|
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
|
<commit> against base <commit>`, where <branch> is the branch checked out, whatever --head names. For a bench of
|
||||||
`task-bench features of <branch>: ...` there. No tool reads the entry as a
|
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.
|
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
|
`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
|
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
|
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
|
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
|
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.
|
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
|
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 typing
|
||||||
import uuid
|
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.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 claude_code.reply import Claude
|
||||||
from task_bench.bench_folder import clear_left, held
|
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 task_bench.digest import counted, digest, Run, TaskRuns
|
||||||
from machine_load.slots import CPUS_PER_SLOT
|
from machine_load.slots import CPUS_PER_SLOT
|
||||||
from git_cli.git_repo import default_ref, Git, top
|
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 claude_code.entries import entry_from, json_objects
|
||||||
from mutate_changes.tool_process import failed, Ran, run_tool
|
from mutate_changes.tool_process import failed, Ran, run_tool
|
||||||
from failure import Failure
|
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 task_bench.figures import figures, Result, Side, SIDES, table
|
||||||
from git_cli import git_repo
|
from git_cli import git_repo
|
||||||
from review_rules.review_folder import made_review_folder, REPORTS
|
from review_rules.review_folder import made_review_folder, REPORTS
|
||||||
@@ -133,7 +136,7 @@ COUNTS = {"--bugs": "5", "--runs": "5", "--seed": "1"}
|
|||||||
TASKS = "--tasks"
|
TASKS = "--tasks"
|
||||||
# Opens the report's last line, which names the bench's folder.
|
# 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: "
|
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")
|
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):
|
if isinstance(given, Failure):
|
||||||
print(f"{given.reason}; {USAGE}", file=sys.stderr)
|
print(f"{given.reason}; {USAGE}", file=sys.stderr)
|
||||||
return 1
|
return 1
|
||||||
# Only bugs are planted at the seats' places.
|
report = bench(given, env, read, home)
|
||||||
places = read(home) if KINDS[given[TASKS]] is BUG else ""
|
|
||||||
report = places if isinstance(places, Failure) else bench(given, env, places, home)
|
|
||||||
if isinstance(report, Failure):
|
if isinstance(report, Failure):
|
||||||
print(report.reason, file=sys.stderr)
|
print(report.reason, file=sys.stderr)
|
||||||
return 1
|
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")
|
return Failure(f"{name} is missing")
|
||||||
if given.setdefault(TASKS, "bugs") not in KINDS:
|
if given.setdefault(TASKS, "bugs") not in KINDS:
|
||||||
return Failure(f"{TASKS} takes {' or '.join(KINDS)}, not {given[TASKS]}")
|
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:
|
for name in OF_BUGS:
|
||||||
if features and name in given:
|
if of_features and name in given:
|
||||||
return Failure(f"{name} chooses the bugs to plant, so it doesn't go with {TASKS} features")
|
return Failure(f"{name} is for a bench of bugs, so it doesn't go with {TASKS} features")
|
||||||
for name, default in COUNTS.items():
|
for name, default in COUNTS.items():
|
||||||
if features and name in OF_BUGS:
|
if of_features and name in OF_BUGS:
|
||||||
continue
|
continue
|
||||||
if not given.setdefault(name, default).isdecimal() or int(given[name]) < 1:
|
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]}")
|
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)
|
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:
|
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, with `places` what `larv-review places` prints there; say
|
"""The report of one bench of the checkout the process runs in, where `read` reads what `larv-review places` prints. It tells
|
||||||
tells the caller the bench's progress."""
|
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)
|
git = functools.partial(git_repo.git, env=env)
|
||||||
checkout = top(git)
|
checkout = top(git)
|
||||||
if isinstance(checkout, Failure):
|
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)
|
sides = commits(given, checkout, git)
|
||||||
if isinstance(sides, Failure):
|
if isinstance(sides, Failure):
|
||||||
return sides
|
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)
|
review = made_review_folder(checkout, home)
|
||||||
if isinstance(review, Failure):
|
if isinstance(review, Failure):
|
||||||
return review
|
return review
|
||||||
@@ -226,18 +232,13 @@ def bench(given: dict[str, str], env: typing.Mapping[str, str], places: str, hom
|
|||||||
if isinstance(folder, Failure):
|
if isinstance(folder, Failure):
|
||||||
return folder
|
return folder
|
||||||
clear_left(home / REPORTS)
|
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()
|
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:
|
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. home holds the config
|
"""The report of a bench of the commits sides names, which empties folder and keeps its runs there. The bench plants bugs at
|
||||||
that names the features' folder."""
|
the places tasks_from names, where it is what `larv-review places` prints, and has Haiku build the features it holds otherwise."""
|
||||||
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
|
|
||||||
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()}")
|
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)
|
shutil.rmtree(folder, ignore_errors=True)
|
||||||
trees: dict[Side, str] = {}
|
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):
|
if isinstance(tree, Failure):
|
||||||
return tree
|
return tree
|
||||||
trees[side] = tree
|
trees[side] = tree
|
||||||
planned: typing.Callable[[Bench], Planned | Failure]
|
planned: typing.Callable[[Bench], Planned | Failure] | Failure
|
||||||
if kept:
|
if isinstance(tasks_from, Features):
|
||||||
# Haiku's copy leaves the features' folder out, with its acceptance tests and reference patches.
|
asked, planned = Asked(FEATURE, int(given["--runs"])), features_planner(tasks_from, checkout, trees)
|
||||||
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)
|
|
||||||
else:
|
else:
|
||||||
mutants = killed_at_places(given, env, places, trees["base"])
|
asked, planned = Asked(BUG, int(given["--runs"])), bugs_planner(given, env, tasks_from, trees["base"])
|
||||||
if isinstance(mutants, Failure):
|
if isinstance(planned, Failure):
|
||||||
return mutants
|
return planned
|
||||||
asked = Asked(kind, int(given["--runs"]), int(given["--seed"]), int(given["--bugs"]))
|
|
||||||
planned = functools.partial(planted_tasks, mutants=mutants)
|
|
||||||
try:
|
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:
|
finally:
|
||||||
closed(containers)
|
closed(containers)
|
||||||
return found if isinstance(found, Failure) else [*found, f"{KEPT}{folder}"]
|
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:
|
def features_planner(features: Features, checkout: str, trees: dict[Side, str]) -> typing.Callable[[Bench], Planned | Failure]:
|
||||||
"""The mutants the tests kill in the Go files of the tree at base that hold a place in places."""
|
"""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()]
|
files = [path for path in place_files(places) if pathlib.Path(base, path).is_file()]
|
||||||
if not files:
|
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.")
|
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)
|
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:
|
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:
|
if fixes.stopped and not fixes.results:
|
||||||
return fixes.stopped
|
return fixes.stopped
|
||||||
names = {task.number: task.name for task in tasks}
|
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
|
return failure
|
||||||
if fixes.stopped:
|
if fixes.stopped:
|
||||||
return stopped_report(fixes.stopped, fixes.results, total, names, bench.folder, bench.asked.kind)
|
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
|
return None
|
||||||
|
|
||||||
|
|
||||||
def planted_tasks(bench: Bench, mutants: list[Mutant]) -> Planned | Failure:
|
def planted_tasks(bench: Bench, mutants: list[Mutant], seed: int, bugs: int) -> 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
|
"""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
|
||||||
says so where it has fewer."""
|
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
|
|
||||||
tasks: list[Task] = []
|
tasks: list[Task] = []
|
||||||
for mutant in drawn(mutants, seed):
|
for mutant in drawn(mutants, seed):
|
||||||
if len(tasks) == bugs:
|
if len(tasks) == bugs:
|
||||||
@@ -352,7 +355,7 @@ def planted_tasks(bench: Bench, mutants: list[Mutant]) -> Planned | Failure:
|
|||||||
tasks += [task] if task else []
|
tasks += [task] if task else []
|
||||||
if not tasks:
|
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 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:
|
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)
|
return Fixes(results, None)
|
||||||
|
|
||||||
|
|
||||||
def kept(bench: Bench, tasks: list[Task], names: dict[int, str], results: list[Result]) -> Failure | None:
|
def kept(bench: Bench, plan: Planned, 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."""
|
"""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())
|
in_a_tree = lambda path: any(pathlib.Path(tree, path).is_file() for tree in bench.trees.values())
|
||||||
noun = bench.asked.kind.noun
|
noun = bench.asked.kind.noun
|
||||||
seed = {} if bench.asked.seed is None else {"seed": bench.asked.seed}
|
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"
|
||||||
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 plan.tasks], in_a_tree, noun)
|
||||||
digest_text = digest(bench.sides, table(results, names, noun), [digested(task, results, bench.folder, noun) for task in tasks], in_a_tree, noun)
|
|
||||||
try:
|
try:
|
||||||
(bench.folder / "results.json").write_text(recorded_runs, encoding="utf-8")
|
(bench.folder / "results.json").write_text(recorded_runs, encoding="utf-8")
|
||||||
(bench.folder / DIGEST).write_text(digest_text, encoding="utf-8", errors="replace")
|
(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))
|
found = figures(events, task.file and os.path.join(WORK, task.file))
|
||||||
if isinstance(found, Failure):
|
if isinstance(found, Failure):
|
||||||
return found
|
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):
|
if isinstance(checked, Failure):
|
||||||
return checked
|
return checked
|
||||||
ran = ran_tests(containers, str(check))
|
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)
|
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:
|
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 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."""
|
the run's id in the digest."""
|
||||||
|
|||||||
+21
-13
@@ -1,11 +1,11 @@
|
|||||||
"""What both kinds of task-bench's tasks share, a planted bug and a feature to build: the task itself, the bench it runs in, and the
|
"""What task-bench's two kinds of task share. One kind is a planted bug, the other a feature to build. They share the task itself, the bench it runs in, and the
|
||||||
steps that commit a task's tree and run the tests over a copy of one."""
|
steps that commit a task's tree and run the tests over a copy of one."""
|
||||||
import dataclasses
|
import dataclasses
|
||||||
import pathlib
|
import pathlib
|
||||||
import shutil
|
import shutil
|
||||||
import typing
|
import typing
|
||||||
|
|
||||||
from task_bench.runs import Containers, ran_tests
|
from task_bench.runs import checked_tree, Containers, ran_tests
|
||||||
from failure import Failure
|
from failure import Failure
|
||||||
from git_cli.git_repo import Git
|
from git_cli.git_repo import Git
|
||||||
from mutate_changes.tool_process import Ran
|
from mutate_changes.tool_process import Ran
|
||||||
@@ -16,8 +16,8 @@ COMMIT = ["-c", "user.name=task-bench", "-c", "user.email=task-bench@localhost",
|
|||||||
|
|
||||||
|
|
||||||
class Kind(typing.NamedTuple):
|
class Kind(typing.NamedTuple):
|
||||||
"""A kind of task: what the report calls one, what Haiku is asked, with the task's own text for `{told}`, and what a side's
|
"""A kind of task: what the report calls one, what Haiku is asked, with the task's own text for `{told}`, and how a failure names a side's
|
||||||
tree is without one."""
|
tree before the bench puts a task there, as in `without a planted bug`."""
|
||||||
|
|
||||||
noun: str
|
noun: str
|
||||||
prompt: str
|
prompt: str
|
||||||
@@ -44,12 +44,9 @@ class Task:
|
|||||||
|
|
||||||
|
|
||||||
class Asked(typing.NamedTuple):
|
class Asked(typing.NamedTuple):
|
||||||
"""What the caller asked of a bench: the kind of its tasks and how often to run each. For bugs also the seed that orders the
|
"""What the caller asked of a bench: the kind of its tasks and how often to run each."""
|
||||||
mutants and how many bugs to plant; both are None for features, which the bench takes as their folder holds them."""
|
|
||||||
kind: Kind
|
kind: Kind
|
||||||
runs: int
|
runs: int
|
||||||
seed: int | None = None
|
|
||||||
bugs: int | None = None
|
|
||||||
|
|
||||||
|
|
||||||
@dataclasses.dataclass(frozen=True)
|
@dataclasses.dataclass(frozen=True)
|
||||||
@@ -67,9 +64,11 @@ class Bench:
|
|||||||
|
|
||||||
|
|
||||||
class Planned(typing.NamedTuple):
|
class Planned(typing.NamedTuple):
|
||||||
"""The tasks a bench runs, and a line for its report on each thing it left out."""
|
"""The tasks a bench runs, a line for its report on each thing it left out, and what drew the tasks, as results.json records
|
||||||
|
it: the seed for bugs. Features come as their folder holds them, so for them it is empty."""
|
||||||
tasks: list[Task]
|
tasks: list[Task]
|
||||||
left_out: list[str]
|
left_out: list[str]
|
||||||
|
drawn_by: dict[str, int]
|
||||||
|
|
||||||
|
|
||||||
def on_disk[T](doing: str, act: typing.Callable[[], T]) -> T | Failure:
|
def on_disk[T](doing: str, act: typing.Callable[[], T]) -> T | Failure:
|
||||||
@@ -89,19 +88,28 @@ def committed(git: Git, tree: str) -> Failure | None:
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def tests_in_copy(containers: Containers, tree: str, folder: pathlib.Path, prepare: typing.Callable[[str], Failure | None] = lambda copy: None) -> Ran | Failure:
|
def tests_in_copy(containers: Containers, tree: str, folder: pathlib.Path) -> Ran | Failure:
|
||||||
"""The test command's run in a copy of tree, removed afterwards, so what the tests write stays out of tree. prepare changes the
|
"""The test command's run in a copy of tree, removed afterwards, so what the tests write stays out of tree."""
|
||||||
copy before the tests run; where it fails, they don't run."""
|
|
||||||
copy = folder / "tested"
|
copy = folder / "tested"
|
||||||
copied = on_disk(f"copy {tree} to test it", lambda: shutil.copytree(tree, copy, symlinks=True))
|
copied = on_disk(f"copy {tree} to test it", lambda: shutil.copytree(tree, copy, symlinks=True))
|
||||||
if isinstance(copied, Failure):
|
if isinstance(copied, Failure):
|
||||||
return copied
|
return copied
|
||||||
try:
|
try:
|
||||||
return prepare(str(copy)) or ran_tests(containers, str(copy))
|
return ran_tests(containers, str(copy))
|
||||||
finally:
|
finally:
|
||||||
shutil.rmtree(copy, ignore_errors=True)
|
shutil.rmtree(copy, ignore_errors=True)
|
||||||
|
|
||||||
|
|
||||||
|
def check_made(tree: str, copy: str, check: str, acceptance: str | None) -> None:
|
||||||
|
"""Makes at check the tree that checks what was built in copy, a copy of tree: `checked_tree`'s, then a feature's acceptance
|
||||||
|
tests over it, where acceptance names their folder. A run of Haiku's and a feature's reference patch are checked alike.
|
||||||
|
|
||||||
|
Raises OSError where a file cannot be copied."""
|
||||||
|
checked_tree(tree, copy, check)
|
||||||
|
if acceptance:
|
||||||
|
with_acceptance(check, acceptance)
|
||||||
|
|
||||||
|
|
||||||
def with_acceptance(tree: str, acceptance: str) -> None:
|
def with_acceptance(tree: str, acceptance: str) -> None:
|
||||||
"""Puts a feature's acceptance tests into tree, each file at its path under `acceptance`, over any file the tree holds there.
|
"""Puts a feature's acceptance tests into tree, each file at its path under `acceptance`, over any file the tree holds there.
|
||||||
|
|
||||||
|
|||||||
@@ -14,11 +14,14 @@ import unittest
|
|||||||
|
|
||||||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
||||||
|
|
||||||
from task_bench.test_task_bench import BASE_CODE, DOCKER, HEAD_CODE, TESTS
|
from task_bench.tasks import Asked, Bench, FEATURE
|
||||||
|
from task_bench.test_task_bench import BASE_CODE, DOCKER, HEAD_CODE, InTurn, TESTS
|
||||||
|
from task_bench.runs import Containers, TimedOut
|
||||||
from failure import Failure
|
from failure import Failure
|
||||||
from task_bench.feature_tasks import features
|
from task_bench.feature_tasks import Feature, features, why_passed_over
|
||||||
from test_env import isolated_env
|
from test_env import isolated_env
|
||||||
from task_bench import main
|
from task_bench import main
|
||||||
|
from mutate_changes.tool_process import Ran
|
||||||
|
|
||||||
CONFIG = "".join(f'{name} = "checkout:{name}.md"\n' for name in ("plan", "working-rules", "decisions", "score-anchors", "comprehension-history", "reading-cost", "changelog", "goals-and-audience", "principles", "standards"))
|
CONFIG = "".join(f'{name} = "checkout:{name}.md"\n' for name in ("plan", "working-rules", "decisions", "score-anchors", "comprehension-history", "reading-cost", "changelog", "goals-and-audience", "principles", "standards"))
|
||||||
# Stands in for `go test ./...`: each test of the tree, a shell text in a file named as a Go test.
|
# Stands in for `go test ./...`: each test of the tree, a shell text in a file named as a Go test.
|
||||||
@@ -72,6 +75,11 @@ def feature(folder: pathlib.Path, spec: str = "Add `Halve(a int) int`, which hal
|
|||||||
(folder / "acceptance" / test).write_text(acceptance)
|
(folder / "acceptance" / test).write_text(acceptance)
|
||||||
|
|
||||||
|
|
||||||
|
def added(path: str) -> str:
|
||||||
|
"""The part of a patch that adds the file path, which holds `exit 0`."""
|
||||||
|
return f"diff --git a/{path} b/{path}\nnew file mode 100644\n--- /dev/null\n+++ b/{path}\n@@ -0,0 +1 @@\n+exit 0\n"
|
||||||
|
|
||||||
|
|
||||||
class FeatureBenchTest(unittest.TestCase):
|
class FeatureBenchTest(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
folder = tempfile.TemporaryDirectory()
|
folder = tempfile.TemporaryDirectory()
|
||||||
@@ -92,6 +100,8 @@ class FeatureBenchTest(unittest.TestCase):
|
|||||||
self.git("init", "--quiet", "--initial-branch", "main")
|
self.git("init", "--quiet", "--initial-branch", "main")
|
||||||
for name, text in (("calc.go", BASE_CODE), ("calc_test.go", TESTS), ("README.md", "# Calc\n")):
|
for name, text in (("calc.go", BASE_CODE), ("calc_test.go", TESTS), ("README.md", "# Calc\n")):
|
||||||
(self.repo / name).write_text(text)
|
(self.repo / name).write_text(text)
|
||||||
|
# A link is copied as a link, never followed, and a dangling one doesn't stop the bench.
|
||||||
|
os.symlink("missing", self.repo / "dangling")
|
||||||
feature(self.tasks / "halve")
|
feature(self.tasks / "halve")
|
||||||
self.base = self.commit("Base")
|
self.base = self.commit("Base")
|
||||||
self.git("checkout", "--quiet", "-b", "item-1")
|
self.git("checkout", "--quiet", "-b", "item-1")
|
||||||
@@ -109,7 +119,7 @@ class FeatureBenchTest(unittest.TestCase):
|
|||||||
|
|
||||||
def bench(self, **given: str):
|
def bench(self, **given: str):
|
||||||
with contextlib.redirect_stderr(io.StringIO()) as self.progress:
|
with contextlib.redirect_stderr(io.StringIO()) as self.progress:
|
||||||
return main.bench({**self.given, **given}, self.env, "", self.home)
|
return main.bench({**self.given, **given}, self.env, lambda home: "", self.home)
|
||||||
|
|
||||||
def test_has_haiku_build_each_feature_at_both_sides_and_checks_it_with_the_acceptance_tests_it_never_saw(self):
|
def test_has_haiku_build_each_feature_at_both_sides_and_checks_it_with_the_acceptance_tests_it_never_saw(self):
|
||||||
# Neither counts: one's acceptance tests pass before it is built, and the other's reference patch doesn't apply at the head.
|
# Neither counts: one's acceptance tests pass before it is built, and the other's reference patch doesn't apply at the head.
|
||||||
@@ -135,7 +145,7 @@ class FeatureBenchTest(unittest.TestCase):
|
|||||||
handed = json.loads(pathlib.Path(f"{self.log}.claude").read_text())
|
handed = json.loads(pathlib.Path(f"{self.log}.claude").read_text())
|
||||||
self.assertEqual(handed["prompt"], "Build the feature below in this project.\n\nAdd `Halve(a int) int`, which halves a.")
|
self.assertEqual(handed["prompt"], "Build the feature below in this project.\n\nAdd `Halve(a int) int`, which halves a.")
|
||||||
# Haiku's copy holds the code and git's own folder: not the features' folder, with its acceptance tests and reference patches.
|
# Haiku's copy holds the code and git's own folder: not the features' folder, with its acceptance tests and reference patches.
|
||||||
self.assertEqual(handed["handed"], [".git", "README.md", "calc.go", "calc_test.go"])
|
self.assertEqual(handed["handed"], [".git", "README.md", "calc.go", "calc_test.go", "dangling"])
|
||||||
results = json.loads((folder / "results.json").read_text())
|
results = json.loads((folder / "results.json").read_text())
|
||||||
self.assertEqual((results["features"], len(results["runs"])), ({"1": "halve"}, 4))
|
self.assertEqual((results["features"], len(results["runs"])), ({"1": "halve"}, 4))
|
||||||
self.assertEqual((results["runs"][0]["feature"], results["runs"][0]["passed"], results["runs"][0]["reads"]), (1, False, None))
|
self.assertEqual((results["runs"][0]["feature"], results["runs"][0]["passed"], results["runs"][0]["reads"]), (1, False, None))
|
||||||
@@ -182,10 +192,33 @@ class FeatureBenchTest(unittest.TestCase):
|
|||||||
self.assertNotIsInstance(report, Failure, report)
|
self.assertNotIsInstance(report, Failure, report)
|
||||||
self.assertIn("| 1: halve | head | 2/2 | 40 | 9000 | 52000 | 800 | 3 | 61.5 | - |", report)
|
self.assertIn("| 1: halve | head | 2/2 | 40 | 9000 | 52000 | 800 | 3 | 61.5 | - |", report)
|
||||||
|
|
||||||
|
def test_benches_a_base_whose_tree_lacks_the_features_folder(self):
|
||||||
|
# A project's first bench of features: the folder came with the head.
|
||||||
|
self.git("rm", "-r", "--quiet", "--cached", "bench-tasks")
|
||||||
|
self.git("commit", "--quiet", "--message", "Base without the features")
|
||||||
|
base = self.git("rev-parse", "HEAD")
|
||||||
|
self.head = self.commit("Add the features")
|
||||||
|
report = self.bench(**{"--base": base})
|
||||||
|
self.assertNotIsInstance(report, Failure, report)
|
||||||
|
self.assertEqual([line for line in report if line.startswith("| 1: halve |")], [
|
||||||
|
"| 1: halve | base | 2/2 | 40 | 9000 | 52000 | 800 | 3 | 61.5 | - |",
|
||||||
|
"| 1: halve | head | 2/2 | 40 | 9000 | 52000 | 800 | 3 | 61.5 | - |",
|
||||||
|
])
|
||||||
|
|
||||||
|
def test_passes_over_a_feature_whose_reference_patch_leans_on_a_test_or_testdata_file_it_adds(self):
|
||||||
|
# A build's tests and testdata files don't count, so the reference patch's don't either.
|
||||||
|
for path in ("halve_cases_test.go", "testdata/halved"):
|
||||||
|
with self.subTest(path=path):
|
||||||
|
shutil.rmtree(self.tasks / "leaning", ignore_errors=True)
|
||||||
|
feature(self.tasks / "leaning", patch=REFERENCE + added(path), acceptance=f"grep -q 'a / 2' halve.go && test -f {path} && exit 0\necho 'Halve or its cases are missing'\nexit 1\n", test="leaning_test.go")
|
||||||
|
report = self.bench()
|
||||||
|
self.assertNotIsInstance(report, Failure, report)
|
||||||
|
self.assertIn("Passed over the feature leaning: the tests fail with its reference patch at the base.", report)
|
||||||
|
|
||||||
def test_fails_where_no_feature_counts_saying_why_each_does_not(self):
|
def test_fails_where_no_feature_counts_saying_why_each_does_not(self):
|
||||||
(self.tasks / "halve/acceptance/halve_test.go").write_text("echo 'never passes'\nexit 1\n")
|
(self.tasks / "halve/acceptance/halve_test.go").write_text("echo 'never passes'\nexit 1\n")
|
||||||
feature(self.tasks / "stale", acceptance="exit 0\n", test="stale_test.go")
|
feature(self.tasks / "stale", acceptance="exit 0\n", test="stale_test.go")
|
||||||
self.assertEqual(self.bench().reason, f"None of the 2 features in {self.tasks} counts. halve: its acceptance tests fail with the reference patch at the base. stale: its acceptance tests pass at the base before it is built.")
|
self.assertEqual(self.bench().reason, f"None of the 2 features in {self.tasks} counts. halve: the tests fail with its reference patch at the base. stale: its acceptance tests pass at the base before it is built.")
|
||||||
self.assertNotIn(["claude"], [call[-2:-1] for call in map(json.loads, self.log.read_text().splitlines())])
|
self.assertNotIn(["claude"], [call[-2:-1] for call in map(json.loads, self.log.read_text().splitlines())])
|
||||||
|
|
||||||
def test_fails_before_any_container_starts_where_the_config_or_the_folder_is_at_fault(self):
|
def test_fails_before_any_container_starts_where_the_config_or_the_folder_is_at_fault(self):
|
||||||
@@ -219,6 +252,31 @@ class FeatureBenchTest(unittest.TestCase):
|
|||||||
self.assertEqual([found.name for found in features(self.tasks)], ["halve"])
|
self.assertEqual([found.name for found in features(self.tasks)], ["halve"])
|
||||||
|
|
||||||
|
|
||||||
|
class PassedOverTest(unittest.TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
folder = tempfile.TemporaryDirectory()
|
||||||
|
self.addCleanup(folder.cleanup)
|
||||||
|
self.folder = pathlib.Path(folder.name)
|
||||||
|
self.trees = {"base": str(self.folder / "base"), "head": str(self.folder / "head")}
|
||||||
|
for tree in self.trees.values():
|
||||||
|
pathlib.Path(tree).mkdir()
|
||||||
|
feature(self.folder / "halve")
|
||||||
|
self.feature = Feature("halve", "Add Halve.", str(self.folder / "halve/reference.patch"), str(self.folder / "halve/acceptance"))
|
||||||
|
|
||||||
|
def test_passes_a_feature_over_where_it_breaks_the_rule_at_the_head_alone(self):
|
||||||
|
late = TimedOut("docker run still ran after 30 min")
|
||||||
|
# The test command's runs in turn: before the build and with the reference patch at the base, then the same at the head.
|
||||||
|
for runs, why in (
|
||||||
|
((Ran(1, ""), Ran(0, ""), Ran(0, ""), Ran(0, "")), "its acceptance tests pass at the head before it is built"),
|
||||||
|
((Ran(1, ""), Ran(0, ""), Ran(1, ""), Ran(1, "")), "the tests fail with its reference patch at the head"),
|
||||||
|
((Ran(1, ""), Ran(0, ""), late), "the tests run out of time at the head"),
|
||||||
|
):
|
||||||
|
with self.subTest(why=why):
|
||||||
|
containers = Containers(InTurn(*runs), "bench", "go test ./...", 512, "1000:1000")
|
||||||
|
bench = Bench("", {"base": "b", "head": "h"}, self.trees, Asked(FEATURE, 1), containers, self.folder, lambda *args, **given: "", lambda line: None)
|
||||||
|
self.assertEqual(why_passed_over(bench, self.trees, self.feature), why)
|
||||||
|
|
||||||
|
|
||||||
class OptionsTest(unittest.TestCase):
|
class OptionsTest(unittest.TestCase):
|
||||||
def options(self, *argv: str):
|
def options(self, *argv: str):
|
||||||
return main.options(["--image", "golang:1.27.4", "--test", "go test ./...", *argv], {"CLAUDE_CODE_OAUTH_TOKEN": "sk"})
|
return main.options(["--image", "golang:1.27.4", "--test", "go test ./...", *argv], {"CLAUDE_CODE_OAUTH_TOKEN": "sk"})
|
||||||
@@ -234,7 +292,7 @@ class OptionsTest(unittest.TestCase):
|
|||||||
def test_the_options_that_choose_bugs_are_refused_with_features(self):
|
def test_the_options_that_choose_bugs_are_refused_with_features(self):
|
||||||
for option in ("--seed", "--bugs", "--prefix"):
|
for option in ("--seed", "--bugs", "--prefix"):
|
||||||
with self.subTest(option=option):
|
with self.subTest(option=option):
|
||||||
self.assertEqual(self.options("--tasks", "features", option, "2").reason, f"{option} chooses the bugs to plant, so it doesn't go with --tasks features")
|
self.assertEqual(self.options("--tasks", "features", option, "2").reason, f"{option} is for a bench of bugs, so it doesn't go with --tasks features")
|
||||||
self.assertNotIn("--seed", self.options("--tasks", "features"))
|
self.assertNotIn("--seed", self.options("--tasks", "features"))
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ class BenchTest(unittest.TestCase):
|
|||||||
(fakes / "gremlins.py").write_text(GREMLINS)
|
(fakes / "gremlins.py").write_text(GREMLINS)
|
||||||
self.log = self.root / "docker.log"
|
self.log = self.root / "docker.log"
|
||||||
self.env = {**isolated_env(), "HOME": str(self.home), "PATH": f"{fakes}{os.pathsep}{os.environ['PATH']}", "FAKE_LOG": str(self.log), "FAKE_CLAUDE": str(fakes / "claude.py"), "CLAUDE_CODE_OAUTH_TOKEN": "sk-secret-token", "RUN_HEAVY_MEMORY": "2048"}
|
self.env = {**isolated_env(), "HOME": str(self.home), "PATH": f"{fakes}{os.pathsep}{os.environ['PATH']}", "FAKE_LOG": str(self.log), "FAKE_CLAUDE": str(fakes / "claude.py"), "CLAUDE_CODE_OAUTH_TOKEN": "sk-secret-token", "RUN_HEAVY_MEMORY": "2048"}
|
||||||
self.given = {"--image": "golang:1.27.4", "--test": "sh calc_test.go", "--prefix": f"{sys.executable} {fakes / 'gremlins.py'}", "--seed": "1", "--bugs": "2", "--runs": "2"}
|
self.given = {"--image": "golang:1.27.4", "--test": "sh calc_test.go", "--prefix": f"{sys.executable} {fakes / 'gremlins.py'}", "--seed": "1", "--bugs": "2", "--runs": "2", "--tasks": "bugs"}
|
||||||
self.git("init", "--quiet", "--initial-branch", "main")
|
self.git("init", "--quiet", "--initial-branch", "main")
|
||||||
for name, text in (("calc.go", BASE_CODE), ("calc_test.go", TESTS), ("README.md", "# Calc\n")):
|
for name, text in (("calc.go", BASE_CODE), ("calc_test.go", TESTS), ("README.md", "# Calc\n")):
|
||||||
(self.repo / name).write_text(text)
|
(self.repo / name).write_text(text)
|
||||||
@@ -127,7 +127,7 @@ class BenchTest(unittest.TestCase):
|
|||||||
|
|
||||||
def bench(self, **given: str):
|
def bench(self, **given: str):
|
||||||
with contextlib.redirect_stderr(io.StringIO()) as self.progress:
|
with contextlib.redirect_stderr(io.StringIO()) as self.progress:
|
||||||
return main.bench({**self.given, "--base": "main", **given}, self.env, PLACES, self.home)
|
return main.bench({**self.given, "--base": "main", **given}, self.env, lambda home: PLACES, self.home)
|
||||||
|
|
||||||
def calls(self) -> list[list[str]]:
|
def calls(self) -> list[list[str]]:
|
||||||
return [json.loads(line) for line in self.log.read_text().splitlines()]
|
return [json.loads(line) for line in self.log.read_text().splitlines()]
|
||||||
@@ -301,7 +301,7 @@ class BenchTest(unittest.TestCase):
|
|||||||
|
|
||||||
def test_fails_where_the_places_name_no_go_file_of_the_base(self):
|
def test_fails_where_the_places_name_no_go_file_of_the_base(self):
|
||||||
with contextlib.redirect_stderr(io.StringIO()):
|
with contextlib.redirect_stderr(io.StringIO()):
|
||||||
found = main.bench({**self.given, "--base": "main"}, self.env, "- `gone.go:1` `Gone`: removed\n- `README.md:1` `Calc`: thin\n", self.home)
|
found = main.bench({**self.given, "--base": "main"}, self.env, lambda home: "- `gone.go:1` `Gone`: removed\n- `README.md:1` `Calc`: thin\n", self.home)
|
||||||
self.assertEqual(found, 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."))
|
self.assertEqual(found, 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."))
|
||||||
self.assertFalse(self.log.exists())
|
self.assertFalse(self.log.exists())
|
||||||
|
|
||||||
@@ -402,11 +402,11 @@ class ReportTest(unittest.TestCase):
|
|||||||
]
|
]
|
||||||
|
|
||||||
def test_names_the_commits_the_bugs_the_runs_and_what_ran_them_above_the_table(self):
|
def test_names_the_commits_the_bugs_the_runs_and_what_ran_them_above_the_table(self):
|
||||||
told = main.report(self.SIDES, self.NAMES, main.Asked(main.BUG, 2, 1, 1), self.RESULTS, [])
|
told = main.report(self.SIDES, self.NAMES, main.Asked(main.BUG, 2), self.RESULTS, [])
|
||||||
self.assertEqual(told, ["task-bench: base bbbbbbbbbbbb, head hhhhhhhhhhhh. 1 bug, each run 2 times at each side by claude-haiku-5-5 in Claude Code 2.1.330.", "", *self.TABLE, ""])
|
self.assertEqual(told, ["task-bench: base bbbbbbbbbbbb, head hhhhhhhhhhhh. 1 bug, each run 2 times at each side by claude-haiku-5-5 in Claude Code 2.1.330.", "", *self.TABLE, ""])
|
||||||
|
|
||||||
def test_says_where_fewer_bugs_were_planted_than_asked_for_and_where_no_run_finished(self):
|
def test_says_where_fewer_bugs_were_planted_than_asked_for_and_where_no_run_finished(self):
|
||||||
told = main.report(self.SIDES, self.NAMES, main.Asked(main.BUG, 1, 1, 3), self.RESULTS[1:], ["Planted 1 of the 3 bugs asked for: no other mutant the tests kill becomes one."])
|
told = main.report(self.SIDES, self.NAMES, main.Asked(main.BUG, 1), self.RESULTS[1:], ["Planted 1 of the 3 bugs asked for: no other mutant the tests kill becomes one."])
|
||||||
self.assertEqual(told[:3], ["task-bench: base bbbbbbbbbbbb, head hhhhhhhhhhhh. 1 bug, each run 1 time at each side by no run that finished.", "Planted 1 of the 3 bugs asked for: no other mutant the tests kill becomes one.", ""])
|
self.assertEqual(told[:3], ["task-bench: base bbbbbbbbbbbb, head hhhhhhhhhhhh. 1 bug, each run 1 time at each side by no run that finished.", "Planted 1 of the 3 bugs asked for: no other mutant the tests kill becomes one.", ""])
|
||||||
|
|
||||||
def test_a_stopped_bench_tells_why_then_how_far_it_came_then_the_table(self):
|
def test_a_stopped_bench_tells_why_then_how_far_it_came_then_the_table(self):
|
||||||
@@ -500,7 +500,7 @@ class RunOutcomesTest(unittest.TestCase):
|
|||||||
return Containers(InTurn(*runs), "bench", "go test ./...", 512, "1000:1000")
|
return Containers(InTurn(*runs), "bench", "go test ./...", 512, "1000:1000")
|
||||||
|
|
||||||
def bench(self, *runs: Ran | Failure) -> main.Bench:
|
def bench(self, *runs: Ran | Failure) -> main.Bench:
|
||||||
return main.Bench("", {"base": "b", "head": "h"}, self.trees, main.Asked(main.BUG, 1, 1, 1), self.containers(*runs), self.folder, lambda *args, **given: "", lambda line: None)
|
return main.Bench("", {"base": "b", "head": "h"}, self.trees, main.Asked(main.BUG, 1), self.containers(*runs), self.folder, lambda *args, **given: "", lambda line: None)
|
||||||
|
|
||||||
def test_a_fix_whose_tests_run_out_of_time_does_not_pass(self):
|
def test_a_fix_whose_tests_run_out_of_time_does_not_pass(self):
|
||||||
late = TimedOut("docker run still ran after 30 min")
|
late = TimedOut("docker run still ran after 30 min")
|
||||||
@@ -512,7 +512,7 @@ class RunOutcomesTest(unittest.TestCase):
|
|||||||
|
|
||||||
def test_tests_docker_could_not_run_without_a_bug_fail_the_bench(self):
|
def test_tests_docker_could_not_run_without_a_bug_fail_the_bench(self):
|
||||||
broke = Failure("docker could not start: No such file or directory")
|
broke = Failure("docker could not start: No such file or directory")
|
||||||
self.assertEqual(main.benched(self.bench(broke), lambda bench: main.planted_tasks(bench, [])), broke)
|
self.assertEqual(main.benched(self.bench(broke), lambda bench: main.planted_tasks(bench, [], 1, 1)), broke)
|
||||||
|
|
||||||
def test_a_mutant_whose_tests_run_out_of_time_is_passed_over(self):
|
def test_a_mutant_whose_tests_run_out_of_time_is_passed_over(self):
|
||||||
late = TimedOut("docker run still ran after 30 min")
|
late = TimedOut("docker run still ran after 30 min")
|
||||||
@@ -536,7 +536,7 @@ class RunOutcomesTest(unittest.TestCase):
|
|||||||
|
|
||||||
def test_results_that_cannot_be_written_fail_the_bench_naming_the_folder(self):
|
def test_results_that_cannot_be_written_fail_the_bench_naming_the_folder(self):
|
||||||
bench = dataclasses.replace(self.bench(), folder=self.folder / "gone")
|
bench = dataclasses.replace(self.bench(), folder=self.folder / "gone")
|
||||||
self.assertFailsWith(main.kept(bench, [], {}, []), f"could not write the results under {self.folder / 'gone'}: ")
|
self.assertFailsWith(main.kept(bench, main.Planned([], [], {}), {}, []), f"could not write the results under {self.folder / 'gone'}: ")
|
||||||
|
|
||||||
def test_a_bug_that_cannot_be_planted_fails_the_bench_naming_the_tree(self):
|
def test_a_bug_that_cannot_be_planted_fails_the_bench_naming_the_tree(self):
|
||||||
(self.folder / "file").write_text("")
|
(self.folder / "file").write_text("")
|
||||||
@@ -561,7 +561,7 @@ class RunOutcomesTest(unittest.TestCase):
|
|||||||
def test_a_digest_quoting_half_of_a_surrogate_pair_is_written_with_a_question_mark_in_its_place(self):
|
def test_a_digest_quoting_half_of_a_surrogate_pair_is_written_with_a_question_mark_in_its_place(self):
|
||||||
# Claude Code may cut a string between the halves of an emoji's pair, and JSON parses the half it keeps into a lone surrogate.
|
# Claude Code may cut a string between the halves of an emoji's pair, and JSON parses the half it keeps into a lone surrogate.
|
||||||
said = entry_from(json.loads('{"type": "assistant", "message": {"content": [{"type": "text", "text": "half \\ud83d pair"}]}}'))
|
said = entry_from(json.loads('{"type": "assistant", "message": {"content": [{"type": "text", "text": "half \\ud83d pair"}]}}'))
|
||||||
self.assertIsNone(main.kept(self.bench(), [self.task], {1: "calc.go:4:11 ARITHMETIC_BASE"}, [Result(1, "base", 1, False, None, [said])]))
|
self.assertIsNone(main.kept(self.bench(), main.Planned([self.task], [], {"seed": 1}), {1: "calc.go:4:11 ARITHMETIC_BASE"}, [Result(1, "base", 1, False, None, [said])]))
|
||||||
self.assertIn("half ? pair", (self.folder / "digest.md").read_text(encoding="utf-8"))
|
self.assertIn("half ? pair", (self.folder / "digest.md").read_text(encoding="utf-8"))
|
||||||
|
|
||||||
def test_a_mutant_in_a_file_the_head_lacks_is_passed_over(self):
|
def test_a_mutant_in_a_file_the_head_lacks_is_passed_over(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user