Test the digest's cuts, the median pick and gather's refusals, and drop project_rung's checkout parameter

This commit is contained in:
2026-11-21 04:24:52 +01:00
parent 7a568f80af
commit b474ec2f5a
6 changed files with 48 additions and 15 deletions
+15 -1
View File
@@ -49,6 +49,13 @@ class TraceTest(unittest.TestCase):
def test_a_shell_command_shows_its_first_line_cut_short(self):
self.assertEqual(trace(stream(call("Bash", command="go test ./...\necho done"))), ["Bash go test ./... …"])
self.assertEqual(trace(stream(call("Bash", command="x" * 200))), [f"Bash {'x' * 120} …"])
self.assertEqual(trace(stream(call("Bash", command="x" * 200 + "\nls"))), [f"Bash {'x' * 120} …"])
self.assertEqual(trace(stream(call("Bash", command="x" * 120 + "\nls"))), [f"Bash {'x' * 120} …"])
self.assertEqual(trace(stream(call("Bash", command="x" * 120))), [f"Bash {'x' * 120}"])
self.assertEqual(trace(stream(call("Bash", command="ls"), result("1", "a.go\nb.go"))), ["Bash ls"])
def test_a_call_without_its_pattern_or_command_shows_none(self):
self.assertEqual(trace(stream(call("Grep"), call("Bash", "2"))), ['Grep ""', "Bash "])
def test_any_other_tool_shows_its_name_and_the_file_it_names(self):
self.assertEqual(trace(stream(call("Edit", file_path="/work/pick.go", old_string="a", new_string="b"), call("TodoWrite", "2", todos=[]))), ["Edit pick.go", "TodoWrite"])
@@ -61,6 +68,9 @@ class TraceTest(unittest.TestCase):
told = stream(said("The test fails in Add.\n\nI will read it.\nThen the caller.\nThen fix it."), call("Read", file_path="/work/calc.go"), said("Found it."))
self.assertEqual(trace(told), ["> The test fails in Add.", "> I will read it.", "> Then the caller. …", "Read calc.go", "> Found it."])
self.assertEqual(trace(stream(said("y" * 300))), [f"> {'y' * 200} …"])
self.assertEqual(trace(stream(said("one\ntwo\nthree"))), ["> one", "> two", "> three"])
self.assertEqual(trace(stream(said(f"one\n{'y' * 300}\nthree\nfour"))), ["> one", f"> {'y' * 200} …", "> three …"])
self.assertEqual(trace(stream(said(f"one\ntwo\n{'y' * 300}\nfour"))), ["> one", "> two", f"> {'y' * 200} …"])
def test_a_stream_without_a_call_or_text_has_no_trace(self):
self.assertEqual(trace(b'{"type": "system", "subtype": "init"}\nnot json\n'), [])
@@ -127,9 +137,13 @@ class DigestTest(unittest.TestCase):
self.assertNotIn("failing run that", held)
self.assertIn("### bug-2-base-1, the passing run with the median tokens, 10", held.splitlines())
def test_the_median_is_by_tokens_whatever_the_order_the_runs_ran_in(self):
runs = [Run("bug-2-base-1", True, 30, b""), Run("bug-2-head-1", True, 10, b""), Run("bug-2-base-2", True, 20, b"")]
self.assertEqual(digest([], [Bug("2: a.go:1:1 X", "a.go", "boom", runs)], lambda path: True).splitlines()[-2:], ["### bug-2-base-2, the passing run with the median tokens, 20", ""])
def test_a_bug_no_run_fixed_shows_the_failing_trace_alone_and_says_where_no_file_misled(self):
held = digest([], [Bug("3: a.go:1:1 X", "a.go", "boom\nat line 2", [Run("bug-3-base-1", False, 10, reading("a.go")), Run("bug-3-head-1", False, 10, reading("a.go"))])], lambda path: True)
self.assertIn("0 of the 2 runs passed. No decoys: no file but the one the fix changes was read by more than half the 2 failing runs.", held.splitlines())
self.assertEqual(held.splitlines()[10:14], ["0 of the 2 runs passed. No decoys: no file but the one the fix changes was read by more than half the 2 failing runs.", "", "### bug-3-base-1, the failing run that spent the most tokens, 10", ""])
self.assertIn(" at line 2", held.splitlines())
# Of two failing runs that spent the same, the first.
self.assertIn("### bug-3-base-1, the failing run that spent the most tokens, 10", held.splitlines())