import pathlib import re import sys import unittest sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[2])) from loop_claude.chunk import chunk_items from claude_code import entries from failure import Failure from loop_claude.chunk import fresh_prompt from plan_store.todo_md import plan_of from model_routing.route import Route from model_routing.ladder import Rung from loop_effects.doubles import said from agent_cycle.verdicts import TakenIn # Item 297 scores the higher L, item 298 the higher E + I. SCORED = "## Items\n\n| ID | Release | Exempt | Item | L | E | I | R | S | Moves | Score |\n|---|---|---|---|---|---|---|---|---|---|---|\n| 297 | 0.8.0 | | **Do it.** | 4 | 2 | 3 | 7 | 2 | 1 by 9 | 25 |\n| 298 | 0.8.0 | | **Do more.** | 3 | 3 | 4 | 8 | 2 | 1 by 9 | 20 |\n" class ChunkItems(unittest.TestCase): def test_names_the_items_on_the_workers_latest_chunk_items_line(self): earlier = said("Chunk items: 297 (L 3, E + I 5)") latest = said("Starting.\n**Chunk items:** 297 (L 4, E + I 5), item 298 (L 3, E + I 7), #12, 298\nOn to the tests.") self.assertEqual(chunk_items.named([earlier, latest]), (297, 298, 12)) self.assertEqual(chunk_items.named([latest, earlier]), (297,)) self.assertEqual(chunk_items.named([earlier, said("Chunk items: none")]), ()) self.assertEqual(chunk_items.named([said("Chunk items: 297 and 298 (L 3, E + I 7)")]), (297, 298)) def test_reads_the_example_line_the_prompt_gives_the_worker(self): example = re.search(r"`(Chunk items:[^`]*)`", fresh_prompt.NAME_THE_ITEMS)[1] self.assertEqual(chunk_items.named([said(example)]), (297, 298)) def test_every_prompt_that_starts_or_resumes_a_chunk_asks_for_the_line(self): self.assertIn("on one line, as in `Chunk items: ", fresh_prompt.WORKER.resumed("", Route(Rung("m")), None)) def test_reads_only_a_line_the_worker_opens_with_the_label_in_its_own_text(self): prompt = entries.LoopPrompt(text="Chunk items: 297 (L 3, E + I 5)") written = entries.AssistantTurn(parts=(entries.ToolCall("t", "Write", {"content": "Chunk items: 9"}),)) mentioned = said("Once I know them, I write `Chunk items: 5`.") self.assertEqual(chunk_items.named([prompt, written, mentioned]), ()) def test_takes_the_highest_l_and_e_plus_i_todo_md_scores_among_the_named_items(self): self.assertEqual(chunk_items.taken_in([said("Chunk items: 297 (L 1, E + I 2), 298, 400")], plan_of(SCORED)), TakenIn(4, 7)) self.assertEqual(chunk_items.taken_in([said("Chunk items: 400")], plan_of(SCORED)), TakenIn()) self.assertEqual(chunk_items.taken_in([], plan_of(SCORED)), TakenIn()) def test_names_the_items_at_no_level_where_todo_md_cannot_be_read(self): self.assertEqual(chunk_items.taken_in([said("Chunk items: 297")], Failure("no todo.md")), TakenIn()) self.assertEqual(chunk_items.taken_in([said("Chunk items: 297")], plan_of("no items table")), TakenIn()) if __name__ == "__main__": unittest.main()