@@ -571,6 +571,7 @@ const makeHarness = Effect.fn("makeThreadSettlementHarness")(function* (options:
571571 const snapshotReads = yield * Queue . unbounded < number > ( ) ;
572572 const candidateReads = yield * Ref . make < ReadonlyArray < string | undefined > > ( [ ] ) ;
573573 const settings = yield * Ref . make ( options . settings ?? DEFAULT_SERVER_SETTINGS ) ;
574+ const settingsReadCount = yield * Ref . make ( 0 ) ;
574575 const settingsChanges = yield * PubSub . unbounded < ContractServerSettings > ( ) ;
575576 const mergedPullRequests = yield * PubSub . unbounded < PullRequestService . PullRequestMergeEvent > ( ) ;
576577 const commands = yield * Ref . make < ReadonlyArray < AutoSettleCommand > > ( [ ] ) ;
@@ -640,7 +641,9 @@ const makeHarness = Effect.fn("makeThreadSettlementHarness")(function* (options:
640641 const serverSettings = ServerSettings . ServerSettingsService . of ( {
641642 start : Effect . void ,
642643 ready : Effect . void ,
643- getSettings : Ref . get ( settings ) ,
644+ getSettings : Ref . update ( settingsReadCount , ( count ) => count + 1 ) . pipe (
645+ Effect . andThen ( Ref . get ( settings ) ) ,
646+ ) ,
644647 updateSettings,
645648 updateProviderInstance : ( ) => Effect . die ( "Unexpected provider mutation" ) ,
646649 withSettingsSnapshot : ( use ) => Ref . get ( settings ) . pipe ( Effect . flatMap ( use ) ) ,
@@ -710,6 +713,7 @@ const makeHarness = Effect.fn("makeThreadSettlementHarness")(function* (options:
710713 activation,
711714 snapshots,
712715 snapshotReadCount,
716+ settingsReadCount,
713717 snapshotReads,
714718 candidateReads,
715719 commands,
@@ -746,6 +750,37 @@ const startHarness = Effect.fn("startThreadSettlementHarness")(function* (
746750} ) ;
747751
748752describe ( "ThreadSettlementServiceV2 worker" , ( ) => {
753+ it . effect ( "skips settings and PR decisions for recent branchless threads" , ( ) =>
754+ Effect . scoped (
755+ Effect . gen ( function * ( ) {
756+ yield * TestClock . setTime ( Date . parse ( NOW ) ) ;
757+ const threads = Array . from ( { length : 32 } , ( _ , index ) =>
758+ makeThread ( `recent-${ index } ` , {
759+ updatedAt : DateTime . makeUnsafe ( NOW ) ,
760+ latestUserMessageAt : DateTime . makeUnsafe ( Date . parse ( NOW ) - 2 * DAY_MS ) ,
761+ } ) ,
762+ ) ;
763+ const fixture = yield * makeHarness ( {
764+ snapshot : makeSnapshot ( threads ) ,
765+ settings : { ...DEFAULT_SERVER_SETTINGS , sidebarAutoSettleAfterDays : 3 } ,
766+ } ) ;
767+ yield * Effect . gen ( function * ( ) {
768+ const service = yield * ThreadSettlementService . ThreadSettlementServiceV2 ;
769+ yield * startHarness ( service , fixture . activation , fixture . snapshotReads ) ;
770+ assert . deepEqual ( yield * Ref . get ( fixture . commands ) , [ ] ) ;
771+ assert . deepEqual ( yield * Ref . get ( fixture . branchCalls ) , [ ] ) ;
772+ assert . equal ( yield * Ref . get ( fixture . settingsReadCount ) , 2 ) ;
773+ yield * fixture . updateSettings ( { sidebarAutoSettleAfterDays : 1 } ) ;
774+ yield * Queue . take ( fixture . snapshotReads ) ;
775+ yield * service . drain ;
776+ assert . deepEqual (
777+ new Set ( ( yield * Ref . get ( fixture . commands ) ) . map ( ( command ) => command . threadId ) ) ,
778+ new Set ( threads . map ( ( thread ) => thread . id ) ) ,
779+ ) ;
780+ } ) . pipe ( Effect . provide ( fixture . layer ) ) ;
781+ } ) ,
782+ ) ,
783+ ) ;
749784 it . effect ( "settles a merged pull request stored only in the thread links" , ( ) =>
750785 Effect . scoped (
751786 Effect . gen ( function * ( ) {
0 commit comments