Answer review: keep Rust test modules for bugs only, order imports, reword
CI / tests (pull_request) Has been cancelled
CI / tests (pull_request) Has been cancelled
This commit is contained in:
@@ -30,8 +30,11 @@ No model judges anything: the bench runs programs, and reads Haiku's own stream.
|
||||
reaches api.anthropic.com and nothing else. A fix ends after 30 minutes.
|
||||
- Check. The test command runs over the planted tree with each file that is no test as Haiku left it; a fix passes where it exits 0.
|
||||
A test Haiku changed, removed or added doesn't count, and neither does a file under a `testdata` folder. In a Rust file, each
|
||||
inline `#[cfg(test)]` module stands as the planted file has it, and the rest is as Haiku left it. A Rust mutant is passed over
|
||||
where its file's modules cannot be told apart, as where two share a name or a brace, string or comment is never closed.
|
||||
inline `#[cfg(test)]` module stands as the planted file has it, and the rest is as Haiku left it. Where Haiku's file lacks one of
|
||||
those modules, or its modules cannot be told apart, the planted file stands whole; where the planted file's cannot be told apart,
|
||||
Haiku's stands. A Rust mutant whose file's modules cannot be told apart, as where two share a name or a brace, string or comment
|
||||
is never closed, is passed over. A Rust test in a file of its own, as `#[cfg(test)] mod tests;` names, counts, since the bench
|
||||
tells no such file from code.
|
||||
|
||||
--image is the project's development image, such as golang:1.27.4. The bench adds Claude Code to it, as its installer installs it,
|
||||
so the image needs curl and bash; the result names the version. Haiku works in that image. So does --test: sh runs that text at
|
||||
@@ -68,7 +71,8 @@ project's config names as `bench-tasks`, in the order of their names. Each holds
|
||||
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
|
||||
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
|
||||
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
|
||||
side's tree with each file that is no test as Haiku left it, a Rust file's test modules included, 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. No mutation tool
|
||||
@@ -174,7 +178,6 @@ import uuid
|
||||
|
||||
from task_bench.tasks import Asked, Bench, BUG, check_made, committed, Kind, KINDS, on_disk, Planned, SHIPPED, Task, tests_in_copy
|
||||
from task_bench.planted_mutant import bug_at_sides, Mutant
|
||||
from task_bench.rust_test_modules import tells_apart
|
||||
from claude_code.reply import Claude
|
||||
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
|
||||
@@ -194,6 +197,7 @@ from larv_review.history_commands import read_places
|
||||
from task_bench.shipped_features import read_shipped, shipped_tasks, ShippedFeatures
|
||||
from task_bench.record_figures import recorded_bench
|
||||
from run_heavy.capped_docker import SHARE_VARIABLE
|
||||
from task_bench.rust_test_modules import tells_apart
|
||||
|
||||
USAGE = "usage: task-bench --image <image> --test <shell text> [--base <ref>] [--head <ref>] [--prefix <shell text>] [--seed <n>] [--bugs <n>] [--runs <n>] [--record-figures], or task-bench --tasks features|data-sources --image <image> --test <shell text> [--base <ref>] [--head <ref>] [--runs <n>] [--record-figures], or task-bench --tasks shipped-features --image <image> --test <shell text> [--base <ref>] [--head <ref>] [--shipped <n>] [--runs <n>] [--record-figures], or task-bench gather"
|
||||
# A panel of three readers, seated as the README's audience, picked these options on 2026-11-21, each 3 to 0.
|
||||
|
||||
+10
-9
@@ -11,8 +11,8 @@ import typing
|
||||
from mutate_changes.tool_process import failed, Ran
|
||||
from failure import Failure
|
||||
from mutate_changes.changed_lines import is_test
|
||||
from task_bench.rust_test_modules import with_tests_of
|
||||
from task_bench.api_proxy import PORT
|
||||
from task_bench.rust_test_modules import with_tests_of
|
||||
|
||||
MODEL = "claude-haiku-5-5"
|
||||
# Where each run's container mounts its copy of the code, and its home folder: the paths in a run's stream start there.
|
||||
@@ -164,10 +164,11 @@ def in_tree(containers: Containers, tree: str) -> list[str]:
|
||||
return [*containers.limits(), "--user", containers.user, "--env", f"HOME={HOME}", "--volume", f"{tree}:{WORK}", "--workdir", WORK]
|
||||
|
||||
|
||||
def checked_tree(planted: str, copy: str, into: str) -> None:
|
||||
def checked_tree(planted: str, copy: str, into: str, rust_tests_planted: bool = True) -> None:
|
||||
"""Makes at `into` the tree the tests check a fix in: `planted`, the code with the bug as Haiku got it, with each file that is no
|
||||
test as `copy` holds it after the fix. So a test Haiku changed, removed or added doesn't count, and neither does a file under
|
||||
a `testdata` folder, where Go's tests keep the output they expect. A Rust file's `#[cfg(test)]` modules are the planted file's.
|
||||
a `testdata` folder, where Go's tests keep the output they expect. Where rust_tests_planted, a Rust file's inline `#[cfg(test)]`
|
||||
modules stand as the planted file has them too, as `with_tests_of` says.
|
||||
|
||||
Raises OSError where a file cannot be copied."""
|
||||
shutil.copytree(planted, into, symlinks=True)
|
||||
@@ -185,19 +186,19 @@ def checked_tree(planted: str, copy: str, into: str) -> None:
|
||||
with contextlib.suppress(FileNotFoundError):
|
||||
os.unlink(target)
|
||||
shutil.copy2(os.path.join(copy, path), target, follow_symlinks=False)
|
||||
if path.endswith(".rs"):
|
||||
if rust_tests_planted and path.endswith(".rs"):
|
||||
keep_rust_tests(os.path.join(planted, path), target)
|
||||
|
||||
|
||||
def keep_rust_tests(planted_file: str, target: str) -> None:
|
||||
"""Puts into the Rust file at target, a copy of Haiku's, the test modules of planted_file; see `with_tests_of`. A file the planted
|
||||
tree lacks, as a link or as a file, is left as it is, since it has no test to keep.
|
||||
"""Puts into the Rust file at target, a copy of Haiku's, the test modules of planted_file, as `with_tests_of` says. A planted tree
|
||||
without the file has no test module, so a file Haiku added keeps none. A link, planted's or Haiku's, is left as it is.
|
||||
|
||||
Raises OSError where a file cannot be read or written."""
|
||||
if os.path.islink(planted_file) or os.path.islink(target) or not os.path.isfile(planted_file):
|
||||
if os.path.islink(planted_file) or os.path.islink(target):
|
||||
return
|
||||
planted, copied = (pathlib.Path(file).read_bytes() for file in (planted_file, target))
|
||||
pathlib.Path(target).write_bytes(with_tests_of(planted, copied))
|
||||
planted = pathlib.Path(planted_file).read_bytes() if os.path.isfile(planted_file) else b""
|
||||
pathlib.Path(target).write_bytes(with_tests_of(planted, pathlib.Path(target).read_bytes()))
|
||||
|
||||
|
||||
def of_tests(path: str) -> bool:
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
"""The `#[cfg(test)]` modules of a Rust file, which stand in the file of the code they test: where each is, and a file with the modules
|
||||
of another file put in place of its own. A file is bytes, since a Rust file is UTF-8 and a module is found by ASCII text alone."""
|
||||
"""The `#[cfg(test)]` modules of a Rust file, which stand in the file of the code they test. Here are where each is, and a file with
|
||||
the modules of another file put in place of its own. A file is bytes: a Rust file is UTF-8, and a module is found by ASCII text alone."""
|
||||
import re
|
||||
|
||||
# What the scan steps over or stops at. A string, a char and a comment may hold a brace.
|
||||
@@ -15,19 +15,19 @@ SCAN = re.compile(
|
||||
)
|
||||
STRING_BODY = re.compile(rb'(?:[^"\\]|\\.)*"', re.DOTALL)
|
||||
COMMENT_EDGE = re.compile(rb"/\*|\*/")
|
||||
# What must follow the attribute for it to start an inline module: other attributes, a visibility, then `mod name {`.
|
||||
# What follows the attribute that starts an inline module: any other attributes, an optional visibility, then `mod name {`.
|
||||
MODULE = re.compile(rb"\s*(?:#\[[^\]]*\]\s*)*(?:pub(?:\([^)]*\))?\s+)?mod\s+(?P<name>\w+)\s*\{")
|
||||
|
||||
|
||||
def tells_apart(path: str, source: bytes) -> bool:
|
||||
"""Whether source, the file at path, is no Rust file or has test modules that `modules` tells apart."""
|
||||
"""Whether source, the file at path, is no Rust file, or holds test modules that `modules` can tell apart."""
|
||||
return not path.endswith(".rs") or modules(source) is not None
|
||||
|
||||
|
||||
def modules(source: bytes) -> dict[bytes, tuple[int, int]] | None:
|
||||
"""Each inline `#[cfg(test)] mod name { ... }` of source by its name, as the offsets from its attribute to its closing brace. A
|
||||
module inside a test module is not listed. None where the modules cannot be told apart: two hold one name, or a brace, string or
|
||||
comment is never closed. A `#[cfg(test)]` on anything but an inline module is not listed."""
|
||||
"""Each inline `#[cfg(test)] mod name { ... }` of source by its name, with the offsets of its first byte, the attribute's, and of the
|
||||
byte after its closing brace. A module inside a test module and a `#[cfg(test)]` on anything but an inline module are not listed.
|
||||
None where the modules cannot be told apart: two share a name, or a brace, string or comment is never closed."""
|
||||
found: dict[bytes, tuple[int, int]] = {}
|
||||
depth = 0
|
||||
# The module being read: its name, the offset of its attribute and the depth outside it.
|
||||
@@ -71,14 +71,15 @@ def after_string(source: bytes, position: int) -> int | None:
|
||||
|
||||
|
||||
def after_raw_string(source: bytes, position: int, hashes: bytes) -> int | None:
|
||||
"""The offset after the raw string, opened by `r`, hashes and a quote, that ends at position, None where it is never closed. It has no escapes."""
|
||||
"""The offset after the raw string, `r` or `br` then hashes and a quote, whose opening ends at position, None where it is never closed.
|
||||
It has no escapes."""
|
||||
closed = re.compile(b'"' + hashes).search(source, position)
|
||||
return closed.end() if closed else None
|
||||
|
||||
|
||||
def with_tests_of(planted: bytes, copy: bytes) -> bytes:
|
||||
"""copy with each test module as planted holds it, and each test module planted lacks left out. So a test a fix changed, removed
|
||||
or added doesn't count.
|
||||
"""copy with each of its test modules replaced by the one of that name in planted, and each that planted lacks left out. So a test a
|
||||
fix changed, removed or added doesn't count.
|
||||
|
||||
Where planted's modules cannot be told apart, copy is returned as it is. Where copy's cannot, or copy lacks one of planted's,
|
||||
planted is returned: Haiku's file has no module to put them in."""
|
||||
|
||||
@@ -114,10 +114,11 @@ def tests_in_copy(containers: Containers, tree: str, folder: pathlib.Path) -> Ra
|
||||
|
||||
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.
|
||||
tests over it, where acceptance names their folder. A run of Haiku's and a feature's reference patch are checked alike. Only a
|
||||
task without acceptance tests has its Rust test modules kept as the tree has them: a feature's change may update such a module.
|
||||
|
||||
Raises OSError where a file cannot be copied."""
|
||||
checked_tree(tree, copy, check)
|
||||
checked_tree(tree, copy, check, rust_tests_planted=not acceptance)
|
||||
if acceptance:
|
||||
with_acceptance(check, acceptance)
|
||||
|
||||
|
||||
@@ -43,21 +43,21 @@ class ModulesTest(unittest.TestCase):
|
||||
def test_holds_each_test_module_from_its_attribute_to_its_closing_brace(self):
|
||||
self.assertEqual(spelt(LIB), {"tests": LIB[LIB.index("#[cfg(test)]"):LIB.rindex("}") + 1]})
|
||||
|
||||
def test_holds_none_where_the_file_has_no_test_module(self):
|
||||
def test_lists_no_module_where_the_file_has_no_test_module(self):
|
||||
self.assertEqual(modules("fn main() {}\n"), {})
|
||||
|
||||
def test_takes_a_module_with_a_visibility_and_another_attribute(self):
|
||||
source = "#[cfg(test)]\n#[allow(dead_code)]\npub(crate) mod checks {\n}\nfn after() {}\n"
|
||||
self.assertEqual(spelt(source), {"checks": source[:source.index("}") + 1]})
|
||||
|
||||
def test_leaves_out_what_the_attribute_is_not_on_an_inline_module(self):
|
||||
def test_lists_no_module_where_the_attribute_is_on_anything_but_an_inline_module(self):
|
||||
self.assertEqual(modules("#[cfg(test)]\nmod tests;\n#[cfg(test)]\nuse std::fmt;\n#[cfg(test)]\nfn helper() {}\n"), {})
|
||||
|
||||
def test_leaves_out_a_module_inside_a_module(self):
|
||||
def test_lists_no_module_inside_a_test_module(self):
|
||||
source = "#[cfg(test)]\nmod outer {\n #[cfg(test)]\n mod inner {}\n}\n"
|
||||
self.assertEqual(list(spelt(source)), ["outer"])
|
||||
|
||||
def test_reads_past_a_brace_in_a_string_a_char_or_a_comment(self):
|
||||
def test_reads_past_a_brace_in_a_string_a_char_a_comment_or_an_escape(self):
|
||||
source = textwrap.dedent("""\
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
@@ -87,7 +87,7 @@ class ModulesTest(unittest.TestCase):
|
||||
source = "#[cfg(test)]\nmod tests {\n const A: &str = " + literal + ";\n}\nfn after() {}\n"
|
||||
self.assertEqual(list(spelt(source)), ["tests"])
|
||||
|
||||
def test_leaves_out_a_module_a_comment_or_a_char_stands_before(self):
|
||||
def test_lists_no_plain_module_that_follows_a_comment_or_a_char(self):
|
||||
self.assertEqual(modules("// helpers\nmod util {}\nfn a() { let c = 'x'; }\nmod more {}\n"), {})
|
||||
|
||||
def test_lists_a_test_module_inside_a_module_that_is_no_test(self):
|
||||
@@ -104,7 +104,7 @@ class ModulesTest(unittest.TestCase):
|
||||
|
||||
|
||||
class TellsApartTest(unittest.TestCase):
|
||||
def test_tells_a_rust_file_apart_where_its_modules_can_be(self):
|
||||
def test_tells_the_modules_of_a_rust_file_apart_where_they_can_be(self):
|
||||
self.assertEqual([tells_apart("lib.rs", b"fn a() {}"), tells_apart("lib.rs", b"fn a() {")], [True, False])
|
||||
|
||||
def test_takes_a_file_of_another_language_whatever_it_holds(self):
|
||||
@@ -132,7 +132,7 @@ class WithTestsOfTest(unittest.TestCase):
|
||||
fixed = "fn a() { 2 }\n#[cfg(test)]\nmod y { fn changed() {} }\n#[cfg(test)]\nmod x { fn changed() {} }\nfn c() {}\n"
|
||||
self.assertEqual(with_tests_of(planted, fixed), "fn a() { 2 }\n#[cfg(test)]\nmod y { fn u() {} }\n#[cfg(test)]\nmod x { fn t() {} }\nfn c() {}\n")
|
||||
|
||||
def test_puts_the_planted_modules_in_where_their_names_sort_in_file_order(self):
|
||||
def test_puts_in_planted_modules_whose_length_differs_from_the_fixed_ones(self):
|
||||
planted = "#[cfg(test)]\nmod a { 1 }\n#[cfg(test)]\nmod b { 22 }\nfn code() {}\n"
|
||||
fixed = "#[cfg(test)]\nmod a { 333 }\n#[cfg(test)]\nmod b { 4444444 }\nfn fixed() {}\n"
|
||||
self.assertEqual(with_tests_of(planted, fixed), "#[cfg(test)]\nmod a { 1 }\n#[cfg(test)]\nmod b { 22 }\nfn fixed() {}\n")
|
||||
|
||||
@@ -727,7 +727,7 @@ class CheckedTreeTest(unittest.TestCase):
|
||||
planted = self.tree("planted", {"src/lib.rs": "fn a() { 1 }\n#[cfg(test)]\nmod tests { fn t() { a() } }\n", "src/other.rs": "fn b() { 1 }\n"})
|
||||
copy = self.tree("copy", {"src/lib.rs": "fn a() { 2 }\n#[cfg(test)]\nmod tests {}\n", "src/other.rs": "fn b() { 2 }\n", "src/new.rs": "#[cfg(test)]\nmod mine {}\nfn c() {}\n"})
|
||||
checked_tree(planted, copy, str(self.root / "check"))
|
||||
self.assertEqual(self.held("check"), {"src/lib.rs": "fn a() { 2 }\n#[cfg(test)]\nmod tests { fn t() { a() } }\n", "src/other.rs": "fn b() { 2 }\n", "src/new.rs": "#[cfg(test)]\nmod mine {}\nfn c() {}\n"})
|
||||
self.assertEqual(self.held("check"), {"src/lib.rs": "fn a() { 2 }\n#[cfg(test)]\nmod tests { fn t() { a() } }\n", "src/other.rs": "fn b() { 2 }\n", "src/new.rs": "\nfn c() {}\n"})
|
||||
|
||||
def test_takes_the_planted_rust_file_where_the_fix_deleted_its_test_module(self):
|
||||
planted = self.tree("planted", {"src/lib.rs": "fn a() { 1 }\n#[cfg(test)]\nmod tests { fn t() {} }\n"})
|
||||
@@ -742,6 +742,15 @@ class CheckedTreeTest(unittest.TestCase):
|
||||
checked_tree(planted, copy, str(self.root / "check"))
|
||||
self.assertEqual((os.readlink(self.root / "check/z.rs"), self.held("check")["a.txt"]), ("a.txt", "text"))
|
||||
|
||||
def test_a_task_with_acceptance_tests_takes_its_rust_test_modules_as_fixed(self):
|
||||
planted = self.tree("planted", {"lib.rs": "fn a() { 1 }\n#[cfg(test)]\nmod tests { fn old() {} }\n"})
|
||||
copy = self.tree("copy", {"lib.rs": "fn a() { 2 }\n#[cfg(test)]\nmod tests { fn new() {} }\n"})
|
||||
acceptance = self.tree("acceptance", {"tests/feature.rs": "accepts"})
|
||||
main.check_made(planted, copy, str(self.root / "kept"), None)
|
||||
main.check_made(planted, copy, str(self.root / "check"), acceptance)
|
||||
self.assertEqual(self.held("kept"), {"lib.rs": "fn a() { 2 }\n#[cfg(test)]\nmod tests { fn old() {} }\n"})
|
||||
self.assertEqual(self.held("check"), {"lib.rs": "fn a() { 2 }\n#[cfg(test)]\nmod tests { fn new() {} }\n", "tests/feature.rs": "accepts"})
|
||||
|
||||
def test_copies_a_link_as_a_link(self):
|
||||
planted = self.tree("planted", {"calc.go": "bug"})
|
||||
copy = self.tree("copy", {"calc.go": "fixed"})
|
||||
|
||||
Reference in New Issue
Block a user