Answer stability round 1: 0 🔴, 10 🟡 (0 misread); take the failed test's last message, fail on a docker run that never started, keep testdata as planted, show finished runs when the API refuses one, and test five survivors

This commit is contained in:
2026-11-21 02:41:36 +01:00
parent 1e96a397af
commit 8c1edf552a
9 changed files with 275 additions and 112 deletions
+31 -17
View File
@@ -28,13 +28,15 @@ MUTATIONS: dict[str, dict[bytes, bytes]] = {
"REMOVE_SELF_ASSIGNMENTS": dict.fromkeys((b"+=", b"&=", b"&^=", b"*=", b"|=", b"/=", b"%=", b"<<=", b">>=", b"-=", b"^="), b"="),
}
HUNK = re.compile(r"^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@", re.MULTILINE)
# go test's report of a failed assertion: ` pick_test.go:42: got 3, want 4`, under the `--- FAIL: TestPick (0.00s)` of its test.
ASSERTION = re.compile(r"^( *)\S*_test\.go:\d+:(.*)$")
# What a test printed, as go test shows it: ` pick_test.go:42: got 3, want 4`. A failed assertion and a log line look the same.
PRINTED = re.compile(r"^( *)\S*_test\.go:\d+:(.*)$")
# The lines that say whose output follows: `=== RUN TestPick` with -v, and `--- FAIL: TestPick (0.00s)` with and without it.
TEST_MARK = re.compile(r"^( *)(?:=== (?:RUN|CONT|NAME)|--- (?:FAIL|PASS|SKIP):)\s+(\S+)")
FAILED_TEST = re.compile(r"^\s*--- FAIL: (\S+)", re.MULTILINE)
class Mutant(typing.NamedTuple):
"""A mutant Gremlins' tests killed: the mutator and the token it changed, by its line and its column in bytes, both from 1."""
"""A mutant the project's tests killed, as Gremlins reports it: the mutator and the token it changed, by its line and its column in bytes, both from 1."""
path: str
line: int
@@ -90,7 +92,7 @@ def line_at_head(diff: str, line: int) -> int | None:
diff is `git diff -U0 <base> <head> -- <file>`, so each hunk holds changed lines only."""
moved = 0
for old_start, old_count, new_start, new_count in ((int(a), int(b or 1), int(c), int(d or 1)) for a, b, c, d in HUNK.findall(diff)):
# A hunk that only adds names the line it adds after, and one that only removes the line the gap is after.
# A hunk that only adds lines names the line it adds them after. One that only removes lines names the line the gap follows.
old_end = old_start + old_count if old_count else old_start + 1
new_end = new_start + new_count if new_count else new_start + 1
if old_count and old_start <= line < old_end:
@@ -101,19 +103,31 @@ def line_at_head(diff: str, line: int) -> int | None:
def task_text(output: str) -> str | None:
"""What Haiku is told of a planted bug: the message of the first assertion that failed in go test's output, without the test's
name, file or line, so it says what goes wrong and not where. None where no assertion failed, as on a panic, a build that
broke or a passing run, or where its message says nothing beyond the test."""
"""What Haiku is told of a planted bug: the failing assertion's message in go test's output, without the test's name, file or
line, so it says what goes wrong and not where. That is the last message of the first failed test that printed one, since a
test logs before it asserts. None where no failed test printed a message, as on a panic, a build that broke or a passing run,
or where the message only names the test."""
lines = output.splitlines()
failed = set(FAILED_TEST.findall(output))
# A subtest is named `TestPick/empty_input`; a message may name the whole or the test it belongs to.
tests = {part for name in FAILED_TEST.findall(output) for part in (name, name.partition("/")[0])}
tests = {part for name in failed for part in (name, name.partition("/")[0])}
marks: list[tuple[int, str]] = []
last: dict[str, tuple[int, re.Match[str]]] = {}
for index, line in enumerate(lines):
if found := ASSERTION.match(line):
indent = len(found[1])
# A message's later lines are indented deeper than its first.
later = lines[index + 1:]
ends = next((at for at, text in enumerate(later) if len(text) - len(text.lstrip(" ")) <= indent), len(later))
message = [text.strip() for text in (found[2], *later[:ends])]
kept = [text for text in message if text and "_test.go" not in text and not any(test in text for test in tests)]
return "\n".join(kept) or None
return None
if mark := TEST_MARK.match(line):
marks.append((len(mark[1]), mark[2]))
elif printed := PRINTED.match(line):
# A test's output is indented deeper than its mark, so a line after a subtest's may be its parent's.
test = next((name for indent, name in reversed(marks) if indent < len(printed[1])), None)
if test is not None and test in failed:
last[test] = index, printed
if not last:
return None
index, found = next(iter(last.values()))
indent = len(found[1])
# A message's later lines are indented deeper than its first.
later = lines[index + 1:]
ends = next((at for at, text in enumerate(later) if len(text) - len(text.lstrip(" ")) <= indent), len(later))
message = [text.strip() for text in (found[2], *later[:ends])]
kept = [text for text in message if text and "_test.go" not in text and not any(name in text for name in tests)]
return "\n".join(kept) or None