Start every feature from one committed tree per side, and name the kind of task in each table and digest
CI / tests (pull_request) Successful in 3m44s
CI / tests (pull_request) Successful in 3m44s
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
"""The features task-bench has Haiku build: each a folder in the project's `bench-tasks` folder, with a spec, a reference patch
|
||||
that builds it, and acceptance tests Haiku never sees. A feature counts at the two commits of a bench only where those tests fail
|
||||
at both before it is built, and pass at both with the reference patch."""
|
||||
import itertools
|
||||
import pathlib
|
||||
import shutil
|
||||
import typing
|
||||
@@ -86,62 +87,61 @@ def feature_in(folder: pathlib.Path) -> Feature | Failure:
|
||||
def feature_tasks(bench: Bench, found: list[Feature], folder: pathlib.Path) -> Planned | Failure:
|
||||
"""The task of building each feature of found that counts at the bench's commits, numbered from 1, and a line on each that
|
||||
doesn't. A Failure where none counts. folder is where the features are kept."""
|
||||
trees = committed_trees(bench)
|
||||
if isinstance(trees, Failure):
|
||||
return trees
|
||||
tasks: list[Task] = []
|
||||
passed_over: list[tuple[str, str]] = []
|
||||
for feature in found:
|
||||
task = feature_task(bench, len(tasks) + 1, feature)
|
||||
if isinstance(task, Failure):
|
||||
return task
|
||||
if isinstance(task, Task):
|
||||
tasks.append(task)
|
||||
why = why_passed_over(bench, trees, feature)
|
||||
if isinstance(why, Failure):
|
||||
return why
|
||||
if why is None:
|
||||
tasks.append(Task(len(tasks) + 1, feature.name, trees, dict.fromkeys(SIDES, feature.spec), acceptance=feature.acceptance))
|
||||
else:
|
||||
passed_over.append((feature.name, task))
|
||||
bench.say(f"task-bench: passed over the feature {feature.name}: {task}.")
|
||||
passed_over.append((feature.name, why))
|
||||
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])
|
||||
|
||||
|
||||
def feature_task(bench: Bench, number: int, feature: Feature) -> Task | str | Failure:
|
||||
"""The task of building feature, each side's tree committed once; or why the feature doesn't count."""
|
||||
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
|
||||
works in."""
|
||||
trees: dict[Side, str] = {}
|
||||
for side in SIDES:
|
||||
tree = bench.folder / "features" / str(number) / side
|
||||
# A feature passed over before this one left its trees under the same number.
|
||||
shutil.rmtree(tree, ignore_errors=True)
|
||||
tree = bench.folder / "features" / side
|
||||
copied = on_disk(f"copy the {side}'s tree to {tree}", lambda: shutil.copytree(bench.trees[side], tree, symlinks=True))
|
||||
if isinstance(copied, Failure):
|
||||
return copied
|
||||
if failure := committed(bench.git, str(tree)):
|
||||
return failure
|
||||
passed_over = why_passed_over(bench, str(tree), side, feature)
|
||||
if passed_over is not None:
|
||||
return passed_over
|
||||
trees[side] = str(tree)
|
||||
return Task(number, feature.name, trees, dict.fromkeys(SIDES, feature.spec), acceptance=feature.acceptance)
|
||||
return trees
|
||||
|
||||
|
||||
def why_passed_over(bench: Bench, tree: str, side: Side, feature: Feature) -> str | Failure | None:
|
||||
"""Why feature doesn't count at side, whose committed tree is tree; None where it counts. A Failure where the tests could
|
||||
not run."""
|
||||
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", "--whitespace=nowarn", feature.patch, cwd=copy)
|
||||
applied = bench.git("apply", feature.patch, cwd=copy)
|
||||
return NotApplied(applied.reason) if isinstance(applied, Failure) else put(copy)
|
||||
|
||||
for prepare, reference in ((put, ""), (built, " with the reference patch")):
|
||||
ran = tests_in_copy(bench.containers, tree, bench.folder, prepare)
|
||||
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):
|
||||
return f"its reference patch doesn't apply at the {side}"
|
||||
if isinstance(ran, TimedOut):
|
||||
return f"its acceptance tests don't end{reference} at the {side}"
|
||||
return f"its acceptance tests don't end at the {side}"
|
||||
if isinstance(ran, Failure):
|
||||
return ran
|
||||
if not reference 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"
|
||||
if reference and ran.code:
|
||||
if is_built and ran.code:
|
||||
return f"its acceptance tests fail with the reference patch at the {side}"
|
||||
return None
|
||||
|
||||
Reference in New Issue
Block a user