Answer stability round 1: 1 🔴, 2 🟡 (1 misread); a feature whose branch landed by fast-forward is passed over and item 531 files benching it, a test refuses a plan outside the checkout from another folder, and the README states the import once
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
"""The features task-bench has Haiku rebuild: those the project shipped, read from its history rather than written for the bench.
|
||||
A shipped feature is a chunk on the base's first-parent line that took an item out of the plan, as branch_chunks cuts that line.
|
||||
The bench takes the chunk's change out of each side's tree and tells Haiku the item's tagline. From there it is a feature as
|
||||
task_bench.feature_tasks has it: its reference patch is the chunk's change, and its acceptance tests are the tests that change
|
||||
holds."""
|
||||
"""The features task-bench has Haiku rebuild: those the project shipped, read from its history. A shipped feature is a chunk on
|
||||
the base's first-parent line that took an item out of the plan, as branch_chunks cuts that line. Once its change is out of each
|
||||
side's tree, it is a feature as task_bench.feature_tasks has it. `task-bench --help` says what Haiku is told and how a rebuild
|
||||
is checked."""
|
||||
import functools
|
||||
import os
|
||||
import pathlib
|
||||
@@ -14,25 +13,31 @@ from task_bench.tasks import Bench, committed, on_disk, Planned, Task
|
||||
from branch_chunks.read import cut_with_shipped, unsupported
|
||||
from failure import Failure
|
||||
from git_cli.git_repo import Git
|
||||
from plan.todo_table import Item
|
||||
from plan.todo_table import Item, tagline_text
|
||||
from branch_chunks.cut import Landing
|
||||
from project_config.main import located
|
||||
from task_bench.runs import of_tests
|
||||
from project_config.settings import RECORDS
|
||||
from task_bench.figures import Side, SIDES
|
||||
|
||||
# The options that keep the checkout's diff config out of a diff. A rename is written as a removal and an addition, which
|
||||
# `git apply` takes whatever it would have detected.
|
||||
# Why a feature whose chunk landed by fast-forward is passed over. Each of its commits is a chunk of its own to branch_chunks,
|
||||
# so the chunk that took the item out holds the branch's last commit alone.
|
||||
FAST_FORWARDED = "its branch landed by fast-forward, so the history doesn't say which commits built it"
|
||||
|
||||
# The options that keep the checkout's diff config out of a patch. --no-renames writes a renamed file as one file removed and
|
||||
# one added, so `git apply` doesn't have to detect the rename again.
|
||||
PLAIN_DIFF = ("--no-color", "--no-ext-diff", "--no-textconv", "--no-renames", "--src-prefix=a/", "--dst-prefix=b/")
|
||||
|
||||
|
||||
class Shipped(typing.NamedTuple):
|
||||
"""A feature the project shipped: the name the report gives it, such as `item 7`, the tagline of each item its chunk took out
|
||||
of the plan, a paragraph each, and the commits its chunk's change runs between."""
|
||||
of the plan, a paragraph each, the commits its chunk's change runs between, and how the chunk landed."""
|
||||
|
||||
name: str
|
||||
told: str
|
||||
before: str
|
||||
tip: str
|
||||
landing: Landing
|
||||
|
||||
|
||||
class ShippedFeatures(typing.NamedTuple):
|
||||
@@ -45,7 +50,8 @@ class ShippedFeatures(typing.NamedTuple):
|
||||
|
||||
def read_shipped(home: pathlib.Path, checkout: str, base: str, git: Git) -> ShippedFeatures | Failure:
|
||||
"""The features that the project in checkout shipped on the first-parent line of the commit base. A Failure where no config
|
||||
names the checkout, where it keeps its plan where branch_chunks doesn't read it, and where that line shipped no item."""
|
||||
names the checkout, where its config puts the plan or a record at a path branch_chunks doesn't read, where git fails, and
|
||||
where that line shipped no item."""
|
||||
in_checkout = functools.partial(git, cwd=checkout)
|
||||
config = located(checkout, home, in_checkout)
|
||||
if isinstance(config, Failure):
|
||||
@@ -57,13 +63,12 @@ def read_shipped(home: pathlib.Path, checkout: str, base: str, git: Git) -> Ship
|
||||
return cut
|
||||
branch, shipped = cut
|
||||
found = [
|
||||
# parse_row keeps a tagline in its two pairs of asterisks.
|
||||
Shipped(named(items), "\n\n".join(item.tagline[2:-2] for item in items), chunk.before, chunk.tip)
|
||||
Shipped(named(items), "\n\n".join(tagline_text(item.tagline) for item in items), chunk.before, chunk.tip, chunk.landing)
|
||||
for chunk, items in zip(branch.chunks, shipped)
|
||||
if items and chunk.before
|
||||
]
|
||||
if not found:
|
||||
return Failure("No chunk on the base's history took an item out of todo.md, so it holds no shipped feature to rebuild.")
|
||||
return Failure("No chunk on the base's history took an item out of todo.md, so that history holds no shipped feature to rebuild.")
|
||||
return ShippedFeatures(found, [path for path in map(config.tracked, ("plan", *RECORDS)) if path])
|
||||
|
||||
|
||||
@@ -73,16 +78,18 @@ def named(items: tuple[Item, ...]) -> str:
|
||||
|
||||
|
||||
def shipped_tasks(bench: Bench, shipped: ShippedFeatures, count: int) -> Planned | Failure:
|
||||
"""The task of rebuilding each of the first count features of shipped that count at the bench's commits, numbered from 1, and
|
||||
a line on each one passed over on the way. A Failure where none counts."""
|
||||
"""The task of rebuilding each feature of shipped that counts at the bench's commits, newest first, until there are count
|
||||
tasks. The tasks are numbered from 1, and a line says why each feature on the way was passed over. A Failure where none
|
||||
counts."""
|
||||
noun = bench.asked.kind.noun
|
||||
tasks: list[Task] = []
|
||||
passed_over: list[str] = []
|
||||
for feature in shipped.found:
|
||||
if len(tasks) == count:
|
||||
break
|
||||
folder = bench.folder / "shipped-features" / folder_name(feature.name)
|
||||
taken_out = on_disk(f"take {feature.name} out of the trees in {folder}", lambda: without(bench, feature, shipped.records, folder))
|
||||
# A feature passed over leaves no folder, so the next one tried takes the same number.
|
||||
folder = bench.folder / "shipped-features" / str(len(tasks) + 1)
|
||||
taken_out = FAST_FORWARDED if feature.landing == "push" else on_disk(f"take {feature.name} out of the trees in {folder}", lambda: without(bench, feature, shipped.records, folder))
|
||||
why = taken_out if not isinstance(taken_out, TakenOut) else why_passed_over(bench, taken_out.trees, taken_out.feature)
|
||||
if isinstance(why, Failure):
|
||||
return why
|
||||
@@ -93,13 +100,13 @@ def shipped_tasks(bench: Bench, shipped: ShippedFeatures, count: int) -> Planned
|
||||
passed_over.append(f"the {noun} {feature.name}: {why}.")
|
||||
bench.say(f"task-bench: passed over {passed_over[-1]}")
|
||||
if not tasks:
|
||||
return Failure(f"None of the {len(shipped.found)} {noun}s on the base's history counts; the lines above say why.")
|
||||
return Failure(f"No {noun} on the base's history counts; the lines above say why.")
|
||||
return Planned(tasks, [f"Passed over {line}" for line in passed_over], {})
|
||||
|
||||
|
||||
def folder_name(name: str) -> str:
|
||||
"""The folder that keeps the trees of the feature called name: `items-7-8` for `items 7, 8`."""
|
||||
return "-".join(name.replace(",", "").split())
|
||||
def held(path: str) -> bool:
|
||||
"""Whether path is a file or a link, which copies as a test does; a folder doesn't."""
|
||||
return os.path.islink(path) or os.path.isfile(path)
|
||||
|
||||
|
||||
class TakenOut(typing.NamedTuple):
|
||||
@@ -116,18 +123,19 @@ def without(bench: Bench, shipped: Shipped, records: list[str], folder: pathlib.
|
||||
|
||||
Raises OSError where a file cannot be copied."""
|
||||
change = (shipped.before, shipped.tip, "--", ".", *(f":(exclude,literal){path}" for path in records))
|
||||
# A path that is not UTF-8 is replaced, so the head's tree doesn't hold it and it is left out.
|
||||
# A name that is not UTF-8 is read with U+FFFD in it. The head's tree holds no file of that name, so the file is left out.
|
||||
names = bench.git("diff", "--name-only", "-z", *change, cwd=bench.checkout, errors="replace")
|
||||
if isinstance(names, Failure):
|
||||
return names
|
||||
tests = [path for path in names.split("\x00") if path and of_tests(path) and os.path.lexists(os.path.join(bench.trees["head"], path))]
|
||||
tests = [path for path in names.split("\x00") if path and of_tests(path) and held(os.path.join(bench.trees["head"], path))]
|
||||
if not tests:
|
||||
return "its change holds no test that the head holds"
|
||||
patch, acceptance = folder / PATCH, folder / ACCEPTANCE
|
||||
for path in tests:
|
||||
os.makedirs(os.path.dirname(acceptance / path), exist_ok=True)
|
||||
shutil.copy2(os.path.join(bench.trees["head"], path), acceptance / path, follow_symlinks=False)
|
||||
# --binary writes a binary file's bytes, which `git apply` needs, and --output keeps git from decoding them.
|
||||
# --binary writes a binary file's bytes, which `git apply` needs. --output has git write them to the file, since bench.git
|
||||
# would read them from its output as text.
|
||||
diffed = bench.git("diff", "--binary", f"--output={patch}", *PLAIN_DIFF, *change, cwd=bench.checkout)
|
||||
if isinstance(diffed, Failure):
|
||||
return diffed
|
||||
|
||||
Reference in New Issue
Block a user