From 86dbd03501f2cbfce2d7fe9f1d0c691f97bd6140 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Wed, 18 Nov 2026 16:35:03 +0100 Subject: [PATCH] =?UTF-8?q?Answer=20stability=20round=201:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=203=20=F0=9F=9F=A1=20(0=20misread);=20move=20the?= =?UTF-8?q?=20parser's=20tests=20beside=20it,=20index=20it=20in=20README,?= =?UTF-8?q?=20fix=20the=20claims=20about=20chunk-preflight?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- bin/plan/test_touches.py | 167 ++++++++++++++++++ bin/todo_item/main.py | 8 +- bin/todo_item/test_todo_item.py | 4 +- .../test_touch_predictions.py | 160 +---------------- docs/decisions.md | 2 +- 6 files changed, 176 insertions(+), 167 deletions(-) create mode 100644 bin/plan/test_touches.py diff --git a/README.md b/README.md index fe62dce9..ff5b8a2d 100644 --- a/README.md +++ b/README.md @@ -223,7 +223,7 @@ Install puts only `loop-claude` on `PATH`; call the others by their path, such a - `machine_load/` takes the machine's heavy slots, its shared lock files, for `run_heavy` and `adf_codec`, and reads the memory share that loop-claude waits for. It also gives `mutate_changes` a slot's CPU count. - `model_routing/` holds the shipped routing ladder (`routing-ladder.json`) and its steps (`ladder.py`), and reads a ladder from that file or a project's own (`ladder_file.py`), for loop-claude, `rule_hook`, `do_epic`, both replay tools and `subagent-rung`. It finds a project's config folder through `project_config`. It also holds the list prices, which `routing_figures` and `transcript_archive` read. - `notifier/` sends the human a DM through the notifier a project's config names, for `notify` and for loop-claude through `loop_effects`. Its backends are `mattermost.py` and `slack.py`. -- `plan/` is the plan's core, and imports neither `plan_store` nor `release_plan`. It holds an item and the items table's format (`todo_table.py`), releases (`release.py`), the ranking (`ranking.py`, with its score formula in `formula.py` and its blocker order in `blockers.py`), the paths an item's text names (`named_paths.py`) and `citations.py`, which holds `todo.md` and `docs/decisions.md` to each other. `goals_file.py` reads the goals file's sections, goals and goal weights, for the ranking and for `loop_claude`'s premises. +- `plan/` is the plan's core, and imports neither `plan_store` nor `release_plan`. It holds an item and the items table's format (`todo_table.py`), releases (`release.py`), the ranking (`ranking.py`, with its score formula in `formula.py` and its blocker order in `blockers.py`), the paths an item's text names (`named_paths.py`), an item's `Touches:` prediction and where two overlap (`touches.py`), and `citations.py`, which holds `todo.md` and `docs/decisions.md` to each other. `goals_file.py` reads the goals file's sections, goals and goal weights, for the ranking and for `loop_claude`'s premises. - `plan_store/` reads and writes a project's plan through the store the project's config names (`stores.py`). Every backend meets `plans.py`'s `PlanStore`: a markdown file (`todo_md.py`, which also ranks and checks the file in place, with its text edits in `markdown_edits.py`) or a Jira epic (`jira_epic.py`). `scoring.py` reads the goal weights that both backends rank by. `contract.py` holds the tests every backend that writes must pass; `jira_epic.py` doesn't yet, and its own tests stand in for Jira. `fakes.py` holds a plan in memory. - `rank_todo.py`, `settings_filter.py` and `statusline.py` are tools of one file each, tested beside them. - `record_store/` reads and writes a project's records, each through the store the project's config names (`stores.py`): a markdown file, a Confluence Cloud page (`confluence_page.py`), or, for the goals, a Jira epic's description (`jira_description.py`). `contract.py` holds the tests every backend must pass, and `fakes.py` a store in memory that the tests of other tools use. diff --git a/bin/plan/test_touches.py b/bin/plan/test_touches.py new file mode 100644 index 00000000..d0e0b18d --- /dev/null +++ b/bin/plan/test_touches.py @@ -0,0 +1,167 @@ +import pathlib +import shutil +import subprocess +import sys +import unittest + +sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1])) + +from adf_codec import convert +from failure import Failure +from plan.touches import overlaps, Part, predicted, rendered, together + +DETAIL = """A planning call. + +Touches: + +- `bin/a.py`: `main`, `Plan.branch` (small) +- `README.md`: `## Goals, and (more): things` +- `bin/run.sh`: lines 10-20 +- `docs/new.md` + +More prose, with `bin/b.py` named. +""" + +needs_docker = unittest.skipIf(shutil.which("docker") is None or subprocess.run(["docker", "info"], capture_output=True, timeout=20).returncode != 0, "adf_codec runs in a container, which needs a docker daemon") + + +def text(words: str, code: bool = False) -> dict: + return {"type": "text", "text": words, **({"marks": [{"type": "code"}]} if code else {})} + + +def bullet_of(*spans: dict) -> dict: + return {"type": "listItem", "attrs": {"localId": "i"}, "content": [{"type": "paragraph", "attrs": {"localId": "p"}, "content": list(spans)}]} + + +# A Touches list as someone types it in Jira's editor: a paragraph, then a bulleted list whose paths and names carry the code mark. +JIRA_TOUCHES = {"type": "doc", "version": 1, "content": [ + {"type": "paragraph", "attrs": {"localId": "a"}, "content": [text("A planning call.")]}, + {"type": "paragraph", "attrs": {"localId": "b"}, "content": [text("Touches:")]}, + {"type": "bulletList", "attrs": {"localId": "c"}, "content": [ + bullet_of(text("bin/a.py", True), text(": "), text("main", True), text(", "), text("Plan.branch", True), text(" (small)")), + bullet_of(text("a`b.md", True), text(": "), text("## The `foo` tool", True), text(" (small)"), text(", "), text("`x`", True)), + bullet_of(text("bin/run.sh", True), text(": lines 10-20")), + bullet_of(text("docs/new.md", True)), + ]}, + {"type": "paragraph", "attrs": {"localId": "d"}, "content": [text("More prose.")]}, +]} + + +class PredictedTest(unittest.TestCase): + def test_reads_each_bullet_of_the_touches_list(self) -> None: + self.assertEqual(predicted(DETAIL), { + "bin/a.py": (Part("main"), Part("Plan.branch", small=True)), + "README.md": (Part("## Goals, and (more): things"),), + "bin/run.sh": (Part("lines 10-20"),), + "docs/new.md": (), + }) + + def test_a_detail_without_the_list_predicts_nothing(self) -> None: + self.assertIsNone(predicted("Only prose, with `bin/a.py` named.")) + + def test_a_bullet_it_cannot_read_is_a_failure_that_quotes_it(self) -> None: + for bullet in ("- bin/a.py: main", "- `bin/a.py`: main", "- `bin/a.py`: lines 20-10", "- `bin/a.py`: `main` `other`"): + with self.subTest(bullet): + found = predicted(f"Touches:\n\n{bullet}\n") + assert isinstance(found, Failure) + self.assertIn(bullet, found.reason) + + def test_an_empty_list_is_a_failure(self) -> None: + self.assertIsInstance(predicted("Touches:\n\nProse.\n"), Failure) + found = predicted("Touches:\n") + assert isinstance(found, Failure) + self.assertEqual(found.reason, "no bullet follows `Touches:`") + + def test_reads_a_list_right_under_its_label_a_one_line_range_and_a_name_of_any_letters(self) -> None: + self.assertEqual(predicted("Touches:\n- `a.py`: `Xray`, lines 5-5\n"), {"a.py": (Part("Xray"), Part("lines 5-5"))}) + + def test_rendered_reads_back(self) -> None: + touches = predicted(DETAIL) + assert isinstance(touches, dict) + self.assertEqual(predicted(f"Touches:\n\n{rendered(touches)}\n"), touches) + + def test_a_name_that_holds_backticks_takes_a_longer_run_with_a_space_inside_each_end(self) -> None: + self.assertEqual(predicted("Touches:\n- `a.md`: `` ## The `foo` tool `` (small), ``` `` ```, `` `x` ``\n"), {"a.md": (Part("## The `foo` tool", small=True), Part("``"), Part("`x`"))}) + self.assertEqual(rendered({"a.md": (Part("## The `foo` tool", small=True), Part("``"))}), "- `a.md`: `` ## The `foo` tool `` (small), ``` `` ```") + + def test_a_longer_run_without_padding_spaces_is_the_text_between_its_runs(self) -> None: + self.assertEqual(predicted("Touches:\n- ``a`b.md``: ``## The `foo` tool`` (small), ``` `` ```, `` `x` ``\n"), {"a`b.md": (Part("## The `foo` tool", small=True), Part("``"), Part("`x`"))}) + + def test_a_longer_run_with_a_space_at_one_end_only_keeps_it(self) -> None: + self.assertEqual(predicted("Touches:\n- `a.md`: `` x``, ``y ``, `` a ``\n"), {"a.md": (Part(" x"), Part("y "), Part("a"))}) + + @needs_docker + def test_a_list_written_in_markdown_and_read_back_from_a_jira_description_reads_as_written(self) -> None: + description = convert.markdown_to_adf(DETAIL) + assert isinstance(description, dict) + self.assertEqual(predicted(convert.adf_to_markdown(description)), predicted(DETAIL)) + + @needs_docker + def test_a_list_typed_in_jiras_editor_reads_as_its_files_and_parts(self) -> None: + read = convert.adf_to_markdown(JIRA_TOUCHES) + self.assertEqual(predicted(read), { + "bin/a.py": (Part("main"), Part("Plan.branch", small=True)), + "a`b.md": (Part("## The `foo` tool", small=True), Part("`x`")), + "bin/run.sh": (Part("lines 10-20"),), + "docs/new.md": (), + }) + + def test_a_name_ends_only_at_a_run_as_long_as_the_one_that_opens_it(self) -> None: + self.assertEqual(predicted("Touches:\n- `a.md`: `` a ``` b ``, `c``d`\n"), {"a.md": (Part("a ``` b"), Part("c``d"))}) + + def test_a_path_holds_any_character_and_a_single_backtick_keeps_a_names_spaces(self) -> None: + self.assertEqual(predicted("Touches:\n- `my file.md`: ` x `\n- `` a`b.md ``\n"), {"my file.md": (Part(" x "),), "a`b.md": ()}) + + def test_rendered_reads_back_whatever_a_path_or_a_name_holds(self) -> None: + touches = {"my file.md": (Part("## todo.md: under `Touches:` in its detail"), Part("## ``a`` and `b`", small=True), Part("`"), Part("## ends in `x`"), Part(" x "), Part("lines 2-3")), "a`b.md": (), "c, d: e.md": (Part("# T"),)} + self.assertEqual(predicted(f"Touches:\n\n{rendered(touches)}\n"), touches) + + def test_a_bullet_with_an_unclosed_run_a_blank_name_or_a_stray_separator_is_a_failure(self) -> None: + for bullet in ("- `a.md`: `` ## A", "- `a.md`: `` ## A `", "- `a.md`: `` ``", "- `a.md`: ", "- `a.md`:", "- `a.md`: `f`, ", "- `a.md`: `f`,`g`", "- ``", "- `a.md` (small)", "- `a.md`: `f` (small) (small)"): + with self.subTest(bullet): + self.assertIsInstance(predicted(f"Touches:\n\n{bullet}\n"), Failure) + + def test_a_range_that_runs_backwards_is_a_failure_that_says_so(self) -> None: + found = predicted("Touches:\n\n- `bin/a.py`: `f`, lines 20-10\n") + assert isinstance(found, Failure) + self.assertEqual(found.reason, "the bullet '- `bin/a.py`: `f`, lines 20-10' under `Touches:` holds a line range whose first line comes after its last") + + def test_together_joins_items_and_keeps_small_only_where_each_says_so(self) -> None: + joined = together([{"a.py": (Part("f", small=True), Part("g", small=True))}, {"a.py": (Part("f"),), "b.md": ()}, {"b.md": (Part("# T"),)}]) + self.assertEqual(joined, {"a.py": (Part("f"), Part("g", small=True)), "b.md": ()}) + + def test_together_keeps_a_part_not_small_once_one_says_so_and_reads_on_past_a_whole_file(self) -> None: + joined = together([{"a.py": (Part("f"),), "b.md": ()}, {"b.md": (Part("# T"),), "a.py": (Part("f", small=True),), "c.py": (Part("h"),)}]) + self.assertEqual(joined, {"a.py": (Part("f"),), "b.md": (), "c.py": (Part("h"),)}) + + +class OverlapsTest(unittest.TestCase): + def test_other_files_and_other_parts_do_not_overlap(self) -> None: + self.assertEqual(overlaps({"a.py": (Part("f"),)}, {"a.py": (Part("g"),), "b.py": ()}), []) + + def test_the_same_part_overlaps(self) -> None: + self.assertEqual(overlaps({"a.py": (Part("f"), Part("g"))}, {"a.py": (Part("g"),)}), ["`a.py` `g`"]) + + def test_a_class_overlaps_its_method_but_not_a_name_it_only_starts(self) -> None: + self.assertEqual(overlaps({"a.py": (Part("Plan"),)}, {"a.py": (Part("Plan.branch"), Part("Planned"))}), ["`a.py` `Plan`"]) + + def test_a_whole_file_overlaps_any_part_of_it(self) -> None: + self.assertEqual(overlaps({"a.py": ()}, {"a.py": (Part("g", small=True),)}), ["`a.py`"]) + + def test_reads_on_past_a_file_only_one_touches_and_past_a_whole_file(self) -> None: + theirs = {"a.py": (), "b.py": (Part("g"),)} + self.assertEqual(overlaps({"z.py": (Part("f"),), "a.py": (), "b.py": (Part("g"),)}, theirs), ["`a.py`", "`b.py` `g`"]) + + def test_line_ranges_overlap_where_they_share_a_line(self) -> None: + self.assertEqual(overlaps({"x.sh": (Part("lines 1-10"),)}, {"x.sh": (Part("lines 10-12"),)}), ["`x.sh` lines 1-10"]) + self.assertEqual(overlaps({"x.sh": (Part("lines 1-9"),)}, {"x.sh": (Part("lines 10-12"),)}), []) + self.assertEqual(overlaps({"x.sh": (Part("lines 10-12"),)}, {"x.sh": (Part("lines 1-10"),)}), ["`x.sh` lines 10-12"]) + self.assertEqual(overlaps({"x.sh": (Part("lines 11-12"),)}, {"x.sh": (Part("lines 1-10"),)}), []) + + def test_a_line_range_overlaps_a_named_part_since_nothing_tells_them_apart(self) -> None: + self.assertEqual(overlaps({"a.py": (Part("lines 1-9"),)}, {"a.py": (Part("f"),)}), ["`a.py` lines 1-9"]) + self.assertEqual(overlaps({"a.py": (Part("f"),)}, {"a.py": (Part("lines 1-9"),)}), ["`a.py` `f`"]) + + def test_a_small_change_on_either_side_is_taken(self) -> None: + self.assertEqual(overlaps({"a.py": (Part("f", small=True),)}, {"a.py": (Part("f"),)}), []) + self.assertEqual(overlaps({"a.py": (Part("f"),)}, {"a.py": (Part("f", small=True),)}), []) diff --git a/bin/todo_item/main.py b/bin/todo_item/main.py index d98f88db..a2e6d3e8 100644 --- a/bin/todo_item/main.py +++ b/bin/todo_item/main.py @@ -28,7 +28,7 @@ list and show read only the plan, and print no Score: an item's place in list's add files the item under the next free ID, with the tagline in bold, and the detail it reads from stdin, if any. The detail may hold no ## or ### heading. It prints `Filed item in .` It doesn't write anything where ranking fails or scores the item under the bar, -or where the detail holds a `Touches:` list that touch-predictions cannot read, as `touch-predictions --help` spells it. +or where the detail holds a `Touches:` list not spelt as `touch-predictions --help` shows. In a Jira epic, add files a Task under the epic, and is the new issue's number. The release must be one of the Jira project's Fix Versions, named as 1.2.0 or v1.2.0 there, and --exempt security also labels the issue `security`. The item scores by the config's `jira-score-formula`, and @@ -42,8 +42,8 @@ edit sets the cells whose flag is given and leaves the rest; an empty value, as empties the cell. --detail replaces the detail with the text on stdin, and --clear-detail removes it. Text on stdin without --detail, and --detail without text on stdin, are refused, so no detail is dropped or wiped by mistake. It prints `Edited item in .` It doesn't write anything where -ranking fails or scores the item under the bar, or where a new detail holds a `Touches:` list that -touch-predictions cannot read. +ranking fails or scores the item under the bar, or where a new detail holds a `Touches:` list not +spelt as `touch-predictions --help` shows. In a Jira epic, edit changes an issue the loop filed: its summary, description and scores, the label `security` with --exempt, and its "is blocked by" links with --blocked-by: it makes a link for each blocker added and deletes the link of each blocker dropped. Each blocker must be an open child of the @@ -199,7 +199,7 @@ def reported(written: Written | Failure, refusal: str, done: typing.Callable[[Wr def unreadable(detail: str | None, refusal: str) -> Failure | None: - """A Failure opened with refusal where detail holds a `Touches:` list touch-predictions cannot read; checked here, before the plan's backend gets the detail, so a plan in Jira is held to it too. chunk-preflight reads the list first, and on such a list starts no chunk beside the item without saying why.""" + """A Failure opened with refusal where detail holds a `Touches:` list touch-predictions cannot read; checked here, before the plan's backend gets the detail, so a plan in Jira is held to it too.""" read = None if detail is None else predicted(detail) return Failure(f"{refusal}: {read.reason}") if isinstance(read, Failure) else None diff --git a/bin/todo_item/test_todo_item.py b/bin/todo_item/test_todo_item.py index 13dd9496..0b9d2cd2 100644 --- a/bin/todo_item/test_todo_item.py +++ b/bin/todo_item/test_todo_item.py @@ -499,9 +499,9 @@ class Edit(TodoItem): class UnreadableTouches(TodoItem): - """A `Touches:` list touch-predictions cannot read is refused when written, since chunk-preflight would silently start no chunk beside the item.""" + """A `Touches:` list touch-predictions cannot read is refused when written, since loop-claude doesn't start any chunk beside an item whose list it cannot read.""" - def test_add_and_edit_refuse_each_bullet_that_stalled_the_loop_and_write_nothing(self): + def test_add_and_edit_refuse_each_bullet_that_stalled_the_loop(self): for bullet in UNREADABLE_BULLETS: for argv, refusal in ((ADD, "not filed: "), (["edit", "3", "--detail"], "not edited: item 3's detail: ")): with self.subTest(bullet=bullet, command=argv[0]): diff --git a/bin/touch_predictions/test_touch_predictions.py b/bin/touch_predictions/test_touch_predictions.py index 3c79fe27..e960c9a6 100644 --- a/bin/touch_predictions/test_touch_predictions.py +++ b/bin/touch_predictions/test_touch_predictions.py @@ -1,7 +1,6 @@ import os import pathlib import re -import shutil import subprocess import sys import tempfile @@ -10,53 +9,16 @@ import unittest sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1])) from touch_predictions.beside import Beside, chunks_beside -from adf_codec import convert from touch_predictions import diff_parts, file_parts, main, record from failure import Failure from test_env import isolated_env from project_config.main import located from record_store.fakes import MemoryStore -from plan.touches import overlaps, Part, predicted, rendered, together +from plan.touches import Part from plan_store.todo_md import plan_of from project_config.settings import ProjectConfig from project_config.test_project_config import write_config -DETAIL = """A planning call. - -Touches: - -- `bin/a.py`: `main`, `Plan.branch` (small) -- `README.md`: `## Goals, and (more): things` -- `bin/run.sh`: lines 10-20 -- `docs/new.md` - -More prose, with `bin/b.py` named. -""" - -needs_docker = unittest.skipIf(shutil.which("docker") is None or subprocess.run(["docker", "info"], capture_output=True, timeout=20).returncode != 0, "adf_codec runs in a container, which needs a docker daemon") - - -def text(words: str, code: bool = False) -> dict: - return {"type": "text", "text": words, **({"marks": [{"type": "code"}]} if code else {})} - - -def bullet_of(*spans: dict) -> dict: - return {"type": "listItem", "attrs": {"localId": "i"}, "content": [{"type": "paragraph", "attrs": {"localId": "p"}, "content": list(spans)}]} - - -# A Touches list as someone types it in Jira's editor: a paragraph, then a bulleted list whose paths and names carry the code mark. -JIRA_TOUCHES = {"type": "doc", "version": 1, "content": [ - {"type": "paragraph", "attrs": {"localId": "a"}, "content": [text("A planning call.")]}, - {"type": "paragraph", "attrs": {"localId": "b"}, "content": [text("Touches:")]}, - {"type": "bulletList", "attrs": {"localId": "c"}, "content": [ - bullet_of(text("bin/a.py", True), text(": "), text("main", True), text(", "), text("Plan.branch", True), text(" (small)")), - bullet_of(text("a`b.md", True), text(": "), text("## The `foo` tool", True), text(" (small)"), text(", "), text("`x`", True)), - bullet_of(text("bin/run.sh", True), text(": lines 10-20")), - bullet_of(text("docs/new.md", True)), - ]}, - {"type": "paragraph", "attrs": {"localId": "d"}, "content": [text("More prose.")]}, -]} - PYTHON = """\"\"\"Docstring.\"\"\" import os @@ -98,126 +60,6 @@ Text. """ -class PredictedTest(unittest.TestCase): - def test_reads_each_bullet_of_the_touches_list(self) -> None: - self.assertEqual(predicted(DETAIL), { - "bin/a.py": (Part("main"), Part("Plan.branch", small=True)), - "README.md": (Part("## Goals, and (more): things"),), - "bin/run.sh": (Part("lines 10-20"),), - "docs/new.md": (), - }) - - def test_a_detail_without_the_list_predicts_nothing(self) -> None: - self.assertIsNone(predicted("Only prose, with `bin/a.py` named.")) - - def test_a_bullet_it_cannot_read_is_a_failure_that_quotes_it(self) -> None: - for bullet in ("- bin/a.py: main", "- `bin/a.py`: main", "- `bin/a.py`: lines 20-10", "- `bin/a.py`: `main` `other`"): - with self.subTest(bullet): - found = predicted(f"Touches:\n\n{bullet}\n") - assert isinstance(found, Failure) - self.assertIn(bullet, found.reason) - - def test_an_empty_list_is_a_failure(self) -> None: - self.assertIsInstance(predicted("Touches:\n\nProse.\n"), Failure) - found = predicted("Touches:\n") - assert isinstance(found, Failure) - self.assertEqual(found.reason, "no bullet follows `Touches:`") - - def test_reads_a_list_right_under_its_label_a_one_line_range_and_a_name_of_any_letters(self) -> None: - self.assertEqual(predicted("Touches:\n- `a.py`: `Xray`, lines 5-5\n"), {"a.py": (Part("Xray"), Part("lines 5-5"))}) - - def test_rendered_reads_back(self) -> None: - touches = predicted(DETAIL) - assert isinstance(touches, dict) - self.assertEqual(predicted(f"Touches:\n\n{rendered(touches)}\n"), touches) - - def test_a_name_that_holds_backticks_takes_a_longer_run_with_a_space_inside_each_end(self) -> None: - self.assertEqual(predicted("Touches:\n- `a.md`: `` ## The `foo` tool `` (small), ``` `` ```, `` `x` ``\n"), {"a.md": (Part("## The `foo` tool", small=True), Part("``"), Part("`x`"))}) - self.assertEqual(rendered({"a.md": (Part("## The `foo` tool", small=True), Part("``"))}), "- `a.md`: `` ## The `foo` tool `` (small), ``` `` ```") - - def test_a_longer_run_without_padding_spaces_is_the_text_between_its_runs(self) -> None: - self.assertEqual(predicted("Touches:\n- ``a`b.md``: ``## The `foo` tool`` (small), ``` `` ```, `` `x` ``\n"), {"a`b.md": (Part("## The `foo` tool", small=True), Part("``"), Part("`x`"))}) - - def test_a_longer_run_with_a_space_at_one_end_only_keeps_it(self) -> None: - self.assertEqual(predicted("Touches:\n- `a.md`: `` x``, ``y ``, `` a ``\n"), {"a.md": (Part(" x"), Part("y "), Part("a"))}) - - @needs_docker - def test_a_list_written_in_markdown_and_read_back_from_a_jira_description_reads_as_written(self) -> None: - description = convert.markdown_to_adf(DETAIL) - assert isinstance(description, dict) - self.assertEqual(predicted(convert.adf_to_markdown(description)), predicted(DETAIL)) - - @needs_docker - def test_a_list_typed_in_jiras_editor_reads_as_its_files_and_parts(self) -> None: - read = convert.adf_to_markdown(JIRA_TOUCHES) - self.assertEqual(predicted(read), { - "bin/a.py": (Part("main"), Part("Plan.branch", small=True)), - "a`b.md": (Part("## The `foo` tool", small=True), Part("`x`")), - "bin/run.sh": (Part("lines 10-20"),), - "docs/new.md": (), - }) - - def test_a_name_ends_only_at_a_run_as_long_as_the_one_that_opens_it(self) -> None: - self.assertEqual(predicted("Touches:\n- `a.md`: `` a ``` b ``, `c``d`\n"), {"a.md": (Part("a ``` b"), Part("c``d"))}) - - def test_a_path_holds_any_character_and_a_single_backtick_keeps_a_names_spaces(self) -> None: - self.assertEqual(predicted("Touches:\n- `my file.md`: ` x `\n- `` a`b.md ``\n"), {"my file.md": (Part(" x "),), "a`b.md": ()}) - - def test_rendered_reads_back_whatever_a_path_or_a_name_holds(self) -> None: - touches = {"my file.md": (Part("## todo.md: under `Touches:` in its detail"), Part("## ``a`` and `b`", small=True), Part("`"), Part("## ends in `x`"), Part(" x "), Part("lines 2-3")), "a`b.md": (), "c, d: e.md": (Part("# T"),)} - self.assertEqual(predicted(f"Touches:\n\n{rendered(touches)}\n"), touches) - - def test_a_bullet_with_an_unclosed_run_a_blank_name_or_a_stray_separator_is_a_failure(self) -> None: - for bullet in ("- `a.md`: `` ## A", "- `a.md`: `` ## A `", "- `a.md`: `` ``", "- `a.md`: ", "- `a.md`:", "- `a.md`: `f`, ", "- `a.md`: `f`,`g`", "- ``", "- `a.md` (small)", "- `a.md`: `f` (small) (small)"): - with self.subTest(bullet): - self.assertIsInstance(predicted(f"Touches:\n\n{bullet}\n"), Failure) - - def test_a_range_that_runs_backwards_is_a_failure_that_says_so(self) -> None: - found = predicted("Touches:\n\n- `bin/a.py`: `f`, lines 20-10\n") - assert isinstance(found, Failure) - self.assertEqual(found.reason, "the bullet '- `bin/a.py`: `f`, lines 20-10' under `Touches:` holds a line range whose first line comes after its last") - - def test_together_joins_items_and_keeps_small_only_where_each_says_so(self) -> None: - joined = together([{"a.py": (Part("f", small=True), Part("g", small=True))}, {"a.py": (Part("f"),), "b.md": ()}, {"b.md": (Part("# T"),)}]) - self.assertEqual(joined, {"a.py": (Part("f"), Part("g", small=True)), "b.md": ()}) - - def test_together_keeps_a_part_not_small_once_one_says_so_and_reads_on_past_a_whole_file(self) -> None: - joined = together([{"a.py": (Part("f"),), "b.md": ()}, {"b.md": (Part("# T"),), "a.py": (Part("f", small=True),), "c.py": (Part("h"),)}]) - self.assertEqual(joined, {"a.py": (Part("f"),), "b.md": (), "c.py": (Part("h"),)}) - - -class OverlapsTest(unittest.TestCase): - def test_other_files_and_other_parts_do_not_overlap(self) -> None: - self.assertEqual(overlaps({"a.py": (Part("f"),)}, {"a.py": (Part("g"),), "b.py": ()}), []) - - def test_the_same_part_overlaps(self) -> None: - self.assertEqual(overlaps({"a.py": (Part("f"), Part("g"))}, {"a.py": (Part("g"),)}), ["`a.py` `g`"]) - - def test_a_class_overlaps_its_method_but_not_a_name_it_only_starts(self) -> None: - self.assertEqual(overlaps({"a.py": (Part("Plan"),)}, {"a.py": (Part("Plan.branch"), Part("Planned"))}), ["`a.py` `Plan`"]) - - def test_a_whole_file_overlaps_any_part_of_it(self) -> None: - self.assertEqual(overlaps({"a.py": ()}, {"a.py": (Part("g", small=True),)}), ["`a.py`"]) - - def test_reads_on_past_a_file_only_one_touches_and_past_a_whole_file(self) -> None: - theirs = {"a.py": (), "b.py": (Part("g"),)} - self.assertEqual(overlaps({"z.py": (Part("f"),), "a.py": (), "b.py": (Part("g"),)}, theirs), ["`a.py`", "`b.py` `g`"]) - - def test_line_ranges_overlap_where_they_share_a_line(self) -> None: - self.assertEqual(overlaps({"x.sh": (Part("lines 1-10"),)}, {"x.sh": (Part("lines 10-12"),)}), ["`x.sh` lines 1-10"]) - self.assertEqual(overlaps({"x.sh": (Part("lines 1-9"),)}, {"x.sh": (Part("lines 10-12"),)}), []) - self.assertEqual(overlaps({"x.sh": (Part("lines 10-12"),)}, {"x.sh": (Part("lines 1-10"),)}), ["`x.sh` lines 10-12"]) - self.assertEqual(overlaps({"x.sh": (Part("lines 11-12"),)}, {"x.sh": (Part("lines 1-10"),)}), []) - - def test_a_line_range_overlaps_a_named_part_since_nothing_tells_them_apart(self) -> None: - self.assertEqual(overlaps({"a.py": (Part("lines 1-9"),)}, {"a.py": (Part("f"),)}), ["`a.py` lines 1-9"]) - self.assertEqual(overlaps({"a.py": (Part("f"),)}, {"a.py": (Part("lines 1-9"),)}), ["`a.py` `f`"]) - - def test_a_small_change_on_either_side_is_taken(self) -> None: - self.assertEqual(overlaps({"a.py": (Part("f", small=True),)}, {"a.py": (Part("f"),)}), []) - self.assertEqual(overlaps({"a.py": (Part("f"),)}, {"a.py": (Part("f", small=True),)}), []) - - class FilePartsTest(unittest.TestCase): def names(self, path: str, text: str, *lines: int) -> set[str] | None: return file_parts.part_names(path, text, lines) diff --git a/docs/decisions.md b/docs/decisions.md index 1181ce2f..27accc7f 100644 --- a/docs/decisions.md +++ b/docs/decisions.md @@ -804,7 +804,7 @@ Valid while the worker writes the tests that larv-review's reviewers hold to the ## todo.md: an item of the next release predicts the files and parts it will touch under `Touches:` in its detail; chunk-preflight takes, in the plan's order, the items that overlap none taken before them as the chunks that may run at once, and the optional `touch-predictions` record keeps each chunk's prediction beside what it touched -2026-11-15, lilleman's call of 2026-11-13 in item 373, which split item 361. Serves goal 1.5, held to goal 1.4: several chunks of one project run at once only where they are unlikely to touch the same lines, since a conflict costs a rebase, a gate rerun and often a review round. A session on the project's rung or above writes each prediction, as `rules/todo-items.md` says, and `bin/touch_predictions/` reads it. The choices the call left open: +2026-11-15, lilleman's call of 2026-11-13 in item 373, which split item 361. Serves goal 1.5, held to goal 1.4: several chunks of one project run at once only where they are unlikely to touch the same lines, since a conflict costs a rebase, a gate rerun and often a review round. A session on the project's rung or above writes each prediction, as `rules/todo-items.md` says, and `bin/plan/touches.py` reads it. The choices the call left open: - **The spelling.** A `Touches:` line, then one bullet per file: the path in backticks, then its parts, each a name in backticks or `lines -`, with `(small)` after a part the item changes only a little; a path or a name that holds a backtick takes a longer run of backticks with a space inside each end, as a Markdown code span does. A path alone is the whole file. Three readers seated as the README's audience picked the bulleted list over one line and over a table, since backticks hold a heading's commas, colons and parentheses. Two of the three put `(small)` after the part and outside the backticks, and two left line ranges unquoted. Each picked a different config key: `touch-predictions` was one reader's first choice and the second choice of the other two. - **A part's boundaries.** Python's `ast` module names the innermost function or class, a top-level assignment by the name it sets, and `(module)` for the rest. A Markdown file's parts are its headings outside fenced code. Any other file, and Python that doesn't parse, falls back to line ranges. A table row is no part of its own: the item named one, but the tables chunks collide on are the plan's and the changelog's, which don't count.