fix(ci): Enforce canonical region order in stacked-PR bodies#63
Merged
Conversation
Stacked-PR bodies carry three managed regions — the stack breadcrumb, the human description, and carried-forward <!-- PR:N --> legacy — but their order was emergent: spliceRegion and upsertCarriedRegion replaced in place or appended, so a region stayed wherever it first landed. Add canonicalizeBody as the single layout authority: breadcrumb → description → carried-forward (ascending PR#). Route the sync path (planUpdate/reconcile) and the merge path (carryForward) through it so both converge to the same canonical body, and a git town sync reformats an existing PR — the one moment the order matters. A body with no managed regions is returned untouched, so plain non-stacked PRs are never rewritten. Retire spliceRegion, now subsumed. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR formalizes a canonical layout for stacked-PR bodies by introducing canonicalizeBody as the single authority for ordering managed regions, and routes both sync-time reconciliation and merge-time carry-forward through it to ensure deterministic, convergent formatting.
Changes:
- Introduces
canonicalizeBodyto enforcebreadcrumb → description → carried-forwardordering (with carried regions sorted by PR number). - Updates sync-time body planning (
planUpdate) to reflow existing out-of-order bodies into canonical order. - Updates merge-time carry-forward (
carryForward) to canonicalize the final parent body so merge and sync paths converge.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| .github/scripts/stack-breadcrumb.cjs | Adds canonicalizeBody, removes spliceRegion, and routes reconcile + carry-forward through canonical layout. |
| .github/scripts/stack-breadcrumb.test.cjs | Replaces spliceRegion tests with coverage for canonical ordering, idempotence, carried sorting, and sync/merge convergence. |
canonicalizeBody derives the description via ownDescription, which used .trim() — stripping leading indentation from a managed PR's prose, so a description opening with an indented Markdown code block could be silently reflowed. Tidy only the whitespace the region surgery introduces: collapse seams, drop leading blank lines, and trim trailing whitespace, leaving the first line's indentation intact. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Formalizes the order the managed regions appear in a stacked-PR body, and makes a stack sync reformat existing PRs to that order.
A stacked-PR body carries up to three managed regions: the stack breadcrumb (
<!-- stack … -->), the human description, and carried-forward legacy (<!-- PR:N -->blocks, a merged child's body accumulated into its surviving parent). Their order was never defined —spliceRegionandupsertCarriedRegionboth replace-in-place when the region exists and otherwise append, so a region stayed wherever it first landed. Depending on authoring history a PR could open with the breadcrumb, the description, or the legacy first, and reconcile only ever swapped content in place, never re-sorted.This adds
canonicalizeBodyas the single layout authority and fixes the order to breadcrumb → description → carried-forward (carried sorted ascending by PR number). Both writers route through it:planUpdate→reconcile): agit town sync/ shape-change reconcile now also normalizes layout — the one moment the region order actually matters, per the discussion that prompted this.carryForward): ends with the same canonicalization, preserving the existing breadcrumb, so whichever of the two jobs writes the parent body last, the result is the same canonical string (race-safe, idempotent, convergent).canonicalizeBodyreturns a body with nothing managed (no breadcrumb to place, none present, no carried regions) byte-for-byte untouched, so a plain non-stacked PR's description is never rewritten — this preserves the oldspliceRegionno-op that kept reconcile from churning ordinary PRs.spliceRegionis retired (its in-place semantics were exactly why order was never enforced); its meaningful invariants moved intocanonicalizeBodytests.Reviewer notes:
breadcrumb → descriptionflip is the visible behavior change; existing PRs re-sort on their next stack sync, not retroactively..github/scripts/*.cjs), no published package touched, so no changeset.node --testcases pass; both files are prettier-clean.🤖 Generated with Claude Code