@@ -34,6 +34,7 @@ import {
3434} from "./Services/OrchestrationEngine.ts" ;
3535import { ProjectionSnapshotQuery } from "./Services/ProjectionSnapshotQuery.ts" ;
3636import * as PullRequestSyncReactor from "./PullRequestSyncReactor.ts" ;
37+ import { resolveAutoSettlementAt } from "./ThreadSettlementPolicy.ts" ;
3738
3839const NOW = "2026-08-28T12:00:00.000Z" ;
3940const PROJECT_ID = ProjectId . make ( "sync-project" ) ;
@@ -155,6 +156,7 @@ function makeSummary(
155156}
156157
157158interface HarnessOptions {
159+ readonly onDispatch ?: ( command : SyncCommand | LinkCommand ) => Effect . Effect < void > ;
158160 readonly invalidate ?: PullRequestService [ "Service" ] [ "invalidate" ] ;
159161 readonly snapshot : OrchestrationShellSnapshot ;
160162 readonly summary ?: (
@@ -192,11 +194,13 @@ const makeHarness = Effect.fn("makePullRequestSyncHarness")(function* (options:
192194 const dispatch : OrchestrationEngineShape [ "dispatch" ] = ( command ) => {
193195 if ( command . type === "thread.pull-request-link.sync" ) {
194196 return Ref . update ( syncCommands , ( recorded ) => [ ...recorded , command ] ) . pipe (
197+ Effect . andThen ( options . onDispatch ?.( command ) ?? Effect . void ) ,
195198 Effect . as ( { sequence : 1 } ) ,
196199 ) ;
197200 }
198201 if ( command . type === "thread.pull-request.link" ) {
199202 return Ref . update ( linkCommands , ( recorded ) => [ ...recorded , command ] ) . pipe (
203+ Effect . andThen ( options . onDispatch ?.( command ) ?? Effect . void ) ,
200204 Effect . as ( { sequence : 1 } ) ,
201205 ) ;
202206 }
@@ -700,20 +704,38 @@ describe("PullRequestSyncReactor", () => {
700704 base : "main" ,
701705 layers : [
702706 { number : 41 , headBranch : "layer-1" , state : "merged" } ,
703- { number : 42 , headBranch : "layer-2" , state : "open " } ,
707+ { number : 42 , headBranch : "layer-2" , state : "merged " } ,
704708 { number : 43 , headBranch : "layer-3" , state : "open" } ,
705709 ] ,
706710 } ;
711+ let thread = makeThread ( "one" , {
712+ pullRequests : [
713+ makeLink ( 42 , { state : "open" } ) ,
714+ makeLink ( 41 , { state : "merged" } , { source : "stack-dismissed" } ) ,
715+ ] ,
716+ } ) ;
707717 const fixture = yield * makeHarness ( {
708- snapshot : makeSnapshot ( [
709- makeThread ( "one" , {
710- pullRequests : [
711- makeLink ( 42 ) ,
712- makeLink ( 41 , { state : "merged" } , { source : "stack-dismissed" } ) ,
713- ] ,
714- } ) ,
715- ] ) ,
718+ snapshot : makeSnapshot ( [ thread ] ) ,
719+ summary : ( input ) =>
720+ Effect . succeed ( makeSummary ( input , { state : "merged" , mergedAt : NOW } ) ) ,
716721 stack : ( ) => Effect . succeed ( stack ) ,
722+ onDispatch : ( command ) =>
723+ Effect . sync ( ( ) => {
724+ thread =
725+ command . type === "thread.pull-request.link"
726+ ? { ...thread , pullRequests : [ ...thread . pullRequests , makeLink ( command . number ) ] }
727+ : applySync ( makeSnapshot ( [ thread ] ) , [ command ] ) . threads [ 0 ] ! ;
728+ // Every projected event may wake settlement, including the terminal root update.
729+ assert . isNull (
730+ resolveAutoSettlementAt ( {
731+ thread,
732+ pullRequest : null ,
733+ now : NOW ,
734+ autoSettleAfterDays : null ,
735+ autoSettleOnMerge : true ,
736+ } ) ,
737+ ) ;
738+ } ) ,
717739 } ) ;
718740
719741 yield * Effect . gen ( function * ( ) {
0 commit comments