Test a shipped feature's binary file, linked test, removed test and passing test, a checkout that drops a diff's prefixes, and a bench run from a folder inside the checkout
This commit is contained in:
@@ -81,7 +81,7 @@ def shipped_tasks(bench: Bench, shipped: ShippedFeatures, count: int) -> Planned
|
||||
for feature in shipped.found:
|
||||
if len(tasks) == count:
|
||||
break
|
||||
folder = bench.folder / "shipped-features" / "-".join(feature.name.replace(",", "").split())
|
||||
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))
|
||||
why = taken_out if not isinstance(taken_out, TakenOut) else why_passed_over(bench, taken_out.trees, taken_out.feature)
|
||||
if isinstance(why, Failure):
|
||||
@@ -97,6 +97,11 @@ def shipped_tasks(bench: Bench, shipped: ShippedFeatures, count: int) -> Planned
|
||||
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())
|
||||
|
||||
|
||||
class TakenOut(typing.NamedTuple):
|
||||
"""A shipped feature taken out of the bench's trees: each side's tree without it, committed once, and the feature that
|
||||
builds it there again."""
|
||||
@@ -112,7 +117,7 @@ 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.
|
||||
names = bench.git("diff", "--name-only", "-z", *PLAIN_DIFF, *change, cwd=bench.checkout, errors="replace")
|
||||
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))]
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
"""`task-bench --tasks shipped-features` from its command line down: a whole bench of the features a project's history shipped,
|
||||
with docker and claude faked, and the histories it passes over."""
|
||||
import contextlib
|
||||
import functools
|
||||
import json
|
||||
import os
|
||||
import pathlib
|
||||
import re
|
||||
import subprocess
|
||||
@@ -13,24 +15,26 @@ sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
||||
from task_bench.test_feature_tasks import ACCEPTANCE, BenchOfTasksCase
|
||||
from task_bench.test_task_bench import BASE_CODE, HEAD_CODE
|
||||
from failure import Failure
|
||||
from task_bench.shipped_features import folder_name, read_shipped
|
||||
from git_cli.git_repo import git
|
||||
from task_bench import main
|
||||
from branch_chunks.read import READ_AT
|
||||
from task_bench.shipped_features import read_shipped
|
||||
|
||||
HEADER = "| ID | Release | Blocked by | Exempt | Item | L | E | I | R | S | Moves |\n|---|---|---|---|---|---|---|---|---|---|---|\n"
|
||||
ROWS = {
|
||||
7: "| 7 | 0.1.0 | | | **Add `Halve`, which halves a whole number.** | 2 | 2 | 1 | 3 | 3 | 1.1 by 3 |\n",
|
||||
8: "| 8 | 0.1.0 | | | **Multiply in `Twice`.** | 2 | 2 | 1 | 3 | 3 | 1.1 by 3 |\n",
|
||||
9: "| 9 | 0.1.0 | | | **Say in the README what Calc is.** | 2 | 2 | 1 | 3 | 3 | 1.1 by 3 |\n",
|
||||
10: "| 10 | 0.1.0 | | | **Keep `Twice` whole.** | 2 | 2 | 1 | 3 | 3 | 1.1 by 3 |\n",
|
||||
}
|
||||
HALVE = "package calc\n\nfunc Halve(a int) int {\n\treturn a / 2\n}\n"
|
||||
|
||||
|
||||
class ShippedFeaturesCase(BenchOfTasksCase):
|
||||
"""BenchOfTasksCase's checkout, whose default branch then shipped three items, each in a chunk rebased onto it, oldest first:
|
||||
item 8 wrote the line of Twice that the head rewrites, item 7 added Halve with its test, and item 9 changed the README alone.
|
||||
The head branches off after them."""
|
||||
"""BenchOfTasksCase's checkout, whose default branch then shipped four items, each in a chunk rebased onto it, oldest first:
|
||||
item 8 wrote the line of Twice that the head rewrites, item 7 added Halve with a binary file, its test and a link to that
|
||||
test, item 9 changed the README alone, and item 10 added only a test that passes without it. The head branches off after
|
||||
them. The checkout's config writes a diff without the `a/` and `b/` that `git apply` strips."""
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
@@ -38,22 +42,28 @@ class ShippedFeaturesCase(BenchOfTasksCase):
|
||||
# branch_chunks reads the plan and two records at these paths alone.
|
||||
self.config.write_text(re.sub(r'"checkout:(plan|comprehension-history|reading-cost)\.md"', lambda found: f'"checkout:{READ_AT[found[1]]}"', self.config.read_text()))
|
||||
self.git("checkout", "--quiet", "main")
|
||||
self.git("config", "diff.noprefix", "true")
|
||||
self.git("rm", "--quiet", "-r", "bench-tasks")
|
||||
(self.repo / "calc.go").write_text(BASE_CODE.replace("a * 2", "a + a"))
|
||||
self.plan(7, 8, 9)
|
||||
self.landed(1, "Plan three items")
|
||||
self.plan(7, 8, 9, 10)
|
||||
self.landed(1, "Plan four items")
|
||||
(self.repo / "calc.go").write_text(BASE_CODE)
|
||||
(self.repo / "twice_test.go").write_text("grep -q 'a \\* 2\\|2 \\* a' calc.go\n")
|
||||
self.plan(7, 9)
|
||||
self.plan(7, 9, 10)
|
||||
self.landed(2, "Multiply in Twice", "Finish item 8 in the plan")
|
||||
(self.repo / "halve_test.go").write_text(ACCEPTANCE)
|
||||
self.landed(3, "Test Halve")
|
||||
(self.repo / "halve.go").write_text(HALVE)
|
||||
self.plan(9)
|
||||
(self.repo / "halve.bin").write_bytes(b"\x00\xff")
|
||||
os.symlink("halve_test.go", self.repo / "linked_test.go")
|
||||
self.plan(9, 10)
|
||||
self.landed(3, "Add Halve", "Finish item 7 in the plan")
|
||||
(self.repo / "README.md").write_text("# Calc\n\nIt adds.\n")
|
||||
self.plan()
|
||||
self.plan(10)
|
||||
self.landed(4, "Say what Calc is")
|
||||
(self.repo / "whole_test.go").write_text("exit 0\n")
|
||||
self.plan()
|
||||
self.landed(5, "Keep Twice whole", "Finish item 10 in the plan")
|
||||
self.base = self.git("rev-parse", "HEAD")
|
||||
self.git("checkout", "--quiet", "-B", "item-1")
|
||||
(self.repo / "calc.go").write_text(HEAD_CODE)
|
||||
@@ -80,6 +90,7 @@ class ShippedFeatureBenchTest(ShippedFeaturesCase):
|
||||
folder = pathlib.Path(report[-1].removeprefix(main.KEPT))
|
||||
self.assertEqual(report[:-1], [
|
||||
f"task-bench: base {self.base[:12]}, head {self.head[:12]}. 1 shipped feature, each run 2 times at each side by claude-haiku-5-5 in Claude Code 2.1.330.",
|
||||
"Passed over the shipped feature item 10: its acceptance tests pass at the base before it is built.",
|
||||
"Passed over the shipped feature item 9: its change holds no test that the head holds.",
|
||||
"Passed over the shipped feature item 8: its revert doesn't apply at the head.",
|
||||
"",
|
||||
@@ -94,8 +105,8 @@ class ShippedFeatureBenchTest(ShippedFeaturesCase):
|
||||
])
|
||||
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`, which halves a whole number.")
|
||||
# Haiku's copy holds the tree without Halve and without its test; the plan and the README stay as the side holds them.
|
||||
self.assertEqual(handed["handed"], [".git", "README.md", "calc.go", "calc_test.go", "dangling", "todo.md", "twice_test.go"])
|
||||
# Haiku's copy holds the tree without Halve, its binary file and its tests; the plan and the later items' files stay as the side holds them.
|
||||
self.assertEqual(handed["handed"], [".git", "README.md", "calc.go", "calc_test.go", "dangling", "todo.md", "twice_test.go", "whole_test.go"])
|
||||
results = json.loads((folder / "results.json").read_text())
|
||||
self.assertEqual((results["shipped-features"], len(results["runs"])), ({"1": "item 7"}, 4))
|
||||
self.assertEqual(sorted(path.name for path in (folder / "runs").iterdir() if path.suffix == ".jsonl"), [f"shipped-feature-1-{side}-{run}.jsonl" for side in ("base", "head") for run in (1, 2)])
|
||||
@@ -104,24 +115,51 @@ class ShippedFeatureBenchTest(ShippedFeaturesCase):
|
||||
report = self.bench(**{"--shipped": "1"})
|
||||
self.assertNotIsInstance(report, Failure, report)
|
||||
# Item 8 shipped before item 7, which filled the bench, so nothing is said of it.
|
||||
self.assertEqual(report[1:3], ["Passed over the shipped feature item 9: its change holds no test that the head holds.", ""])
|
||||
self.assertEqual(report[1:4], [
|
||||
"Passed over the shipped feature item 10: its acceptance tests pass at the base before it is built.",
|
||||
"Passed over the shipped feature item 9: its change holds no test that the head holds.",
|
||||
"",
|
||||
])
|
||||
|
||||
def test_gives_haiku_a_tree_whose_one_commit_holds_it_without_the_feature(self):
|
||||
report = self.bench()
|
||||
tree = pathlib.Path(report[-1].removeprefix(main.KEPT)) / "shipped-features" / "item-7" / "head"
|
||||
self.assertEqual(sorted(path.name for path in tree.iterdir()), [".git", "README.md", "calc.go", "calc_test.go", "dangling", "todo.md", "twice_test.go"])
|
||||
self.assertEqual(sorted(path.name for path in tree.iterdir()), [".git", "README.md", "calc.go", "calc_test.go", "dangling", "todo.md", "twice_test.go", "whole_test.go"])
|
||||
self.assertEqual(subprocess.run(["git", "log", "--format=%s"], cwd=tree, env=self.env, check=True, capture_output=True, text=True).stdout, "Import\n")
|
||||
self.assertEqual(subprocess.run(["git", "status", "--porcelain"], cwd=tree, env=self.env, check=True, capture_output=True, text=True).stdout, "")
|
||||
|
||||
def test_keeps_a_test_that_is_a_link_as_a_link(self):
|
||||
report = self.bench()
|
||||
acceptance = pathlib.Path(report[-1].removeprefix(main.KEPT)) / "shipped-features" / "item-7" / "acceptance"
|
||||
self.assertEqual(sorted(path.name for path in acceptance.iterdir()), ["halve_test.go", "linked_test.go"])
|
||||
self.assertEqual(os.readlink(acceptance / "linked_test.go"), "halve_test.go")
|
||||
|
||||
def test_benches_the_whole_checkout_from_a_folder_inside_it(self):
|
||||
(self.repo / "inside").mkdir()
|
||||
self.enterContext(contextlib.chdir(self.repo / "inside"))
|
||||
report = self.bench()
|
||||
self.assertNotIsInstance(report, Failure, report)
|
||||
self.assertIn("| 1: item 7 | head | 2/2 | 40 | 9000 | 52000 | 800 | 3 | 61.5 | - |", report)
|
||||
|
||||
def test_passes_over_a_feature_whose_test_the_head_removed(self):
|
||||
# The checkout the process runs in still holds the test.
|
||||
self.git("checkout", "--quiet", "-b", "without-test")
|
||||
self.git("rm", "--quiet", "halve_test.go", "linked_test.go")
|
||||
self.commit("Remove Halve's tests")
|
||||
self.git("checkout", "--quiet", "item-1")
|
||||
report = self.bench(**{"--head": "without-test"})
|
||||
self.assertEqual(report.reason, "None of the 4 shipped features on the base's history counts; the lines above say why.")
|
||||
self.assertIn("task-bench: passed over the shipped feature item 7: its change holds no test that the head holds.", self.progress.getvalue().splitlines())
|
||||
|
||||
def test_fails_where_no_shipped_feature_counts(self):
|
||||
# The default branch as it was when item 8 had shipped and no other; the head rewrites the line item 8 wrote.
|
||||
self.git("branch", "--quiet", "--force", "main", "main~4")
|
||||
self.git("branch", "--quiet", "--force", "main", "main~6")
|
||||
report = self.bench()
|
||||
self.assertEqual(report.reason, "None of the 1 shipped features on the base's history counts; the lines above say why.")
|
||||
self.assertIn("task-bench: passed over the shipped feature item 8: its revert doesn't apply at the head.", self.progress.getvalue().splitlines())
|
||||
|
||||
def test_fails_before_docker_runs_where_the_history_shipped_no_item(self):
|
||||
self.git("branch", "--quiet", "--force", "main", "main~6")
|
||||
self.git("branch", "--quiet", "--force", "main", "main~8")
|
||||
report = self.bench()
|
||||
self.assertEqual(report.reason, "No chunk on the base's history took an item out of todo.md, so it holds no shipped feature to rebuild.")
|
||||
self.assertFalse(self.log.exists(), "docker ran")
|
||||
@@ -134,12 +172,13 @@ class ShippedFeatureBenchTest(ShippedFeaturesCase):
|
||||
|
||||
|
||||
class ReadShippedTest(ShippedFeaturesCase):
|
||||
def read(self):
|
||||
return read_shipped(self.home, str(self.repo), "main", functools.partial(git, env=self.env))
|
||||
def read(self, run=git):
|
||||
return read_shipped(self.home, str(self.repo), "main", functools.partial(run, env=self.env))
|
||||
|
||||
def test_reads_the_features_newest_first_with_the_paths_a_revert_leaves_alone(self):
|
||||
shipped = self.read()
|
||||
self.assertEqual([(feature.name, feature.told) for feature in shipped.found], [
|
||||
("item 10", "Keep `Twice` whole."),
|
||||
("item 9", "Say in the README what Calc is."),
|
||||
("item 7", "Add `Halve`, which halves a whole number."),
|
||||
("item 8", "Multiply in `Twice`."),
|
||||
@@ -162,7 +201,20 @@ class ReadShippedTest(ShippedFeaturesCase):
|
||||
self.landed(5, "Plan an item again")
|
||||
self.plan()
|
||||
self.landed(6, "Drop item 8: nobody asked for it")
|
||||
self.assertEqual(self.read().found[0].name, "item 9")
|
||||
self.assertEqual(self.read().found[0].name, "item 10")
|
||||
|
||||
def test_reads_the_checkout_it_is_given_wherever_the_process_runs(self):
|
||||
self.enterContext(contextlib.chdir(self.root))
|
||||
self.assertEqual(len(self.read().found), 4)
|
||||
|
||||
def test_fails_where_git_cannot_read_a_plan(self):
|
||||
def run(*args, **named):
|
||||
return Failure("git broke") if "show" in args[:1] or "cat-file" in args[:1] else git(*args, **named)
|
||||
|
||||
self.assertEqual(self.read(run).reason, "git broke")
|
||||
|
||||
def test_names_a_features_folder_by_its_items(self):
|
||||
self.assertEqual((folder_name("item 7"), folder_name("items 7, 8")), ("item-7", "items-7-8"))
|
||||
|
||||
|
||||
class OptionsTest(unittest.TestCase):
|
||||
|
||||
Reference in New Issue
Block a user