Answer stability round 1: compare medians, refuse unknown options, name the archive read, repair a failed run, and pass the clock and home in from main
This commit is contained in:
@@ -73,8 +73,9 @@ class Figures(unittest.TestCase):
|
||||
def test_rises_only_above_the_five_before_and_needs_ten(self):
|
||||
flat = [Reading(100, collections.Counter({"a.py": 1}))] * 10
|
||||
self.assertEqual(reading_cost.trend(flat[:9]), "9 chunks measured; the trend needs 10.")
|
||||
self.assertTrue(reading_cost.trend(flat).startswith("Not rising: the last 5 chunks read 100 tokens"))
|
||||
self.assertEqual(reading_cost.trend(flat[:5] + [Reading(101, collections.Counter({"b.py": 2}))] * 5), "Rising: the last 5 chunks read 101 tokens on average before their first commit, the 5 before them 100.\n\nRead most over the last 5:\n\n- `b.py` 10")
|
||||
self.assertTrue(reading_cost.trend(flat).startswith("Not rising: the last 5 chunks' median is 100 tokens"))
|
||||
self.assertTrue(reading_cost.trend(flat[:9] + [Reading(3000000, collections.Counter())]).startswith("Not rising:"))
|
||||
self.assertEqual(reading_cost.trend(flat[:5] + [Reading(101, collections.Counter({"b.py": 2}))] * 5), "Rising: the last 5 chunks' median is 101 tokens read before their first commit, the 5 before them 100.\n\nRead most over the last 5:\n\n- `b.py` 10")
|
||||
|
||||
def test_a_figure_reads_back_as_the_reading_it_was_written_from_and_a_damaged_one_fails(self):
|
||||
reading = Reading(7, collections.Counter({"b.py": 1, "a.py": 3}))
|
||||
@@ -120,8 +121,8 @@ class ReadingCostTool(unittest.TestCase):
|
||||
with contextlib.redirect_stderr(io.StringIO()):
|
||||
self.assertIsNone(archive("proj", str(transcript), "Do it.", f"{outcome}\n\nEvidence:\n> merged", at, self.paths))
|
||||
|
||||
def run_tool(self, cwd):
|
||||
return subprocess.run([sys.executable, str(TOOL)], capture_output=True, cwd=cwd, env=self.env, text=True)
|
||||
def run_tool(self, cwd, *args):
|
||||
return subprocess.run([sys.executable, str(TOOL), *args], capture_output=True, cwd=cwd, env=self.env, text=True)
|
||||
|
||||
def test_appends_each_finished_chunk_once_in_the_order_they_finished_from_a_worktree(self):
|
||||
self.archive_chunk(1790000200)
|
||||
@@ -134,15 +135,20 @@ class ReadingCostTool(unittest.TestCase):
|
||||
ran = self.run_tool(worktree)
|
||||
self.assertEqual(ran.returncode, 0, ran.stderr)
|
||||
history = worktree / "docs" / "comprehension-history.md"
|
||||
self.assertEqual(ran.stdout, f"Appended 2 reading-cost figures to {history}.\n2 chunks measured; the trend needs 10.\n")
|
||||
self.assertEqual(ran.stdout, f"Appended 2 reading-cost figures from {self.home / '.claude' / 'loop-claude-transcripts' / 'proj'} to {history}.\n2 chunks measured; the trend needs 10.\n")
|
||||
figure = "## Reading cost, chunk {}, finished {}\n\n33 tokens read before the first commit.\n\nRead most:\n\n- `a.py` 1\n"
|
||||
self.assertEqual(history.read_text(), "# Comprehension history\n\n" + "\n".join(figure.format(chunk.folder[:12], chunk.finished) for chunk in chunks))
|
||||
self.assertTrue(self.run_tool(worktree).stdout.startswith(f"Appended 0 reading-cost figures to {history}."))
|
||||
self.assertTrue(self.run_tool(worktree).stdout.startswith(f"Appended 0 reading-cost figures from"))
|
||||
self.assertEqual(history.read_text().count("## Reading cost"), 2)
|
||||
reset = subprocess.run([sys.executable, str(TOOL), "--reset"], capture_output=True, cwd=worktree, env=self.env, text=True)
|
||||
self.assertEqual(reset.stdout, f"Appended 0 reading-cost figures and a reset to {history}.\n0 chunks measured; the trend needs 10.\n")
|
||||
reset = self.run_tool(worktree, "--reset")
|
||||
self.assertEqual(reset.stdout, f"Appended 0 reading-cost figures from {self.home / '.claude' / 'loop-claude-transcripts' / 'proj'} and a reset to {history}.\n0 chunks measured; the trend needs 10.\n")
|
||||
self.assertRegex(history.read_text(), r"\n## Reading cost reset, \d{4}-\d\d-\d\dT\d\d:\d\d:\d\dZ\n$")
|
||||
|
||||
def test_refuses_an_option_it_does_not_know(self):
|
||||
ran = self.run_tool(self.checkout, "--rest")
|
||||
self.assertEqual((ran.returncode, ran.stdout), (1, ""))
|
||||
self.assertFalse((self.checkout / "--rest").exists())
|
||||
|
||||
def test_exits_1_outside_a_checkout(self):
|
||||
ran = self.run_tool(self.home)
|
||||
self.assertEqual(ran.returncode, 1)
|
||||
|
||||
Reference in New Issue
Block a user