Answer architecture round 3: 0 🔴, 2 🟡 (0 misread); a record write names its version, even None, in every backend, and the unreleased section is read through markdown_text.section by one title pattern

This commit is contained in:
2026-11-16 16:17:12 +01:00
parent 50ce373c40
commit a7a6640ea1
12 changed files with 30 additions and 31 deletions
+3 -2
View File
@@ -10,8 +10,9 @@ VERSION = r"[0-9]+\.[0-9]+\.[0-9]+"
DATE_DIGITS = (4, 2, 2) DATE_DIGITS = (4, 2, 2)
DATED = re.compile(rf"({VERSION}) - " + "-".join(f"[0-9]{{{digits}}}" for digits in DATE_DIGITS)) DATED = re.compile(rf"({VERSION}) - " + "-".join(f"[0-9]{{{digits}}}" for digits in DATE_DIGITS))
TAG = re.compile(rf"v({VERSION})") TAG = re.compile(rf"v({VERSION})")
# The heading of CHANGELOG.md's section for news not yet released: ## Unreleased, or a heading that says unreleased, such as `## 0.6.0 (unreleased)`, as a project's own changelog may head it. # The title of CHANGELOG.md's section for news not yet released: Unreleased, or a title that says unreleased, such as `0.6.0 (unreleased)`, as a project's own changelog may head it; and its ## heading.
UNRELEASED_HEADING = re.compile(r"^## .*unreleased.*$", re.M | re.I) UNRELEASED_TITLE = r"(?i:.*unreleased.*)"
UNRELEASED_HEADING = re.compile(rf"^## {UNRELEASED_TITLE}$", re.M)
def release_of(version: str) -> Release: def release_of(version: str) -> Release:
+1 -1
View File
@@ -238,7 +238,7 @@ class Located(unittest.TestCase):
class Update(unittest.TestCase): class Update(unittest.TestCase):
def test_fails_where_the_record_refuses_the_write(self): def test_fails_where_the_record_refuses_the_write(self):
class Unwritable(MemoryStore): class Unwritable(MemoryStore):
def write(self, text: str, over: str | None = None) -> Held | Failure: def write(self, text: str, over: str | None) -> Held | Failure:
return Failure("the wiki is down") return Failure("the wiki is down")
archive = pathlib.Path(self.enterContext(tempfile.TemporaryDirectory())) archive = pathlib.Path(self.enterContext(tempfile.TemporaryDirectory()))
+1 -1
View File
@@ -81,7 +81,7 @@ class ConfluencePage:
return Failure(f"cannot convert {self.label} to markdown: {texts.reason}") return Failure(f"cannot convert {self.label} to markdown: {texts.reason}")
return texts[0] return texts[0]
def write(self, text: str, over: str | None = None) -> Held | Failure: def write(self, text: str, over: str | None) -> Held | Failure:
"""Replaces the page's text with text, as the version after over, the one held() gave. Where over is None, it replaces the page as it stands.""" """Replaces the page's text with text, as the version after over, the one held() gave. Where over is None, it replaces the page as it stands."""
seen = self.seen_of(over) seen = self.seen_of(over)
if isinstance(seen, Failure): if isinstance(seen, Failure):
+3 -3
View File
@@ -21,12 +21,12 @@ class RecordStoreContract:
def test_reads_back_what_it_wrote_to_the_character(self) -> None: def test_reads_back_what_it_wrote_to_the_character(self) -> None:
store = self.new_store() store = self.new_store()
text = "# Decisions\n\n- Å, 🔴 and a | pipe\n\n\n" text = "# Decisions\n\n- Å, 🔴 and a | pipe\n\n\n"
self.assertEqual(store.write(text), store.held()) self.assertEqual(store.write(text, None), store.held())
self.assertEqual(store.read(), text) self.assertEqual(store.read(), text)
def test_a_write_replaces_the_whole_record(self) -> None: def test_a_write_replaces_the_whole_record(self) -> None:
store = self.new_store() store = self.new_store()
first = store.write("first\nsecond\n") first = store.write("first\nsecond\n", None)
assert isinstance(first, Held), first assert isinstance(first, Held), first
# A write over the version the last one left replaces the record, as a later save does. # A write over the version the last one left replaces the record, as a later save does.
self.assertIsInstance(store.write("third\n", first.version), Held) self.assertIsInstance(store.write("third\n", first.version), Held)
@@ -34,7 +34,7 @@ class RecordStoreContract:
def test_holds_its_text_with_the_version_a_write_over_it_names(self) -> None: def test_holds_its_text_with_the_version_a_write_over_it_names(self) -> None:
store = self.new_store() store = self.new_store()
store.write("text\n") store.write("text\n", None)
held = store.held() held = store.held()
assert isinstance(held, Held), held assert isinstance(held, Held), held
self.assertEqual(held.text, "text\n") self.assertEqual(held.text, "text\n")
+1 -1
View File
@@ -19,7 +19,7 @@ class MemoryStore:
def held(self) -> Held | Failure: def held(self) -> Held | Failure:
return Failure(self.fails) if self.fails else Held(self.text) return Failure(self.fails) if self.fails else Held(self.text)
def write(self, text: str, over: str | None = None) -> Held | Failure: def write(self, text: str, over: str | None) -> Held | Failure:
if self.fails: if self.fails:
return Failure(self.fails) return Failure(self.fails)
self.text = text self.text = text
+1 -1
View File
@@ -54,5 +54,5 @@ class EpicDescription:
text = self.read() text = self.read()
return text if isinstance(text, Failure) else Held(text) return text if isinstance(text, Failure) else Held(text)
def write(self, text: str, over: str | None = None) -> Held | Failure: def write(self, text: str, over: str | None) -> Held | Failure:
return Failure(READ_ONLY) return Failure(READ_ONLY)
+5 -5
View File
@@ -31,8 +31,8 @@ class RecordStore(typing.Protocol):
def held(self) -> Held | Failure: def held(self) -> Held | Failure:
"""The record as it stands, with the version a write over it names.""" """The record as it stands, with the version a write over it names."""
def write(self, text: str, over: str | None = None) -> Held | Failure: def write(self, text: str, over: str | None) -> Held | Failure:
"""Replaces the record's whole text, creating the record where it doesn't exist yet, and gives the record as the write left it. over is the version held() gave: where someone saved the record since, the write refuses. None replaces the record as it stands.""" """Replaces the record's whole text, creating the record where it doesn't exist yet, and gives the record as the write left it. over is the version held() gave: where someone saved the record since, the write refuses. None replaces the record as it stands, so a caller passes it only where it read no version."""
@dataclasses.dataclass(frozen=True) @dataclasses.dataclass(frozen=True)
@@ -59,7 +59,7 @@ class FileStore:
except OSError as failure: except OSError as failure:
return Failure(f"cannot read {self.path}: {failure.strerror}") return Failure(f"cannot read {self.path}: {failure.strerror}")
def write(self, text: str, over: str | None = None) -> Held | Failure: def write(self, text: str, over: str | None) -> Held | Failure:
try: try:
self.path.parent.mkdir(parents=True, exist_ok=True) self.path.parent.mkdir(parents=True, exist_ok=True)
except OSError as failure: except OSError as failure:
@@ -108,7 +108,7 @@ def local_file(record: RecordStore, copy: pathlib.Path) -> pathlib.Path | Failur
if isinstance(held, Failure): if isinstance(held, Failure):
return held return held
if held.text: if held.text:
written = FileStore(copy, None).write(held.text) written = FileStore(copy, None).write(held.text, None)
if isinstance(written, Failure): if isinstance(written, Failure):
return written return written
else: else:
@@ -145,7 +145,7 @@ def version_file(copy: pathlib.Path) -> pathlib.Path:
def kept(copy: pathlib.Path, version: str | None) -> Failure | None: def kept(copy: pathlib.Path, version: str | None) -> Failure | None:
"""Keeps version beside copy, or removes the file that kept an earlier one where version is None.""" """Keeps version beside copy, or removes the file that kept an earlier one where version is None."""
if version is not None: if version is not None:
written = FileStore(version_file(copy), None).write(version) written = FileStore(version_file(copy), None).write(version, None)
return written if isinstance(written, Failure) else None return written if isinstance(written, Failure) else None
try: try:
version_file(copy).unlink(missing_ok=True) version_file(copy).unlink(missing_ok=True)
+3 -3
View File
@@ -141,7 +141,7 @@ class ConfluencePageTest(ConfluenceCase):
def test_a_write_with_no_read_replaces_the_page_as_it_stands(self) -> None: def test_a_write_with_no_read_replaces_the_page_as_it_stands(self) -> None:
self.confluence.teammate_saves("earlier\n") self.confluence.teammate_saves("earlier\n")
self.assertIsInstance(self.new_store().write("replaced\n"), Held) self.assertIsInstance(self.new_store().write("replaced\n", None), Held)
self.assertEqual(self.confluence.calls[0], ("GET", URL, AUTHORIZATION, None)) self.assertEqual(self.confluence.calls[0], ("GET", URL, AUTHORIZATION, None))
self.assertEqual(self.new_store().read(), "replaced\n") self.assertEqual(self.new_store().read(), "replaced\n")
@@ -168,7 +168,7 @@ class ConfluencePageTest(ConfluenceCase):
self.confluence.teammate_saves("text\n") self.confluence.teammate_saves("text\n")
store = ConfluencePage(PAGE, self.env, self.confluence.http, lambda _: Failure("the shim is down"), lambda _: Failure("the shim is down")) store = ConfluencePage(PAGE, self.env, self.confluence.http, lambda _: Failure("the shim is down"), lambda _: Failure("the shim is down"))
self.assertEqual(store.read(), Failure(f"cannot convert {PAGE.spelling} to markdown: the shim is down")) self.assertEqual(store.read(), Failure(f"cannot convert {PAGE.spelling} to markdown: the shim is down"))
self.assertEqual(store.write("text\n"), Failure(f"cannot convert the text for {PAGE.spelling} to ADF: the shim is down")) self.assertEqual(store.write("text\n", None), Failure(f"cannot convert the text for {PAGE.spelling} to ADF: the shim is down"))
def test_fails_naming_the_page_where_adf_codec_refuses_its_document(self) -> None: def test_fails_naming_the_page_where_adf_codec_refuses_its_document(self) -> None:
self.confluence.teammate_saves("text\n") self.confluence.teammate_saves("text\n")
@@ -178,7 +178,7 @@ class ConfluencePageTest(ConfluenceCase):
def test_a_write_confluence_refuses_otherwise_fails_naming_the_page_and_not_a_teammate(self) -> None: def test_a_write_confluence_refuses_otherwise_fails_naming_the_page_and_not_a_teammate(self) -> None:
answers = iter([{"title": "Decisions", "version": {"number": 3}}, ErrorAnswer("PUT /wiki/api/v2/pages/2293761 answered 403: Forbidden", 403)]) answers = iter([{"title": "Decisions", "version": {"number": 3}}, ErrorAnswer("PUT /wiki/api/v2/pages/2293761 answered 403: Forbidden", 403)])
store = ConfluencePage(PAGE, self.env, lambda *_: next(answers), to_markdown, to_adf) store = ConfluencePage(PAGE, self.env, lambda *_: next(answers), to_markdown, to_adf)
self.assertEqual(store.write("text\n"), Failure(f"cannot write {PAGE.spelling}: PUT /wiki/api/v2/pages/2293761 answered 403: Forbidden")) self.assertEqual(store.write("text\n", None), Failure(f"cannot write {PAGE.spelling}: PUT /wiki/api/v2/pages/2293761 answered 403: Forbidden"))
def test_fails_on_a_version_it_cannot_read_and_writes_nothing(self) -> None: def test_fails_on_a_version_it_cannot_read_and_writes_nothing(self) -> None:
written = self.new_store().write("text\n", "{}") written = self.new_store().write("text\n", "{}")
+1 -1
View File
@@ -79,7 +79,7 @@ class EpicDescriptionTest(unittest.TestCase):
self.assertEqual(self.calls, []) self.assertEqual(self.calls, [])
def test_writing_fails_since_the_store_only_reads(self) -> None: def test_writing_fails_since_the_store_only_reads(self) -> None:
found = self.store().write("## Goals\n") found = self.store().write("## Goals\n", None)
assert isinstance(found, Failure), found assert isinstance(found, Failure), found
self.assertIn("Jira", found.reason) self.assertIn("Jira", found.reason)
self.assertEqual(self.calls, []) self.assertEqual(self.calls, [])
+4 -4
View File
@@ -57,19 +57,19 @@ class FileStore(unittest.TestCase):
def test_a_write_that_fails_is_a_failure_naming_it(self): def test_a_write_that_fails_is_a_failure_naming_it(self):
(self.folder / "docs").write_text("a file where the folder goes") (self.folder / "docs").write_text("a file where the folder goes")
path = self.folder / "docs" / "decisions.md" path = self.folder / "docs" / "decisions.md"
written = stores.FileStore(path, None).write("text\n") written = stores.FileStore(path, None).write("text\n", None)
self.assertIsInstance(written, Failure) self.assertIsInstance(written, Failure)
self.assertIn(f"cannot write {path}: ", written.reason) self.assertIn(f"cannot write {path}: ", written.reason)
def test_a_write_makes_each_folder_the_file_lacks(self): def test_a_write_makes_each_folder_the_file_lacks(self):
path = self.folder / "records" / "acme" / "decisions.md" path = self.folder / "records" / "acme" / "decisions.md"
self.assertEqual(stores.FileStore(path, None).write("text\n"), Held("text\n")) self.assertEqual(stores.FileStore(path, None).write("text\n", None), Held("text\n"))
self.assertEqual(path.read_text(), "text\n") self.assertEqual(path.read_text(), "text\n")
def test_a_write_onto_a_folder_is_a_failure_naming_it(self): def test_a_write_onto_a_folder_is_a_failure_naming_it(self):
path = self.folder / "decisions.md" path = self.folder / "decisions.md"
path.mkdir() path.mkdir()
written = stores.FileStore(path, None).write("text\n") written = stores.FileStore(path, None).write("text\n", None)
self.assertIsInstance(written, Failure) self.assertIsInstance(written, Failure)
self.assertIn(f"cannot write {path}: ", written.reason) self.assertIn(f"cannot write {path}: ", written.reason)
@@ -113,7 +113,7 @@ class LocalFile(unittest.TestCase):
def test_a_file_record_is_its_own_local_file_and_no_copy_is_made(self): def test_a_file_record_is_its_own_local_file_and_no_copy_is_made(self):
record = stores.FileStore(self.folder / "decisions.md", None) record = stores.FileStore(self.folder / "decisions.md", None)
record.write("kept\n") record.write("kept\n", None)
self.assertEqual(stores.local_file(record, self.folder / "copies" / "decisions.md"), self.folder / "decisions.md") self.assertEqual(stores.local_file(record, self.folder / "copies" / "decisions.md"), self.folder / "decisions.md")
self.assertIsNone(stores.stored(record, self.folder / "copies" / "decisions.md")) self.assertIsNone(stores.stored(record, self.folder / "copies" / "decisions.md"))
self.assertEqual((record.read(), (self.folder / "copies").exists()), ("kept\n", False)) self.assertEqual((record.read(), (self.folder / "copies").exists()), ("kept\n", False))
+5 -9
View File
@@ -1,15 +1,14 @@
"""How the plan stands to the last release cut: the next release, whether work has landed towards it, and whether it is to be planned, reviewed or cut; and, from that standing, the item the next chunk takes first, with what the default branch holds for the pick.""" """How the plan stands to the last release cut: the next release, whether work has landed towards it, and whether it is to be planned, reviewed or cut; and, from that standing, the item the next chunk takes first, with what the default branch holds for the pick."""
import dataclasses import dataclasses
import re
from git_cli.git_repo import commits_since, file_at, git, Git from git_cli.git_repo import commits_since, file_at, git, Git
from plan.release import dated, dated_heading_pattern, newest_tag, parsed, Release, tagged, UNRELEASED_HEADING from plan.release import dated, dated_heading_pattern, newest_tag, parsed, Release, tagged, UNRELEASED_TITLE
from failure import Failure from failure import Failure
from plan.todo_table import Item, items, next_item, renames from plan.todo_table import Item, items, next_item, renames
from plan_store.plans import Plan from plan_store.plans import Plan
from plan_store import stores as plan_stores, plans from plan_store import stores as plan_stores, plans
from project_config.settings import ProjectConfig from project_config.settings import ProjectConfig
from text_files.markdown_text import sections from text_files.markdown_text import section, sections
from record_store import stores from record_store import stores
from project_config import templates from project_config import templates
@@ -259,12 +258,9 @@ def unreleased_changes(cut: LastCut) -> int | Failure:
def unreleased_entries(changelog: str) -> int | None: def unreleased_entries(changelog: str) -> int | None:
"""How many top-level `- ` entries CHANGELOG.md holds under its unreleased section, as UNRELEASED_HEADING heads it; None without that section.""" """How many top-level `- ` entries CHANGELOG.md holds under its unreleased section, whose heading's title UNRELEASED_TITLE matches; None without that section."""
heading = UNRELEASED_HEADING.search(changelog) body = section(changelog, UNRELEASED_TITLE)
if heading is None: return None if body is None else sum(line.startswith("- ") for line in body)
return None
body = re.split(r"^## ", changelog[heading.end():], maxsplit=1, flags=re.M)[0]
return sum(line.startswith("- ") for line in body.splitlines())
def named_releases(todos: list[str] | Failure) -> set[Release] | Failure: def named_releases(todos: list[str] | Failure) -> set[Release] | Failure:
@@ -352,6 +352,8 @@ class ChunkItem(unittest.TestCase):
self.assertEqual(release_standing.unreleased_entries("# Changelog\n\n## Unreleased\n\n- One.\n - A nested line.\n- Two.\n\n## 0.1.0\n\n- Old.\n"), 2) self.assertEqual(release_standing.unreleased_entries("# Changelog\n\n## Unreleased\n\n- One.\n - A nested line.\n- Two.\n\n## 0.1.0\n\n- Old.\n"), 2)
self.assertEqual(release_standing.unreleased_entries("# Changelog\n\n## Unreleased\n\n## 0.1.0\n\n- Old.\n"), 0) self.assertEqual(release_standing.unreleased_entries("# Changelog\n\n## Unreleased\n\n## 0.1.0\n\n- Old.\n"), 0)
self.assertIsNone(release_standing.unreleased_entries("# Changelog\n\n## 0.1.0\n\n- Old.\n")) self.assertIsNone(release_standing.unreleased_entries("# Changelog\n\n## 0.1.0\n\n- Old.\n"))
# A heading inside a code fence doesn't end the section.
self.assertEqual(release_standing.unreleased_entries("# Changelog\n\n## Unreleased\n\n- One.\n\n```\n## 0.1.0\n```\n\n- Two.\n\n## 0.1.0\n\n- Old.\n"), 2)
# The section todo-item finish files a bullet under, as a project's own changelog may head it. # The section todo-item finish files a bullet under, as a project's own changelog may head it.
self.assertEqual(release_standing.unreleased_entries("# Changelog\n\n## 0.6.0 (unreleased)\n\n- One.\n\n## 0.5.0\n\n- Old.\n"), 1) self.assertEqual(release_standing.unreleased_entries("# Changelog\n\n## 0.6.0 (unreleased)\n\n- One.\n\n## 0.5.0\n\n- Old.\n"), 1)