@@ -36,6 +36,8 @@ const SCRIPT = readFileSync(resolve(REPO, "scripts/finish-release.mjs"), "utf8")
3636const MAVEN_COORD = readFileSync ( resolve ( REPO , "scripts/maven-coordinate.mjs" ) , "utf8" ) ;
3737// Gate 0 asks the eject release gate, and the fixture ships the real one for the same reason.
3838const EJECT_GATE = readFileSync ( resolve ( REPO , "scripts/eject-release-gate.mjs" ) , "utf8" ) ;
39+ // Gate 1's branch rule, shared with release.mjs — the real module, for the same reason.
40+ const RELEASE_BRANCH = readFileSync ( resolve ( REPO , "scripts/lib/release-branch.mjs" ) , "utf8" ) ;
3941const EJECT_MANIFEST = "fixtures/generator-registry-conformance/registry.json" ;
4042/** The shared file as the release branch leaves it: nothing pending. */
4143const EJECT_CLEAR = `${ JSON . stringify ( { eject : { pending : [ ] } } ) } \n` ;
@@ -173,6 +175,7 @@ function makeRepo(spec: Spec = {}): Fixture {
173175 "scripts/finish-release.mjs" : SCRIPT ,
174176 "scripts/maven-coordinate.mjs" : MAVEN_COORD ,
175177 "scripts/eject-release-gate.mjs" : EJECT_GATE ,
178+ "scripts/lib/release-branch.mjs" : RELEASE_BRANCH ,
176179 } ) ) {
177180 const full = join ( work , rel ) ;
178181 mkdirSync ( dirname ( full ) , { recursive : true } ) ;
@@ -291,6 +294,46 @@ describe("finish-release gate 1: the tree that will be tagged", () => {
291294 expect ( r . out ) . toContain ( "HEAD is not origin/main" ) ;
292295 } ) ;
293296
297+ // A maintenance branch `release/<major>.<minor>` may tag a patch on its own line; the
298+ // rule itself is unit-tested in scripts/test-release-branch.mjs. These cases prove the
299+ // script wires it: the branch is accepted, a version off its line is refused, and the
300+ // sync check compares against origin/<that branch>, never origin/main.
301+ const onMaintenance = ( name : string , push = true ) => {
302+ const f = makeRepo ( ) ;
303+ f . git ( f . work , "checkout" , "--quiet" , "-b" , name ) ;
304+ if ( push ) f . git ( f . work , "push" , "--quiet" , "-u" , "origin" , name ) ;
305+ return f ;
306+ } ;
307+
308+ test ( "a maintenance branch on the release's own line passes gate 1" , ( ) => {
309+ const r = onMaintenance ( "release/0.24" ) . run ( RELEASE , "--check" ) ;
310+ expect ( r . out ) . toContain ( "on release/0.24, clean, synced with origin" ) ;
311+ expect ( r . code ) . toBe ( 0 ) ;
312+ } ) ;
313+
314+ test ( "a maintenance branch refuses a version off its line" , ( ) => {
315+ const r = onMaintenance ( "release/0.23" ) . run ( RELEASE , "--check" ) ;
316+ expect ( r . code ) . not . toBe ( 0 ) ;
317+ expect ( r . out ) . toContain ( "cuts only 0.23.x" ) ;
318+ expect ( r . out ) . not . toContain ( "synced with origin" ) ;
319+ } ) ;
320+
321+ test ( "a maintenance branch syncs against its OWN remote, not origin/main" , ( ) => {
322+ const f = onMaintenance ( "release/0.24" ) ;
323+ writeFileSync ( join ( f . work , "NOTES.md" ) , "unpushed\n" ) ;
324+ f . git ( f . work , "add" , "-A" ) ;
325+ f . git ( f . work , "commit" , "--quiet" , "-m" , "local only" ) ;
326+ const r = f . run ( RELEASE , "--check" ) ;
327+ expect ( r . code ) . not . toBe ( 0 ) ;
328+ expect ( r . out ) . toContain ( "HEAD is not origin/release/0.24" ) ;
329+ } ) ;
330+
331+ test ( "a maintenance branch never pushed is refused, not crashed on" , ( ) => {
332+ const r = onMaintenance ( "release/0.24" , false ) . run ( RELEASE , "--check" ) ;
333+ expect ( r . code ) . not . toBe ( 0 ) ;
334+ expect ( r . out ) . toContain ( "HEAD is not origin/release/0.24" ) ;
335+ } ) ;
336+
294337 // The defect: the fetch was `|| true`, so a failure left `origin/main` at a stale
295338 // remote-tracking ref and the very next line printed "synced with origin" having
296339 // verified nothing. The realistic case is the port-bump commit pushed from another
@@ -647,6 +690,21 @@ describe("finish-release gate 7: cutting the tag", () => {
647690 expect ( f . git ( f . origin , "tag" , "-l" ) ) . toContain ( `v${ RELEASE } ` ) ;
648691 } ) ;
649692
693+ test ( "tags and pushes from a maintenance branch, leaving origin/main where it was" , ( ) => {
694+ const f = makeRepo ( ) ;
695+ const mainBefore = f . git ( f . origin , "rev-parse" , "main" ) ;
696+ f . git ( f . work , "checkout" , "--quiet" , "-b" , "release/0.24" ) ;
697+ writeFileSync ( join ( f . work , "NOTES.md" ) , "the patch\n" ) ;
698+ f . git ( f . work , "add" , "-A" ) ;
699+ f . git ( f . work , "commit" , "--quiet" , "-m" , "patch on the maintenance line" ) ;
700+ f . git ( f . work , "push" , "--quiet" , "-u" , "origin" , "release/0.24" ) ;
701+ const r = f . run ( RELEASE ) ;
702+ expect ( r . out ) . toContain ( `cut and pushed v${ RELEASE } ` ) ;
703+ expect ( r . code ) . toBe ( 0 ) ;
704+ expect ( f . git ( f . origin , "rev-parse" , `v${ RELEASE } ^{commit}` ) ) . toBe ( f . git ( f . work , "rev-parse" , "HEAD" ) ) ;
705+ expect ( f . git ( f . origin , "rev-parse" , "main" ) ) . toBe ( mainBefore ) ;
706+ } ) ;
707+
650708 test ( "--check cuts nothing" , ( ) => {
651709 const f = makeRepo ( ) ;
652710 expect ( f . run ( RELEASE , "--check" ) . code ) . toBe ( 0 ) ;
0 commit comments