@@ -403,6 +403,46 @@ it.effect("waits for Retry-After before retrying a rate-limited message", () =>
403403 } ) ,
404404) ;
405405
406+ it . effect ( "bounds total retry time while preserving delays within the deadline" , ( ) =>
407+ Effect . gen ( function * ( ) {
408+ const limited = yield * Deferred . make < void > ( ) ;
409+ let attempts = 0 ;
410+ const client = Layer . succeed (
411+ HttpClient . HttpClient ,
412+ HttpClient . make ( ( request ) =>
413+ Effect . gen ( function * ( ) {
414+ attempts += 1 ;
415+ yield * Deferred . succeed ( limited , undefined ) ;
416+ return HttpClientResponse . fromWeb (
417+ request ,
418+ new Response ( null , { status : 429 , headers : { "retry-after" : "40" } } ) ,
419+ ) ;
420+ } ) ,
421+ ) ,
422+ ) ;
423+ const fiber = yield * postDiscordWebhook (
424+ webhookUrl ,
425+ buildDiscordReleaseAnnouncement ( latestAnnouncement ) [ 0 ] ! ,
426+ latestAnnouncement ,
427+ ) . pipe ( Effect . provide ( client ) , Effect . result , Effect . forkChild ) ;
428+ yield * Deferred . await ( limited ) ;
429+ yield * TestClock . adjust ( "39 seconds" ) ;
430+ assert . equal ( attempts , 1 ) ;
431+ yield * TestClock . adjust ( "1 second" ) ;
432+ assert . equal ( attempts , 2 ) ;
433+ yield * TestClock . adjust ( "20 seconds" ) ;
434+ const result = yield * Fiber . join ( fiber ) ;
435+ assert . equal ( attempts , 2 ) ;
436+ assert . equal ( result . _tag , "Failure" ) ;
437+ if ( result . _tag !== "Failure" ) assert . fail ( "Expected the retry deadline to expire" ) ;
438+ assert . equal ( result . failure . _tag , "DiscordReleaseWebhookRequestError" ) ;
439+ if ( result . failure . _tag !== "DiscordReleaseWebhookRequestError" )
440+ assert . fail ( `Unexpected error: ${ result . failure . _tag } ` ) ;
441+ assert . equal ( result . failure . reason , "TimeoutError" ) ;
442+ assert . ok ( ! Cause . pretty ( Cause . fail ( result . failure ) ) . includes ( "test-secret-token" ) ) ;
443+ } ) ,
444+ ) ;
445+
406446// Run the checked-in shell commands with gh/node stubs, then send their captured
407447// arguments through the real CLI parser and an injected HTTP client.
408448function workflowRun ( workflow : string , stepName : string ) {
@@ -494,20 +534,31 @@ it.layer(NodeServices.layer)("Discord release CLI and workflow", (it) => {
494534 0 ,
495535 ) ;
496536 assert . equal ( yield * fs . readFileString ( `${ temp } /discord-release-notes.md` ) , "" ) ;
497- // A failed fetch must skip the announcement, rather than send the empty
498- // file created by shell redirection before gh failed.
499537 assert . equal (
500538 yield * spawner . exitCode (
501- ChildProcess . make ( "bash" , [ "-e" , "-c" , `gh() { return 42; }\n${ read } ` ] , {
502- env : shellEnv ,
503- } ) ,
539+ ChildProcess . make (
540+ "bash" ,
541+ [ "-e" , "-c" , `gh() { printf '%s' 'partial changelog'; return 42; }\n${ read } ` ] ,
542+ { env : shellEnv } ,
543+ ) ,
504544 ) ,
505- 42 ,
545+ 0 ,
506546 ) ;
547+ assert . equal ( yield * fs . readFileString ( `${ temp } /discord-release-notes.md` ) , "" ) ;
548+ const fallbackRequests : string [ ] = [ ] ;
549+ yield * runCli ( args ) . pipe ( Effect . provide ( [ configLayer , captureClient ( fallbackRequests ) ] ) ) ;
550+ assert . equal ( fallbackRequests . length , 1 ) ;
551+ const fallback = decodePayload ( fallbackRequests [ 0 ] ! ) ;
552+ assert . equal ( fallback . embeds [ 0 ] ?. description , intro ) ;
553+ assert . equal ( fallback . content , `-# <@&${ latestAnnouncement . roleId } >` ) ;
554+ assert . deepStrictEqual ( fallback . allowed_mentions , {
555+ parse : [ ] ,
556+ roles : [ latestAnnouncement . roleId ] ,
557+ } ) ;
507558 assert . ok (
508- workflow . includes (
509- "if: needs.preflight.outputs.is_prerelease == 'true' && steps.discord_release_notes.outcome == 'success'" ,
510- ) ,
559+ workflow
560+ . split ( " - name: Announce prerelease on Discord\n" ) [ 1 ]
561+ ?. startsWith ( " if: needs.preflight.outputs.is_prerelease == 'true'\n" ) ,
511562 ) ;
512563 assert . ok ( workflow . includes ( "GH_REPO: ${{ github.repository }}" ) ) ;
513564 assert . ok ( workflow . includes ( "RELEASE_TAG: ${{ needs.preflight.outputs.tag }}" ) ) ;
0 commit comments