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:
@@ -14,11 +14,14 @@ import unittest
|
||||
|
||||
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 task_bench.feature_tasks import features
|
||||
from task_bench.feature_tasks import Feature, features, why_passed_over
|
||||
from test_env import isolated_env
|
||||
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"))
|
||||
# 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)
|
||||
|
||||
|
||||
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):
|
||||
def setUp(self):
|
||||
folder = tempfile.TemporaryDirectory()
|
||||
@@ -92,6 +100,8 @@ class FeatureBenchTest(unittest.TestCase):
|
||||
self.git("init", "--quiet", "--initial-branch", "main")
|
||||
for name, text in (("calc.go", BASE_CODE), ("calc_test.go", TESTS), ("README.md", "# Calc\n")):
|
||||
(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")
|
||||
self.base = self.commit("Base")
|
||||
self.git("checkout", "--quiet", "-b", "item-1")
|
||||
@@ -109,7 +119,7 @@ class FeatureBenchTest(unittest.TestCase):
|
||||
|
||||
def bench(self, **given: str):
|
||||
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):
|
||||
# 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())
|
||||
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.
|
||||
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())
|
||||
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))
|
||||
@@ -182,10 +192,33 @@ class FeatureBenchTest(unittest.TestCase):
|
||||
self.assertNotIsInstance(report, Failure, 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):
|
||||
(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")
|
||||
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())])
|
||||
|
||||
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"])
|
||||
|
||||
|
||||
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):
|
||||
def options(self, *argv: str):
|
||||
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):
|
||||
for option in ("--seed", "--bugs", "--prefix"):
|
||||
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"))
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user