Skip to content

fix(changelog): make prepare-changelog fail closed on content it cannot freeze - #1691

Merged
c-vigo merged 7 commits into
devfrom
bugfix/1689-prepare-changelog-loose-bullets
Sep 25, 2026
Merged

c-vigo merged 7 commits into
devfrom
bugfix/1689-prepare-changelog-loose-bullets

Conversation

@c-vigo

@c-vigo c-vigo commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Description

prepare-changelog validate and prepare-changelog prepare disagreed about what counts as content under ## Unreleased, and the gap destroyed entries silently. validate accepted any line starting with -; prepare froze only bullets under a recognised ### <Standard> subsection. A bullet written directly under the heading therefore passed validation, and prepare then 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 selects prepare by calling validate, which made both paths live.

This PR gives both commands one bounded body and one notion of content, and makes prepare fail closed: it never exits 0 having removed a bullet from ## Unreleased or from the folded ## [X.Y.Z] block.

Type of Change

  • fix -- Bug fix
  • test -- Adding or updating tests
  • docs -- Documentation only

Modifiers

  • Breaking change (!)

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.
  • validate now reports "has content" only when _parse_subsections finds something, i.e. exactly when prepare can 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.
  • prepare and seed share that guard through extract_unreleased_content, and prepare refuses 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.
  • The same guard covers the popped ## [X.Y.Z] - TBD block, and validate --version (the release-time gate) now uses _parse_subsections too, so it can no longer green-light a section a later prepare would empty.
  • Duplicate headings are refused rather than merged: a repeated ### Added is the signature of a mis-resolved changelog conflict, and stitching it back together would hide that from the author.
  • No workflow logic changes. The fix(ci): freeze main's carried changelog entries in the hotfix lane #1682 classifier treats any non-zero validate as "seed", and seed now refuses the same input, so the hotfix lane fails closed on its dry probe. Both prepare-hotfix.yml copies only had stale comments corrected; docs/RELEASE_CYCLE.md and docs/DOWNSTREAM_RELEASE.md updated to match (the "never call prepare on an empty Unreleased, it scoops the previous release" claim is retired because both halves are now false).
  • A regression guard pins that synthesize-bot-changelog's #### Dependencies block under ### Changed still counts as content.

Out of scope, pre-existing and unchanged: when ## Unreleased is not the first ## section, content above it is still discarded by prepare. The new docstring says so explicitly rather than claiming otherwise.

Changelog Entry

Fixed

  • prepare-changelog prepare no longer deletes entries it cannot freeze
    (#1689)
    • validate counted any line starting with - under ## Unreleased as
      content, while prepare only moved bullets sitting under a recognised
      ### <section> heading. A bullet written straight under ## Unreleased
      therefore passed validate, and prepare then wrote an empty
      ## [X.Y.Z] - TBD, reset ## Unreleased, dropped the bullet and exited
      0 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 selected prepare on exactly the input prepare could
      not freeze.
    • A bare ## Unreleased (no ### headings at all) was worse: the body
      capture was bounded by \n## [, a lookahead that cannot fire when the
      separating 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
      — validate reported content and prepare
      duplicated that release into the new version section.
    • Both commands now read one body bounded at the next ## heading and share
      one notion of content: "has content" means "prepare can freeze this".
      Bullets outside a recognised ### subsection are refused by validate,
      prepare and seed alike, naming every offending line and leaving the file
      untouched; prepare refuses when there is nothing to freeze instead of
      writing an empty section. The hotfix lane needs no change — validate
      exits 1, the classifier picks seed, and seed refuses the same input, so
      the lane fails closed instead of losing the entry.
    • The same guard now runs over the ## [X.Y.Z] block prepare folds back in
      on 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.yml and the scaffold's
      release-core.yml, reads content the same way, so it no longer blesses a
      section prepare would empty on the next cycle.
    • A repeated standard heading (### Added twice, the normal result of a
      hand-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

  • Tests pass locally (just test)
  • Manual testing performed (describe below)
PYTHONPATH=$PWD/packages/vig-utils/src uv run pytest packages/vig-utils/tests \
  tests/test_workflow_prepare_hotfix.py tests/test_release_time_changelog.py \
  tests/test_workflow_release_neutral.py -q      # 698 passed, exit 0
just precommit                                     # 53 hooks passed, exit 0

RED-first at both test commits: 17 failed / 142 passed at b1c9dfb9 against the pre-fix source, 11 failed / 161 passed at f93f9cf7.

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 ## Unreleased above 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 and validate --version exit 1); duplicate ### Added (was: second block deleted; now: refused naming the heading). The real devkit CHANGELOG.md still passes validate, prepare 9.9.9 and validate --version 9.9.9.

Local note: the nix devshell's PYTHONPATH puts a previously built vig-utils ahead 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.yml or release.yml dispatch. The fail-closed path is proven by unit and subprocess tests only.

Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have updated the documentation accordingly
  • I have updated CHANGELOG.md in the [Unreleased] section (and pasted the entry above)
  • My changes generate no new warnings or errors
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published

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 validate also exited 0 there), and this PR fixes both.

Refs: #1689

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 c-vigo added bug Something isn't working area:ci CI/CD, GitHub Actions, workflows labels Sep 25, 2026
@c-vigo
c-vigo enabled auto-merge September 25, 2026 07:48
@c-vigo
c-vigo merged commit 1d2e710 into dev Sep 25, 2026
12 checks passed
@c-vigo
c-vigo deleted the bugfix/1689-prepare-changelog-loose-bullets branch September 25, 2026 08:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:ci CI/CD, GitHub Actions, workflows bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant