@@ -1177,6 +1177,59 @@ it.effect("keeps hover previews fresh after edits and turns", () =>
11771177 ) ,
11781178) ;
11791179
1180+ it . effect ( "shares one refresh stream between independently created pull request readers" , ( ) =>
1181+ Effect . scoped (
1182+ Effect . gen ( function * ( ) {
1183+ const revision = yield * SubscriptionRef . make ( 0 ) ;
1184+ let subscriptions = 0 ;
1185+ let title = "Original title" ;
1186+ const client = {
1187+ [ WS_METHODS . pullRequestsSubscribeRefreshes ] : ( ) =>
1188+ Stream . unwrap (
1189+ Effect . sync ( ( ) => {
1190+ subscriptions ++ ;
1191+ return SubscriptionRef . changes ( revision ) ;
1192+ } ) ,
1193+ ) ,
1194+ [ WS_METHODS . pullRequestsSummary ] : ( ) => Effect . sync ( ( ) => ( { title, state : "open" } ) ) ,
1195+ [ WS_METHODS . pullRequestsDetail ] : ( ) => Effect . sync ( ( ) => ( { title, state : "open" } ) ) ,
1196+ } as unknown as WsRpcProtocolClient ;
1197+ const { runtime, atoms, registry } = yield * makeTestRuntime ( client ) ;
1198+ const target = {
1199+ environmentId : TARGET . environmentId ,
1200+ input : { projectId : ProjectId . make ( "project-1" ) , repository : "acme/web" , number : 1 } ,
1201+ } ;
1202+ const summary = createLinkedPullRequestSummaryAtomFamily ( runtime ) ( target ) ;
1203+ const detail = atoms . detail ( target ) ;
1204+ for ( const atom of [ summary , detail ] ) {
1205+ const unmount = registry . mount ( atom ) ;
1206+ yield * Effect . addFinalizer ( ( ) => Effect . sync ( unmount ) ) ;
1207+ expect ( ( yield * AtomRegistry . getResult ( registry , atom ) ) . title ) . toBe ( title ) ;
1208+ }
1209+ yield * AtomRegistry . getResult (
1210+ registry ,
1211+ atoms . refreshes ( { environmentId : target . environmentId , input : { } } ) ,
1212+ ) ;
1213+ expect ( subscriptions ) . toBe ( 1 ) ;
1214+
1215+ const changed = [ summary , detail ] . map ( ( atom ) => {
1216+ const ready = Latch . makeUnsafe ( ) ;
1217+ const stop = registry . subscribe ( atom , ( result ) => {
1218+ if ( AsyncResult . isSuccess ( result ) && result . value . title === "Updated title" ) {
1219+ ready . openUnsafe ( ) ;
1220+ }
1221+ } ) ;
1222+ return { ready, stop } ;
1223+ } ) ;
1224+ yield * Effect . addFinalizer ( ( ) => Effect . sync ( ( ) => changed . forEach ( ( { stop } ) => stop ( ) ) ) ) ;
1225+ title = "Updated title" ;
1226+ yield * SubscriptionRef . update ( revision , ( value ) => value + 1 ) ;
1227+ for ( const { ready } of changed ) yield * ready . await ;
1228+ expect ( subscriptions ) . toBe ( 1 ) ;
1229+ } ) ,
1230+ ) ,
1231+ ) ;
1232+
11801233it . effect ( "shares close, reopen, and merge with an untouched client's mounted PR readers" , ( ) =>
11811234 Effect . scoped (
11821235 Effect . gen ( function * ( ) {
0 commit comments