Repository navigation
fix(changelog): make prepare-changelog fail closed on content it cannot freeze - #1691
Merged
Merged
Conversation
prepare-changelog validate reports "has content" for any line starting with a dash under ## Unreleased, while prepare only freezes bullets that sit under a recognised "### <section>" heading. The gap lets prepare exit 0 having deleted the entry, and the #1682 hotfix classifier selects prepare on exactly the input prepare cannot freeze. The bare ## Unreleased shape is worse than the issue describes. The body regex is bounded by a literal newline plus "## [", and with an empty body that separating newline is already consumed by the heading's own "\s*\n", so the capture runs to end of file and both validate and prepare read the PREVIOUS release's subsections as unreleased content. validate therefore returns 0 there as well, so the classifier does not mask the duplication after all. These tests fail on the current implementation. Refs: #1689
…ntent validate and prepare disagreed about what counts as content under ## Unreleased, and the gap destroyed entries. validate accepted any line starting with a dash; prepare only moved bullets sitting under a recognised "### <section>" heading. A loose bullet therefore passed validate and was deleted by prepare, which exited 0 with a warning, and the #1682 hotfix classifier selected prepare on exactly that input. Both commands now read one bounded Unreleased body and share one notion of content: - _unreleased_body bounds the capture at the next "## " heading. The old "\n## [" lookahead could not fire on a bare ## Unreleased, because the separating newline was consumed by the heading match itself, so the capture ran to end of file and the previous release's subsections were read as unreleased content. That made validate report content and prepare duplicate the previous release into the new version section. - _reject_loose_bullets refuses, leaving the file untouched, when the body holds bullets no recognised "### " subsection owns, naming every offending line. It runs from extract_unreleased_content (prepare and seed) and from validate_changelog. - validate's has_content is now _parse_subsections, so "has content" means exactly "prepare can freeze this". - prepare refuses when there is nothing to freeze instead of writing an empty ## [X.Y.Z] - TBD and warning on stdout, which only deferred the failure to release.yml's validate --version. cmd_prepare's empty branch is therefore unreachable and goes. No caller depends on prepare succeeding on an empty section: every prepare call is gated by a validate that refuses one. prepare-release.yml validates before preparing in both trees, and the #1682 classifier in prepare-hotfix.yml routes an empty section to seed. justfile.gh only calls reset. No workflow change is needed for the loose-bullet path either. validate exits 1, so the classifier picks seed, and seed now refuses the same input through the shared guard, failing the dry probe loudly under set -euo pipefail rather than wiping the entry. Refs: #1689
Both hazards belong in the entry: the loose bullet validate accepted and prepare deleted, and the bare ## Unreleased whose unbounded body capture made prepare duplicate the previous release. The mirror under assets/workspace/.devcontainer/ is the sync-manifest hook's output. Refs: #1689
The docstring is not raw, so the backslash-n written to describe the old lookahead rendered as a real newline mid-sentence. Describe it in words instead. Refs: #1689
Review of the #1689 branch found the same invariant broken in two more places, both silently at rc 0: - _pop_version_section folds an existing ## [X.Y.Z] block back in through _parse_subsections, so a bullet written directly under that heading — the shape docs/DOWNSTREAM_RELEASE.md tells hotfix authors to write, and the one a reused release branch re-prepares — is dropped while the command reports "Moved N section(s)". validate --version blesses it too, so the release-time gate disagrees with prepare. - _parse_subsections searches once per section name, so only the FIRST ### Added block is read; _find_loose_bullets sees a recognised heading and reports nothing loose. A heading duplicated by a hand-resolved merge conflict therefore loses its second block. Two of the added tests are green already and stay as regression guards: synthesize-bot-changelog writes its bullets under a #### Dependencies heading inside ### Changed, and that must keep counting as content in both the Unreleased and the pending-version paths. Refs: #1689
_reject_loose_bullets becomes _reject_unparsable_body and gains a duplicate-heading check, and now runs over both sections that _parse_subsections reads: - _pop_version_section guards the popped ## [X.Y.Z] block before folding it into the new version section, closing the twin of the Unreleased path. This is the shape docs/DOWNSTREAM_RELEASE.md asks hotfix authors to hand-write, and the scaffold's prepare-release.yml re-prepares it on a reused release branch. - validate_version_section reads content through _parse_subsections instead of a bare bullet search, so the release-time gate agrees with the tool that rewrites the section. Its two callers, release.yml and the scaffold's release-core.yml, only read the exit code under set -euo pipefail, so the contract is unchanged: 0 passes, non-zero refuses. It tightens rather than loosens — the sections it now refuses are exactly the ones prepare would silently empty on the next cycle. Duplicate standard headings REFUSE rather than merge. Merging the blocks would work and would preserve within-section order, but the file is a record: a repeated heading means a merge conflict was resolved wrongly, and quietly stitching it back together hides that from the author while _merge_sections' dedupe swallows the duplicated bullets such a resolution usually carries too. Refusing is also the smaller, auditable change, and the remedy is one local edit. This matches the rest of #1689: every shape _parse_subsections cannot fully see is refused, never repaired. synthesize_bot_changelog writes its bullets under a fourth-level Dependencies heading inside the Changed section; that heading is neither a subsection boundary nor a recognised heading here, so the generated block keeps counting as content in both paths (regression-guarded). Refs: #1689
The SSoT rule puts these with the code that invalidated them. Three statements were false or incomplete after the guard landed: - RELEASE_CYCLE.md's `prepare` entry said never to call it on an empty ## Unreleased because it scoops the previous release's section. Both halves are gone: _unreleased_body bounds the capture so nothing is scooped, and prepare refuses an empty section outright. Replaced with what it actually refuses, and a pointer to seed. - RELEASE_CYCLE.md's `validate` entry and the fix-PR contract in both RELEASE_CYCLE.md and DOWNSTREAM_RELEASE.md said the gate only checks non-emptiness. It now also requires bullets under a recognised ### heading, which is what lets prepare-hotfix.yml classify with validate and trust the verdict. - Both prepare-hotfix.yml copies carried the same scooping claim in the classifier comment. Updated in lockstep, along with the dry-probe comment listing what the probe refuses, and the else-branch echo, which announced main's Unreleased as empty before the probe could refuse it for a different reason. The prepare docstring is scoped to what is now guaranteed — no bullet lost from ## Unreleased or the folded ## [version] block — and states what is not: content above ## Unreleased is still discarded, as it always was, since create_new_changelog rebuilds the file from a fixed header. That is pre-existing and untouched here. The CHANGELOG entry gains sub-bullets for the version-block twin and the duplicate-heading refusal. The assets/workspace mirrors are the sync-manifest hook's output. Refs: #1689
c-vigo
enabled auto-merge
September 25, 2026 07:48
This was referenced Sep 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
prepare-changelog validateandprepare-changelog preparedisagreed about what counts as content under## Unreleased, and the gap destroyed entries silently.validateaccepted any line starting with-;preparefroze only bullets under a recognised### <Standard>subsection. A bullet written directly under the heading therefore passed validation, andpreparethen wrote the new version section empty, dropped the bullet, and exited 0 with only a warning. The same body regex was also unbounded on a bare## Unreleased, so the previous release's bullets were parsed as unreleased content and duplicated into the new section. Since #1682 the hotfix classifier selectsprepareby callingvalidate, which made both paths live.This PR gives both commands one bounded body and one notion of content, and makes
preparefail closed: it never exits 0 having removed a bullet from## Unreleasedor from the folded## [X.Y.Z]block.Type of Change
fix-- Bug fixtest-- Adding or updating testsdocs-- Documentation onlyModifiers
!)Changes Made
_unreleased_body()bounds the Unreleased capture at the next top-level##heading, so a bare section can no longer swallow the release below it.validatenow reports "has content" only when_parse_subsectionsfinds something, i.e. exactly whenpreparecan freeze it. Loose bullets (outside a recognised###subsection) and duplicated standard headings are refused with exit 1 and a message naming the offending lines or headings.prepareandseedshare that guard throughextract_unreleased_content, andpreparerefuses when there is nothing to freeze instead of writing an empty section. The check runs after_pop_version_section, so the [BUG] Smoke-test dispatch not idempotent across candidate→final on same base version #612 reused-release-branch fold still works.## [X.Y.Z] - TBDblock, andvalidate --version(the release-time gate) now uses_parse_subsectionstoo, so it can no longer green-light a section a laterpreparewould empty.### Addedis the signature of a mis-resolved changelog conflict, and stitching it back together would hide that from the author.validateas "seed", andseednow refuses the same input, so the hotfix lane fails closed on its dry probe. Bothprepare-hotfix.ymlcopies only had stale comments corrected;docs/RELEASE_CYCLE.mdanddocs/DOWNSTREAM_RELEASE.mdupdated to match (the "never call prepare on an empty Unreleased, it scoops the previous release" claim is retired because both halves are now false).synthesize-bot-changelog's#### Dependenciesblock under### Changedstill counts as content.Out of scope, pre-existing and unchanged: when
## Unreleasedis not the first##section, content above it is still discarded byprepare. The new docstring says so explicitly rather than claiming otherwise.Changelog Entry
Fixed
prepare-changelog prepareno longer deletes entries it cannot freeze(#1689)
validatecounted any line starting with-under## Unreleasedascontent, while
prepareonly moved bullets sitting under a recognised### <section>heading. A bullet written straight under## Unreleasedtherefore passed
validate, andpreparethen wrote an empty## [X.Y.Z] - TBD, reset## Unreleased, dropped the bullet and exited0 with a warning. fix(ci): freeze main's carried changelog entries in the hotfix lane #1682's classifier picks its mode by calling
validate, so it selectedprepareon exactly the inputpreparecouldnot freeze.
## Unreleased(no###headings at all) was worse: the bodycapture was bounded by
\n## [, a lookahead that cannot fire when theseparating newline is already consumed by the heading match, so the capture
ran to end of file and the previous release's entries were read as
unreleased content —
validatereported content andprepareduplicated that release into the new version section.
##heading and shareone notion of content: "has content" means "
preparecan freeze this".Bullets outside a recognised
###subsection are refused byvalidate,prepareandseedalike, naming every offending line and leaving the fileuntouched;
preparerefuses when there is nothing to freeze instead ofwriting an empty section. The hotfix lane needs no change —
validateexits 1, the classifier picks
seed, andseedrefuses the same input, sothe lane fails closed instead of losing the entry.
## [X.Y.Z]blockpreparefolds back inon a reused release branch, closing the twin of the bug: a bullet written
straight under the version heading — the shape the hotfix runbook asks
authors to fill in — was dropped just as silently.
validate --version,the release-time gate in
release.ymland the scaffold'srelease-core.yml, reads content the same way, so it no longer blesses asection
preparewould empty on the next cycle.### Addedtwice, the normal result of ahand-resolved merge conflict) is refused as well. Only the first block of
each heading was ever read, so the rest was deleted at exit 0. It refuses
rather than merging the blocks: a repeated heading means an edit went
wrong, and quietly stitching it back together would hide that.
Testing
just test)RED-first at both test commits: 17 failed / 142 passed at
b1c9dfb9against the pre-fix source, 11 failed / 161 passed atf93f9cf7.Manual Testing Details
CLI runs on fixture changelogs, before and after: loose bullet under
## Unreleased(was: validate 0, prepare 0, bullet deleted; now: both exit 1, file byte-identical); bare## Unreleasedabove a release (was: validate 0, prepare duplicated the release; now: validate 1, prepare refuses, seed succeeds); loose bullet inside## [1.0.1] - TBD(was: deleted at exit 0; now: prepare andvalidate --versionexit 1); duplicate### Added(was: second block deleted; now: refused naming the heading). The real devkitCHANGELOG.mdstill passesvalidate,prepare 9.9.9andvalidate --version 9.9.9.Local note: the nix devshell's
PYTHONPATHputs a previously builtvig-utilsahead of the editable install for subprocesses, so the CLI subprocess tests need the prefix shown above locally. CI builds the devshell from the branch.Not exercised: a live
prepare-hotfix.ymlorrelease.ymldispatch. The fail-closed path is proven by unit and subprocess tests only.Checklist
CHANGELOG.mdin the[Unreleased]section (and pasted the entry above)Additional Notes
The issue text originally called the bare-Unreleased duplication "masked by the classifier"; a follow-up comment on #1689 corrects that (the old
validatealso exited 0 there), and this PR fixes both.Refs: #1689