Answer architecture round 2: split reading_cost's main, reset the trend when the reading-cost item ships, order figures by finish time, share the archive's stamp format
This commit is contained in:
@@ -12,7 +12,7 @@ import unittest
|
||||
|
||||
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent))
|
||||
|
||||
from loop_claude.transcript_archive import archive, FINISHED, finished_chunks, FinishedChunk, UNFINISHED
|
||||
from loop_claude.transcript_archive import archive, FINISHED, FINISHED_AT, finished_chunks, FinishedChunk, UNFINISHED, utc
|
||||
from reading_cost import Checkout, Reading
|
||||
from failure import Failure
|
||||
from test_loop_claude_black_box import host_env
|
||||
@@ -41,6 +41,9 @@ class ShellReads(unittest.TestCase):
|
||||
command = "cd ../w && sed -n 1,5p src/a.py | grep -n x\ngrep -rn 'def x' bin/t.py > out.txt\npython3 - <<'EOF'\ncat secret.py\nEOF\ncat ~/README.md\nsed -i s/a/b/ c.py"
|
||||
self.assertEqual(shell_reads(command, "/c/p", "/h"), Reads(["/c/w/src/a.py", "/c/w/bin/t.py", "/h/README.md"], []))
|
||||
|
||||
def test_ends_a_dashed_heredoc_at_its_marker(self):
|
||||
self.assertEqual(shell_reads("cat <<-EOF > x.md\ncat secret.py\nEOF\ncat a.py", "/c/p", "/h"), Reads(["/c/p/a.py"], []))
|
||||
|
||||
def test_names_the_worktree_a_git_worktree_add_makes(self):
|
||||
self.assertEqual(shell_reads("git worktree add -q -b topic ../p-topic origin/main", "/c/p", "/h"), Reads([], ["/c/p-topic"]))
|
||||
|
||||
@@ -81,6 +84,16 @@ class Figures(unittest.TestCase):
|
||||
self.assertEqual(reading_cost.readings_of(written.replace("7 tokens", "seven tokens")), Failure('the figure under "## Reading cost, chunk abcdef012345, finished t" holds no single tokens line; restore it from git history'))
|
||||
|
||||
|
||||
def test_counts_only_figures_finished_after_the_last_reset_in_the_order_they_finished(self):
|
||||
def written(chunk, finished, tokens):
|
||||
return reading_cost.figure(FinishedChunk(chunk, finished, pathlib.Path(), []), Reading(tokens, collections.Counter()))
|
||||
history = "\n".join([written("a", "2026-10-01T00:00:00Z", 1), written("c", "2026-10-03T00:00:00Z", 3), "## Reading cost reset, 2026-10-02T00:00:00Z\n", written("b", "2026-10-04T00:00:00Z", 2)])
|
||||
self.assertEqual(reading_cost.readings_of(history), [Reading(3, collections.Counter()), Reading(2, collections.Counter())])
|
||||
|
||||
def test_the_archive_stamps_what_it_reads_back(self):
|
||||
self.assertRegex(f"{utc(1790000000)} {FINISHED}", FINISHED_AT)
|
||||
|
||||
|
||||
class ReadingCostTool(unittest.TestCase):
|
||||
def setUp(self):
|
||||
temp = tempfile.TemporaryDirectory()
|
||||
@@ -126,6 +139,9 @@ class ReadingCostTool(unittest.TestCase):
|
||||
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.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")
|
||||
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_exits_1_outside_a_checkout(self):
|
||||
ran = self.run_tool(self.home)
|
||||
|
||||
Reference in New Issue
Block a user