@@ -499,7 +499,7 @@ describe("PullRequestSyncReactor", () => {
499499 ) ,
500500 ) ;
501501
502- it . effect ( "asks the host once for a pull request shared by two threads" , ( ) =>
502+ it . effect ( "asks the host once for a pull request shared by two threads in one project " , ( ) =>
503503 Effect . scoped (
504504 Effect . gen ( function * ( ) {
505505 yield * TestClock . setTime ( Date . parse ( NOW ) ) ;
@@ -516,6 +516,7 @@ describe("PullRequestSyncReactor", () => {
516516 yield * startAndSweep ( fixture ) ;
517517
518518 assert . strictEqual ( ( yield * Ref . get ( fixture . summaryCalls ) ) . length , 1 ) ;
519+ assert . strictEqual ( ( yield * Ref . get ( fixture . stackCalls ) ) . length , 1 ) ;
519520 const commands = yield * Ref . get ( fixture . syncCommands ) ;
520521 assert . deepStrictEqual (
521522 commands
@@ -531,6 +532,86 @@ describe("PullRequestSyncReactor", () => {
531532 ) ,
532533 ) ;
533534
535+ it . effect . each ( [ "summary" , "stack" ] as const ) (
536+ "isolates a failed project %s refresh and retries it after the other project succeeds" ,
537+ ( operation ) =>
538+ Effect . scoped (
539+ Effect . gen ( function * ( ) {
540+ yield * TestClock . setTime ( Date . parse ( NOW ) ) ;
541+ const otherProject = ProjectId . make ( "other-project" ) ;
542+ const link = makeLink ( 42 , { state : "merged" , mergedAt : NOW } ) ;
543+ let failing = true ;
544+ const failure = new PullRequestOperationError ( { operation, detail : "checkout missing" } ) ;
545+ const fixture = yield * makeHarness ( {
546+ snapshot : makeSnapshot ( [
547+ makeThread ( "failing" , { pullRequests : [ link ] } ) ,
548+ makeThread ( "healthy" , { projectId : otherProject , pullRequests : [ link ] } ) ,
549+ makeThread ( "same-project" , { projectId : otherProject , pullRequests : [ link ] } ) ,
550+ ] ) ,
551+ summary : ( input ) =>
552+ failing && input . projectId === PROJECT_ID && operation === "summary"
553+ ? Effect . fail ( failure )
554+ : Effect . succeed (
555+ makeSummary ( input , {
556+ state : "merged" ,
557+ mergedAt : NOW ,
558+ title : input . projectId ,
559+ } ) ,
560+ ) ,
561+ stack : ( input ) =>
562+ failing && input . projectId === PROJECT_ID && operation === "stack"
563+ ? Effect . fail ( failure )
564+ : Effect . succeed ( {
565+ id : input . projectId ,
566+ number : 42 ,
567+ url : "https://github.com/owner/repository/stacks/42" ,
568+ base : "main" ,
569+ layers : [ { number : 42 , headBranch : "feature" , state : "merged" } ] ,
570+ } ) ,
571+ } ) ;
572+ yield * Effect . gen ( function * ( ) {
573+ const reactor = yield * startAndSweep ( fixture ) ;
574+ assert . deepStrictEqual ( yield * Ref . get ( fixture . summaryCalls ) , [ ] ) ;
575+ yield * reactor . requestSync ( link ) ;
576+ yield * Queue . take ( fixture . snapshotReads ) ;
577+ yield * reactor . drain ;
578+ const commands = yield * Ref . get ( fixture . syncCommands ) ;
579+ assert . sameDeepMembers (
580+ commands . map ( ( command ) => [
581+ command . threadId ,
582+ command . snapshot . title ,
583+ command . stack ?. id ,
584+ ] ) ,
585+ [
586+ [ "healthy" , otherProject , otherProject ] ,
587+ [ "same-project" , otherProject , otherProject ] ,
588+ ] ,
589+ ) ;
590+ assert . sameMembers (
591+ ( yield * Ref . get ( fixture . summaryCalls ) ) . map ( ( call ) => call . projectId ) ,
592+ [ PROJECT_ID , otherProject ] ,
593+ ) ;
594+ assert . sameMembers (
595+ ( yield * Ref . get ( fixture . stackCalls ) ) . map ( ( call ) => call . projectId ) ,
596+ operation === "stack" ? [ PROJECT_ID , otherProject ] : [ otherProject ] ,
597+ ) ;
598+ yield * Ref . update ( fixture . snapshots , ( snapshot ) => applySync ( snapshot , commands ) ) ;
599+ failing = false ;
600+ yield * sweepAgain ( fixture , reactor ) ;
601+ assert . strictEqual ( ( yield * Ref . get ( fixture . summaryCalls ) ) . length , 3 ) ;
602+ assert . strictEqual (
603+ ( yield * Ref . get ( fixture . summaryCalls ) ) . at ( - 1 ) ?. projectId ,
604+ PROJECT_ID ,
605+ ) ;
606+ const retried = ( yield * Ref . get ( fixture . syncCommands ) ) . at ( - 1 ) ;
607+ assert . strictEqual ( retried ?. threadId , ThreadId . make ( "failing" ) ) ;
608+ assert . strictEqual ( retried ?. snapshot . title , PROJECT_ID ) ;
609+ assert . strictEqual ( retried ?. stack ?. id , PROJECT_ID ) ;
610+ } ) . pipe ( Effect . provide ( fixture . layer ) ) ;
611+ } ) ,
612+ ) ,
613+ ) ;
614+
534615 it . effect ( "recovers the HTTP port when syncing an older Forgejo link" , ( ) =>
535616 Effect . scoped (
536617 Effect . gen ( function * ( ) {
@@ -580,11 +661,11 @@ describe("PullRequestSyncReactor", () => {
580661 ) ,
581662 ) ;
582663
583- it . effect ( "refreshes closed links through the reactor's project after reopening elsewhere" , ( ) =>
664+ it . effect ( "refreshes closed links through each project after reopening elsewhere" , ( ) =>
584665 Effect . scoped (
585666 Effect . gen ( function * ( ) {
586667 yield * TestClock . setTime ( Date . parse ( NOW ) ) ;
587- const stale = yield * Ref . make ( true ) ;
668+ const invalidated = yield * Ref . make < ReadonlyArray < ProjectId > > ( [ ] ) ;
588669 const fixture = yield * makeHarness ( {
589670 snapshot : makeSnapshot ( [
590671 makeThread ( "first" , { pullRequests : [ makeLink ( 42 , { state : "closed" } ) ] } ) ,
@@ -594,24 +675,36 @@ describe("PullRequestSyncReactor", () => {
594675 } ) ,
595676 ] ) ,
596677 invalidate : ( { reference } ) =>
597- reference ?. projectId === makeProject ( ) . id && reference . host === "github.com"
598- ? Ref . set ( stale , false )
678+ reference !== undefined
679+ ? Ref . update ( invalidated , ( projects ) => [ ... projects , reference . projectId ] )
599680 : Effect . void ,
600681 summary : ( input ) =>
601- Ref . get ( stale ) . pipe (
602- Effect . map ( ( cached ) => makeSummary ( input , { state : cached ? "closed" : "open" } ) ) ,
682+ Ref . get ( invalidated ) . pipe (
683+ Effect . map ( ( projects ) =>
684+ makeSummary ( input , {
685+ state : projects . includes ( input . projectId ) ? "open" : "closed" ,
686+ } ) ,
687+ ) ,
603688 ) ,
604689 } ) ;
605690 yield * Effect . gen ( function * ( ) {
606691 const reactor = yield * startAndSweep ( fixture ) ;
607- assert . strictEqual ( ( yield * Ref . get ( fixture . summaryCalls ) ) . length , 1 ) ;
692+ assert . strictEqual ( ( yield * Ref . get ( fixture . summaryCalls ) ) . length , 2 ) ;
608693 yield * reactor . requestSync ( {
609694 host : "github.com" ,
610695 repository : "owner/repository" ,
611696 number : 42 ,
612697 } ) ;
613698 yield * Queue . take ( fixture . snapshotReads ) ;
614699 yield * reactor . drain ;
700+ assert . sameMembers (
701+ [ ...( yield * Ref . get ( invalidated ) ) ] ,
702+ [ PROJECT_ID , ProjectId . make ( "second-project" ) ] ,
703+ ) ;
704+ assert . sameMembers (
705+ ( yield * Ref . get ( fixture . stackCalls ) ) . map ( ( call ) => call . projectId ) ,
706+ [ PROJECT_ID , ProjectId . make ( "second-project" ) ] ,
707+ ) ;
615708 const commands = yield * Ref . get ( fixture . syncCommands ) ;
616709 yield * Ref . update ( fixture . snapshots , ( snapshot ) => applySync ( snapshot , commands ) ) ;
617710 const snapshot = yield * Ref . get ( fixture . snapshots ) ;
0 commit comments