@@ -184,7 +184,11 @@ async function runCanaryPublish({
184184}
185185
186186/** Runs the stable publish step over two packages with stubbed npm and pnpm. */
187- function runStablePublish ( { failingPackage = '' , failOnce = '' } = { } ) {
187+ function runStablePublish ( {
188+ failingPackage = '' ,
189+ failOnce = '' ,
190+ verifyExit = null ,
191+ } = { } ) {
188192 const root = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , 'astryx-stable-publish-' ) ) ;
189193 const publishLog = path . join ( root , 'publish.log' ) ;
190194 try {
@@ -212,6 +216,9 @@ function runStablePublish({failingPackage = '', failOnce = ''} = {}) {
212216 writeExecutable ( root , 'npm' , '#!/bin/sh\nexit 1\n' ) ;
213217 writeExecutable ( root , 'pnpm' , PNPM_STUB ) ;
214218 const publisherEnv = withPublisher ( root ) ;
219+ if ( verifyExit !== null ) writeVerifierStub ( root , verifyExit ) ;
220+ const githubOutput = path . join ( root , 'github-output' ) ;
221+ fs . writeFileSync ( githubOutput , '' ) ;
215222 const result = spawnSync (
216223 'bash' ,
217224 [ '-c' , step ( stable , 'Publish changed packages' ) . run ] ,
@@ -224,6 +231,7 @@ function runStablePublish({failingPackage = '', failOnce = ''} = {}) {
224231 DRY_RUN : 'false' ,
225232 FAIL_ONCE : failOnce ,
226233 FAIL_PACKAGE : failingPackage ,
234+ GITHUB_OUTPUT : githubOutput ,
227235 PATH : `${ path . join ( root , 'bin' ) } :${ process . env . PATH } ` ,
228236 PUBLISH_LOG : publishLog ,
229237 RELEASE_VERSION : '0.7.7' ,
@@ -232,6 +240,7 @@ function runStablePublish({failingPackage = '', failOnce = ''} = {}) {
232240 ) ;
233241 return {
234242 ...result ,
243+ output : fs . readFileSync ( githubOutput , 'utf8' ) ,
235244 published : fs . existsSync ( publishLog )
236245 ? fs . readFileSync ( publishLog , 'utf8' )
237246 : '' ,
@@ -241,6 +250,39 @@ function runStablePublish({failingPackage = '', failOnce = ''} = {}) {
241250 }
242251}
243252
253+ /** A registry verifier stand-in that exits with `code`. */
254+ function writeVerifierStub ( root , code ) {
255+ const file = path . join ( root , 'scripts/npm/verify-published.mjs' ) ;
256+ fs . mkdirSync ( path . dirname ( file ) , { recursive : true } ) ;
257+ fs . writeFileSync ( file , `process.exit(${ code } );\n` ) ;
258+ }
259+
260+ /** Runs one follow-up verification job's script with a verifier stand-in. */
261+ function runFollowUp ( job , verifyExit ) {
262+ const root = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , 'astryx-verify-' ) ) ;
263+ try {
264+ writeVerifierStub ( root , verifyExit ) ;
265+ const githubOutput = path . join ( root , 'github-output' ) ;
266+ fs . writeFileSync ( githubOutput , '' ) ;
267+ const result = spawnSync (
268+ 'bash' ,
269+ [ '-c' , step ( job , 'Verify published packages' ) . run ] ,
270+ {
271+ cwd : root ,
272+ encoding : 'utf8' ,
273+ env : {
274+ ...process . env ,
275+ GITHUB_OUTPUT : githubOutput ,
276+ RELEASE_VERSION : '0.7.7' ,
277+ } ,
278+ } ,
279+ ) ;
280+ return { ...result , output : fs . readFileSync ( githubOutput , 'utf8' ) } ;
281+ } finally {
282+ fs . rmSync ( root , { recursive : true , force : true } ) ;
283+ }
284+ }
285+
244286describe ( 'stable and canary publication authority' , ( ) => {
245287 it ( 'keeps stable explicit and canary limited to main pushes' , ( ) => {
246288 expect ( stable . if ) . toBe ( "github.event_name == 'workflow_dispatch'" ) ;
@@ -609,4 +651,97 @@ describe('stable publish requires the cut commit release-check (spec:AST-030 FR1
609651 expect ( stable . steps [ guard ] [ 'continue-on-error' ] ) . toBeUndefined ( ) ;
610652 expect ( stable . permissions . actions ) . toBe ( 'read' ) ;
611653 } ) ;
654+
655+ it ( 'passes the release when every package is readable in the first window' , ( ) => {
656+ const result = runStablePublish ( { verifyExit : 0 } ) ;
657+
658+ expect ( result . status ) . toBe ( 0 ) ;
659+ expect ( result . output ) . toContain ( 'verified=true' ) ;
660+ } ) ;
661+
662+ it ( 'ends the publish job as "not yet readable", not failed, and hands over to a follow-up' , ( ) => {
663+ const result = runStablePublish ( { verifyExit : 2 } ) ;
664+
665+ expect ( result . status ) . toBe ( 0 ) ;
666+ expect ( result . output ) . toContain ( 'verified=pending' ) ;
667+ expect ( result . stdout ) . toContain ( 'not yet readable on the registry' ) ;
668+ } ) ;
669+
670+ it ( 'still fails the publish job on a verification error' , ( ) => {
671+ const result = runStablePublish ( { verifyExit : 1 } ) ;
672+
673+ expect ( result . status ) . toBe ( 1 ) ;
674+ expect ( result . output ) . not . toContain ( 'verified=' ) ;
675+ } ) ;
676+
677+ it ( 'runs at most two bounded follow-up verification jobs, each only while packages are pending' , ( ) => {
678+ const first = workflow . jobs [ 'verify-registry-1' ] ;
679+ const last = workflow . jobs [ 'verify-registry-2' ] ;
680+ const followUps = Object . keys ( workflow . jobs ) . filter ( name =>
681+ name . startsWith ( 'verify-registry' ) ,
682+ ) ;
683+
684+ expect ( followUps ) . toEqual ( [ 'verify-registry-1' , 'verify-registry-2' ] ) ;
685+ expect ( stable . outputs . verified ) . toBe (
686+ '${{ steps.publish.outputs.verified }}' ,
687+ ) ;
688+ expect ( first . needs ) . toBe ( 'publish' ) ;
689+ expect ( first . if ) . toBe ( "needs.publish.outputs.verified == 'pending'" ) ;
690+ expect ( last . needs ) . toBe ( 'verify-registry-1' ) ;
691+ expect ( last . if ) . toBe (
692+ "needs.verify-registry-1.outputs.verified == 'pending'" ,
693+ ) ;
694+ for ( const job of [ first , last ] ) {
695+ expect ( job [ 'runs-on' ] ) . toBe ( 'ubuntu-latest' ) ;
696+ expect ( job [ 'timeout-minutes' ] ) . toBeLessThanOrEqual ( 10 ) ;
697+ expect ( job . permissions ) . toEqual ( { contents : 'read' } ) ;
698+ expect ( step ( job , 'Verify published packages' ) . run ) . toContain (
699+ 'node scripts/npm/verify-published.mjs --version "$RELEASE_VERSION" --tag latest --window-ms 420000' ,
700+ ) ;
701+ }
702+ } ) ;
703+
704+ it ( 'hands a still-pending check from the first follow-up to the last one' , ( ) => {
705+ const pending = runFollowUp ( workflow . jobs [ 'verify-registry-1' ] , 2 ) ;
706+ expect ( pending . status ) . toBe ( 0 ) ;
707+ expect ( pending . output ) . toContain ( 'verified=pending' ) ;
708+
709+ const readable = runFollowUp ( workflow . jobs [ 'verify-registry-1' ] , 0 ) ;
710+ expect ( readable . status ) . toBe ( 0 ) ;
711+ expect ( readable . output ) . toContain ( 'verified=true' ) ;
712+ } ) ;
713+
714+ it ( 'fails the release when the last follow-up still finds a package unreadable' , ( ) => {
715+ const result = runFollowUp ( workflow . jobs [ 'verify-registry-2' ] , 2 ) ;
716+
717+ expect ( result . status ) . toBe ( 2 ) ;
718+ expect ( result . stdout ) . toContain (
719+ 'still not readable on the registry after three verification windows' ,
720+ ) ;
721+ } ) ;
722+
723+ it ( 'lets nothing act on a stable release before the final verification decides the run' , ( ) => {
724+ // Every job that depends on the publish job is the next verification
725+ // window, so no release step can start on the publish job's pass alone.
726+ const dependents = name =>
727+ Object . entries ( workflow . jobs )
728+ . filter ( ( [ , job ] ) => [ job . needs ] . flat ( ) . includes ( name ) )
729+ . map ( ( [ jobName ] ) => jobName ) ;
730+ expect ( dependents ( 'publish' ) ) . toEqual ( [ 'verify-registry-1' ] ) ;
731+ expect ( dependents ( 'verify-registry-1' ) ) . toEqual ( [ 'verify-registry-2' ] ) ;
732+ expect ( dependents ( 'verify-registry-2' ) ) . toEqual ( [ ] ) ;
733+
734+ // Pending in the publish job and in follow-up 1, still unreadable in
735+ // follow-up 2: the run ends failed, so anything that waits for the run's
736+ // conclusion does not proceed.
737+ const publish = runStablePublish ( { verifyExit : 2 } ) ;
738+ const first = runFollowUp ( workflow . jobs [ 'verify-registry-1' ] , 2 ) ;
739+ const last = runFollowUp ( workflow . jobs [ 'verify-registry-2' ] , 2 ) ;
740+ const jobResults = [ publish . status , first . status , last . status ] ;
741+ expect ( jobResults ) . toEqual ( [ 0 , 0 , 2 ] ) ;
742+ expect ( jobResults . some ( status => status !== 0 ) ) . toBe ( true ) ;
743+ expect ( stable . outputs . verified ) . toBeDefined ( ) ;
744+ expect ( publish . output ) . toContain ( 'verified=pending' ) ;
745+ expect ( first . output ) . toContain ( 'verified=pending' ) ;
746+ } ) ;
612747} ) ;
0 commit comments