Answer stability round 1: 0 🔴, 8 🟡 (0 misread); keep Ask.asked in seconds and stamp it only in its file, keep the dated-heading rule in one function and the preflight's wording in chunk_preflight, match the heading line itself, and test a device path, a tagged repo with a dated heading, an untagged one without, and the wording where nothing is cut

This commit is contained in:
2026-11-04 21:25:16 +01:00
parent 0a47507756
commit 8a35412a0a
13 changed files with 98 additions and 54 deletions
+12 -17
View File
@@ -94,7 +94,7 @@ def default_plan(root: str, ref: str) -> DefaultPlan:
"""What ref, the default branch as last fetched, holds for the pick, read in the checkout at root."""
tag = newest_release_tag(ref, root)
changelog = file_at(ref, "CHANGELOG.md", root)
after = max(dated_headings(changelog), default=None) if tag is None else None
after = dated_cut(tag, changelog)
since = tag if after is None else heading_commit(after, ref, root)
commits = since if isinstance(since, Failure) else commits_since(since, ref, root)
reviewed = tag if isinstance(tag, Failure) else release_reviewed(tag, ref, root, after)
@@ -103,7 +103,9 @@ def default_plan(root: str, ref: str) -> DefaultPlan:
def heading_commit(release: tuple[int, int, int], ref: str, cwd: str) -> str | None | Failure:
"""The oldest commit on ref that added release's dated heading to CHANGELOG.md, which a branch with no tag counts the unreleased commits from; None where git finds none."""
added = git("log", "--reverse", "--format=%H", "-S", f"## {version(release)} - ", ref, "--", "CHANGELOG.md", cwd=cwd)
# -G matches the heading line itself, so a changelog entry that quotes the heading doesn't count.
heading = "^## " + version(release).replace(".", "\\.") + " - [0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$"
added = git("log", "--reverse", "--format=%H", "-G", heading, ref, "--", "CHANGELOG.md", cwd=cwd)
return added if isinstance(added, Failure) else next(iter(added.split()), None)
@@ -160,29 +162,22 @@ def next_release(found: list[Item], cut: LastCut) -> Upcoming | Cut | Unknown:
if earliest is not None:
after.add(earliest)
release = min(after, default=None)
return Upcoming(release, earliest == release and (earliest is not None or version == BEFORE_FIRST_RELEASE), landed(cut))
nothing_cut = version == BEFORE_FIRST_RELEASE
return Upcoming(release, earliest == release and (earliest is not None or nothing_cut), landed(cut))
def cut_version(cut: LastCut) -> tuple[int, int, int] | None:
"""Which version is cut. It is the tag's, or None where the tag names no version. On a branch with no tag, it is the newest version under a dated CHANGELOG.md heading, else BEFORE_FIRST_RELEASE."""
if cut.tag is None:
return max(dated_headings(cut.changelog), default=BEFORE_FIRST_RELEASE)
return dated_cut(cut.tag, cut.changelog) or BEFORE_FIRST_RELEASE
return version_of(cut.tag)
def cut_name(cut: LastCut) -> str | None:
"""How the preflight names cut_version's cut: the tag, or the version under its dated heading; None where nothing is cut."""
if cut.tag is not None:
return None if isinstance(cut.tag, Failure) else cut.tag
headed = max(dated_headings(cut.changelog), default=None)
return None if headed is None else f"{version(headed)} (dated in CHANGELOG.md)"
def dated_headings(changelog: str | Failure) -> list[tuple[int, int, int]]:
"""Each version CHANGELOG.md heads `## X.Y.Z - YYYY-MM-DD`, the heading a cut release takes; an undated heading is not cut."""
if isinstance(changelog, Failure):
return []
return [release_of(dated[1]) for heading in sections(changelog) if (dated := re.fullmatch(r"([0-9]+\.[0-9]+\.[0-9]+) - [0-9]{4}-[0-9]{2}-[0-9]{2}", heading))]
def dated_cut(tag: str | None | Failure, changelog: str | Failure) -> tuple[int, int, int] | None:
"""The version a branch with no tag counts as cut: the newest CHANGELOG.md heads `## X.Y.Z - YYYY-MM-DD`, the heading a cut release takes. None where the branch has a tag, or CHANGELOG.md has no such heading; an undated heading is not cut."""
if tag is not None or isinstance(changelog, Failure):
return None
return max((release_of(dated[1]) for heading in sections(changelog) if (dated := re.fullmatch(r"([0-9]+\.[0-9]+\.[0-9]+) - [0-9]{4}-[0-9]{2}-[0-9]{2}", heading))), default=None)
def version_of(tag: str | None | Failure) -> tuple[int, int, int] | None: