1+ import * as NodeV8 from "node:v8" ;
2+
13import { SourceControlProviderKind } from "@t3tools/contracts" ;
24import * as Stream from "effect/Stream" ;
35import {
@@ -21,10 +23,12 @@ import {
2123 type ThreadPullRequestSnapshot ,
2224} from "@t3tools/contracts" ;
2325import { assert , describe , it } from "@effect/vitest" ;
26+ import * as Cache from "effect/Cache" ;
2427import * as Clock from "effect/Clock" ;
2528import * as Crypto from "effect/Crypto" ;
2629import * as DateTime from "effect/DateTime" ;
2730import * as Deferred from "effect/Deferred" ;
31+ import * as Duration from "effect/Duration" ;
2832import * as Effect from "effect/Effect" ;
2933import * as Layer from "effect/Layer" ;
3034import * as Queue from "effect/Queue" ;
@@ -496,6 +500,40 @@ const mergingSnapshot = () =>
496500 makeSnapshot ( [ makeThread ( MERGING_THREAD , { pullRequests : [ makeLink ( 7 , { state : "open" } ) ] } ) ] ) ;
497501
498502describe ( "PullRequestSyncReactor" , ( ) => {
503+ it . effect ( "lets a finished sweep's links go while a cache keeps the fiber that read them" , ( ) =>
504+ Effect . gen ( function * ( ) {
505+ class SweptLink {
506+ readonly swept = true ;
507+ }
508+ // Like PullRequestReadCache's revisions: a lookup fiber, kept for good, forked from the reader.
509+ const kept = yield * Cache . makeWith ( ( ) => Effect . void , {
510+ capacity : 1 ,
511+ timeToLive : ( ) => Duration . infinity ,
512+ } ) ;
513+ const fixture = yield * makeHarness ( {
514+ snapshot : makeSnapshot ( [ ] ) ,
515+ summary : ( input ) => Cache . get ( kept , undefined ) . pipe ( Effect . as ( makeSummary ( input ) ) ) ,
516+ } ) ;
517+ yield * Ref . set (
518+ fixture . snapshots ,
519+ makeSnapshot (
520+ Array . from ( { length : 30 } , ( _ , index ) =>
521+ makeThread ( `thread-${ index } ` , {
522+ pullRequests : [ Object . assign ( new SweptLink ( ) , makeLink ( 7 ) ) ] ,
523+ } ) ,
524+ ) ,
525+ ) ,
526+ ) ;
527+ yield * Effect . gen ( function * ( ) {
528+ yield * startAndSweep ( fixture ) ;
529+ assert . strictEqual ( ( yield * Ref . get ( fixture . syncCommands ) ) . length , 30 ) ;
530+ yield * Ref . set ( fixture . snapshots , makeSnapshot ( [ ] ) ) ;
531+
532+ assert . strictEqual ( NodeV8 . queryObjects ( SweptLink , { format : "count" } ) , 0 ) ;
533+ } ) . pipe ( Effect . provide ( fixture . layer ) ) ;
534+ } ) ,
535+ ) ;
536+
499537 it . effect ( "retries a failed stack read after the summary becomes terminal" , ( ) =>
500538 Effect . scoped (
501539 Effect . gen ( function * ( ) {
0 commit comments