Read a Touches list from a Jira description, as the codec spells it, and reword four decisions' expiry and two reading-cost goal citations
CI / tests (pull_request) Failing after 3m8s

This commit is contained in:
2026-11-17 03:01:46 +01:00
parent ed9ab534f8
commit c3745ca03f
4 changed files with 93 additions and 12 deletions
+5 -4
View File
@@ -10,7 +10,7 @@ The spelling, which the decision `todo.md: an item of the next release predicts
A path alone is the whole file, and (small) marks a part the item changes only a little. file_parts says how a part is named.
A path or a name that holds a backtick is spelt as a Markdown code span that holds one: in a longer run of backticks than any it holds, with a space inside each end, as in `` ## The `foo` tool ``. So every path and name on one line has a spelling."""
A path or a name that holds a backtick is spelt as a Markdown code span that holds one: in a longer run of backticks than any it holds, with a space inside each end, as in `` ## The `foo` tool ``. So every path and name on one line has a spelling. A description kept in Jira reaches here through adf_codec, which spells such a name without the spaces where it neither opens nor ends in a backtick, as ``a`b.md``; that is read as the same name."""
import dataclasses
import re
@@ -82,10 +82,11 @@ def code_span(line: str, at: int) -> tuple[str, int] | None:
return None
text = line[opened.end():opened.end() + closed.start()]
if len(run) > 1:
# A longer run holds a space inside each end, which keeps a backtick at either end of the text apart from the run.
if len(text) < 3 or not text.startswith(" ") or not text.endswith(" "):
if not text.strip():
return None
text = text[1:-1]
# As a Markdown code span reads: a space inside each end keeps a backtick at either end of the text apart from the run, and goes. adf_codec pads only that case, so no space is also the text.
if len(text) >= 3 and text.startswith(" ") and text.endswith(" "):
text = text[1:-1]
return (text, opened.end() + closed.end()) if text else None
@@ -1,6 +1,7 @@
import os
import pathlib
import re
import shutil
import subprocess
import sys
import tempfile
@@ -8,6 +9,7 @@ import unittest
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
from adf_codec import convert
from touch_predictions.beside import Beside, chunks_beside
from touch_predictions import diff_parts, file_parts, main, record
from failure import Failure
@@ -31,6 +33,30 @@ Touches:
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
@@ -109,6 +135,26 @@ class PredictedTest(unittest.TestCase):
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_the_spaces_the_text_does_not_need_reads_as_its_text(self) -> None:
# The spelling adf_codec gives a code mark: it pads a longer run only where the text opens or ends in a backtick.
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`"))})
@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_the_item_it_names(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"))})
@@ -119,8 +165,8 @@ class PredictedTest(unittest.TestCase):
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_longer_run_without_its_spaces_or_its_end_or_a_name_is_a_failure(self) -> None:
for bullet in ("- `a.md`: ``## A``", "- `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)"):
def test_a_longer_run_without_its_end_or_a_name_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)