Refuse a Touches: list touch-predictions cannot read in todo-item add and edit, and in rank_todo.py --check
This commit is contained in:
+14
-4
@@ -27,7 +27,8 @@ 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 <ID> in <plan>.` It doesn't write anything where ranking fails or scores the item under the bar.
|
||||
It prints `Filed item <ID> in <plan>.` 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.
|
||||
In a Jira epic, add files a Task under the epic, and <ID> 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
|
||||
@@ -41,7 +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 <ID> in <plan>.` It doesn't write anything where
|
||||
ranking fails or scores the item under the bar.
|
||||
ranking fails or scores the item under the bar, or where a new detail holds a `Touches:` list that
|
||||
touch-predictions cannot read.
|
||||
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
|
||||
@@ -92,6 +94,7 @@ from plan_store.stores import store as plan_store
|
||||
from record_store.stores import RecordStore, store
|
||||
from todo_item.table import shown, table
|
||||
from todo_item.edits import with_bullet
|
||||
from touch_predictions.prediction import predicted
|
||||
|
||||
# Each score flag, as --l or --L, and the field it sets.
|
||||
LETTERS = ("L", "E", "I", "S")
|
||||
@@ -115,7 +118,8 @@ def main(argv: list[str], folder: pathlib.Path = pathlib.Path(), stdin: typing.T
|
||||
case "show":
|
||||
done = show(args, plan)
|
||||
case "add":
|
||||
done = reported(plan.add(fields(args), piped(stdin)), "not filed", lambda written: f"Filed item {written.id} in {plan.label}.")
|
||||
detail = piped(stdin)
|
||||
done = unreadable(detail, "not filed") or reported(plan.add(fields(args), detail), "not filed", lambda written: f"Filed item {written.id} in {plan.label}.")
|
||||
case "edit":
|
||||
done = edit(args, plan, piped(stdin))
|
||||
case "move":
|
||||
@@ -194,6 +198,12 @@ def reported(written: Written | Failure, refusal: str, done: typing.Callable[[Wr
|
||||
return done(written)
|
||||
|
||||
|
||||
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."""
|
||||
read = None if detail is None else predicted(detail)
|
||||
return Failure(f"{refusal}: {read.reason}") if isinstance(read, Failure) else None
|
||||
|
||||
|
||||
def list_(args: argparse.Namespace, plan: PlanStore) -> str | Failure:
|
||||
read = plan.read()
|
||||
if isinstance(read, Failure):
|
||||
@@ -220,7 +230,7 @@ def edit(args: argparse.Namespace, plan: PlanStore, text: str) -> str | Failure:
|
||||
detail = text if args.detail else "" if args.clear_detail else None
|
||||
if not fields(args) and detail is None:
|
||||
return Failure("not edited: no flag names a change; todo-item --help lists them")
|
||||
return reported(plan.edit(args.id, fields(args), detail, args.comment), "not edited", lambda written: f"Edited item {written.id} in {plan.label}.")
|
||||
return unreadable(detail, f"not edited: item {args.id}'s detail") or reported(plan.edit(args.id, fields(args), detail, args.comment), "not edited", lambda written: f"Edited item {written.id} in {plan.label}.")
|
||||
|
||||
|
||||
def finish(args: argparse.Namespace, plan: PlanStore, changelog: RecordStore | None) -> str | Failure:
|
||||
|
||||
@@ -25,6 +25,16 @@ CHANGELOG = "# Changelog\n\n## Unreleased\n\n- Older news.\n\n## 0.1.0\n\n- Firs
|
||||
# ## Details of the ranked fixture, without the trailing ## Notes.
|
||||
HEADER = "| ID | Release | Blocked by | Exempt | Item | L | E | I | R | S | Moves |\n|---|---|---|---|---|---|---|---|---|---|---|\n"
|
||||
DETAILS = "## Details\n\n### 3. Make it fast, `a | b`.\n\nFast detail.\n\n### 1. Ship the later thing.\n\nLater detail.\n\n"
|
||||
# The bullets six items held on 2026-11-18, which touch-predictions cannot read: `(small)` after a bare path, and a part not in backticks.
|
||||
UNREADABLE_BULLETS = (
|
||||
"- `bin/judge_replay/main.py` (small)",
|
||||
"- `bin/do_epic/main.py` (small)",
|
||||
"- `principles/technical-principles.md`: the tests bullet group, `A valuable test checks behaviour` (small)",
|
||||
"- `README.md`: loop-claude's section (small)",
|
||||
"- `bin/rule_hook/rules.py`: the rule table (small)",
|
||||
"- `settings.json`: the PreToolUse matcher (small)",
|
||||
)
|
||||
READABLE_TOUCHES = "Why.\n\nTouches:\n\n- `bin/a.py`: `main`, `Plan.branch` (small)\n- `bin/run.sh`: lines 10-20\n- `docs/new.md`\n"
|
||||
|
||||
|
||||
class Terminal(io.StringIO):
|
||||
@@ -488,6 +498,37 @@ class Edit(TodoItem):
|
||||
self.assertEqual(self.todo.read_text(), before)
|
||||
|
||||
|
||||
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."""
|
||||
|
||||
def test_add_and_edit_refuse_each_bullet_that_stalled_the_loop_and_write_nothing(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]):
|
||||
before = self.todo.read_text()
|
||||
code, out, err = self.run_main(*argv, stdin=f"Why.\n\nTouches:\n\n- `bin/a.py`: `main`\n{bullet}\n")
|
||||
self.assertEqual((code, out), (1, ""))
|
||||
self.assertTrue(err.startswith(refusal), err)
|
||||
self.assertIn(repr(bullet), err)
|
||||
self.assertEqual(self.todo.read_text(), before)
|
||||
|
||||
def test_add_and_edit_take_a_readable_list_and_a_detail_without_one(self):
|
||||
for detail in (READABLE_TOUCHES, "Why, without a list.\n"):
|
||||
with self.subTest(detail):
|
||||
self.assertEqual(self.run_main(*ADD, stdin=detail)[0], 0)
|
||||
self.assertEqual(self.run_main("edit", "3", "--detail", stdin=detail)[0], 0)
|
||||
self.assertIn(detail, self.todo.read_text())
|
||||
|
||||
def test_a_plan_in_jira_gets_no_unreadable_list_either(self):
|
||||
self.config.write_text(self.config.read_text().replace('"checkout:todo.md"', f'"{JIRA_PLAN}"') + 'env-file = "~/acme.env"\n' + JIRA_SCORING)
|
||||
plan = MemoryPlan({3: {"Release": "0.1.0", "Item": "**Count the runs.**", "L": "1", "E": "2", "I": "3", "S": "1"}})
|
||||
self.enterContext(unittest.mock.patch.object(main, "plan_store", return_value=plan))
|
||||
detail = f"Touches:\n\n{UNREADABLE_BULLETS[0]}\n"
|
||||
self.assertEqual(self.run_main(*ADD, stdin=detail)[:2], (1, ""))
|
||||
self.assertEqual(self.run_main("edit", "3", "--detail", stdin=detail)[:2], (1, ""))
|
||||
self.assertEqual((list(plan.rows), plan.details), ([3], {}))
|
||||
|
||||
|
||||
class Move(TodoItem):
|
||||
def test_sets_the_items_release_and_keeps_the_rest(self):
|
||||
self.assertEqual(self.run_main("move", "3", "--release", "0.2.0"), (0, f"Moved item 3 to release 0.2.0 in {self.todo}.\n", ""))
|
||||
|
||||
Reference in New Issue
Block a user