Answer stability round 1: 1 🔴, 4 🟡 (0 misread); check Goals and Audience on the document that is sent, report an unknown section as a Failure, refuse a section body that holds a heading, correct the stale read-only text

This commit is contained in:
2026-11-18 10:39:22 +01:00
parent 0755291112
commit fe351d3ed4
12 changed files with 77 additions and 30 deletions
+6 -4
View File
@@ -1,6 +1,6 @@
"""A Jira epic's description as do-epic's record: a language line and the sections Goals, Audience, Scoring (the formula and the bar) and Decisions, read and written one at a time through `EpicDescription`, so a write leaves every other line as it was.
"""A Jira epic's description as the record of do-epic, the tool that will drive one epic.
Goals and Audience change only where the human approved in an interrupt, which `write_section` takes as `approved`; `EpicDescription` refuses the change otherwise."""
The description holds a language line and the sections Goals, Audience, Scoring (the formula and the bar) and Decisions. They are read and written one at a time through `EpicDescription`, and a write leaves every other line of the markdown as it was. Goals and Audience change only where the human approved in an interrupt, which `write_section` takes as `approved`; `EpicDescription` refuses the change otherwise."""
import dataclasses
import re
import typing
@@ -28,6 +28,8 @@ def with_section(text: str, name: str, body: str) -> str | Failure:
span = span_of(text, name)
if isinstance(span, Failure):
return span
if any(line.startswith(("# ", "## ")) and not fenced for line, fenced in fenced_lines(body)):
return Failure(f"the body of ## {name} holds a level 1 or 2 heading, which would start another section")
if span is None:
return text.rstrip("\n") + "\n\n" * bool(text.strip()) + f"## {name}\n\n{body.strip()}\n"
lines = text.splitlines()
@@ -38,9 +40,9 @@ def with_section(text: str, name: str, body: str) -> str | Failure:
def span_of(text: str, name: str) -> tuple[int, int] | None | Failure:
"""The index of the one ## name heading's line and of the line that ends its section; None where there is no such heading. Fenced lines start and end no section."""
"""The index of the one ## name heading's line and of the line after its section; None where there is no such heading. A heading inside a code fence is ignored."""
if name not in SECTIONS:
raise ValueError(f"{name} is not a section of an epic's description; the sections are {', '.join(SECTIONS)}")
return Failure(f"{name} is not a section of an epic's description; the sections are {', '.join(SECTIONS)}")
lines = fenced_lines(text)
headings = [index for index, (line, fenced) in enumerate(lines) if not fenced and (line.startswith("# ") or line.startswith("## "))]
starts = [index for index in headings if lines[index][0].startswith("## ") and lines[index][0][3:].strip() == name]
+11 -2
View File
@@ -74,8 +74,17 @@ class SectionsTest(unittest.TestCase):
def test_refuses_a_repeated_section_and_a_name_that_is_no_section(self) -> None:
self.assertIsInstance(with_section("## Scoring\nA\n\n## Scoring\nB\n", "Scoring", "C"), Failure)
with self.assertRaisesRegex(ValueError, "Language is not a section.*Goals, Audience, Scoring, Decisions"):
read_section(DESCRIPTION, "Language")
for found in (read_section(DESCRIPTION, "Language"), with_section(DESCRIPTION, "Language", "Swedish")):
assert isinstance(found, Failure), found
self.assertIn("Language is not a section of an epic's description; the sections are Goals, Audience, Scoring, Decisions", found.reason)
def test_refuses_a_body_that_would_start_another_section(self) -> None:
for body in ("A\n## Goals\nB", "# Title"):
with self.subTest(body):
found = with_section(DESCRIPTION, "Scoring", body)
assert isinstance(found, Failure), found
self.assertIn("level 1 or 2 heading", found.reason)
self.assertIsInstance(with_section(DESCRIPTION, "Scoring", "```\n## Goals\n```\n### Bar"), str)
class LanguageTest(unittest.TestCase):