@@ -161,6 +161,7 @@ const makeHarness = Effect.fn("makeThreadSettlementHarness")(function* (options:
161161 } >
162162 > ( [ ] ) ;
163163 const summaryRecovery = yield * Ref . make < ReadonlyArray < boolean | undefined > > ( [ ] ) ;
164+ const invalidatedCwds = yield * Ref . make < ReadonlyArray < string > > ( [ ] ) ;
164165
165166 const updateSettings = ( patch : ServerSettingsPatch ) =>
166167 Effect . gen ( function * ( ) {
@@ -221,7 +222,10 @@ const makeHarness = Effect.fn("makeThreadSettlementHarness")(function* (options:
221222 Effect . andThen ( Ref . get ( snapshots ) ) ,
222223 ) ,
223224 } ) ,
224- Layer . mock ( GitManager ) ( { branchPullRequest } ) ,
225+ Layer . mock ( GitManager ) ( {
226+ branchPullRequest,
227+ invalidateStatus : ( cwd ) => Ref . update ( invalidatedCwds , ( cwds ) => [ ...cwds , cwd ] ) ,
228+ } ) ,
225229 Layer . mock ( PullRequestService ) ( {
226230 summary : pullRequestSummary ,
227231 subscribeMerges : PubSub . subscribe ( mergedPullRequests ) . pipe (
@@ -251,6 +255,7 @@ const makeHarness = Effect.fn("makeThreadSettlementHarness")(function* (options:
251255 branchCalls,
252256 summaryCalls,
253257 summaryRecovery,
258+ invalidatedCwds,
254259 updateSettings,
255260 publishMerge : PubSub . publish ( mergedPullRequests , {
256261 projectId : PROJECT_ID ,
@@ -446,6 +451,42 @@ describe("ThreadSettlementReactor", () => {
446451 ) ,
447452 ) ;
448453
454+ it . effect ( "settles branch threads on a pull request merge without waiting for the next sweep" , ( ) =>
455+ Effect . scoped (
456+ Effect . gen ( function * ( ) {
457+ yield * TestClock . setTime ( Date . parse ( NOW ) ) ;
458+ const state = yield * Ref . make < "open" | "merged" > ( "open" ) ;
459+ const mergedThreadSettled = yield * Deferred . make < void > ( ) ;
460+ const fixture = yield * makeHarness ( {
461+ snapshot : makeSnapshot ( [ makeThread ( "branch-thread" , { branch : "saved-feature" } ) ] ) ,
462+ branchPullRequest : ( ) =>
463+ Ref . get ( state ) . pipe (
464+ Effect . map ( ( pullRequestState ) => ( { state : pullRequestState , updatedAt : NOW } ) ) ,
465+ ) ,
466+ onDispatch : ( ) => Deferred . succeed ( mergedThreadSettled , undefined ) ,
467+ } ) ;
468+
469+ yield * Effect . gen ( function * ( ) {
470+ const reactor = yield * ThreadSettlementReactor . ThreadSettlementReactor ;
471+ yield * startHarness ( reactor , fixture . activation , fixture . snapshotReads ) ;
472+ assert . deepStrictEqual ( yield * Ref . get ( fixture . commands ) , [ ] ) ;
473+ assert . deepStrictEqual ( yield * Ref . get ( fixture . invalidatedCwds ) , [ ] ) ;
474+
475+ yield * Ref . set ( state , "merged" ) ;
476+ yield * fixture . publishMerge ;
477+ yield * Deferred . await ( mergedThreadSettled ) ;
478+
479+ assert . deepStrictEqual (
480+ ( yield * Ref . get ( fixture . commands ) ) . map ( ( command ) => command . threadId ) ,
481+ [ ThreadId . make ( "branch-thread" ) ] ,
482+ ) ;
483+ assert . deepStrictEqual ( yield * Ref . get ( fixture . invalidatedCwds ) , [ "/workspace/project" ] ) ;
484+ yield * reactor . drain ;
485+ } ) . pipe ( Effect . provide ( fixture . layer ) ) ;
486+ } ) ,
487+ ) ,
488+ ) ;
489+
449490 it . effect ( "uses fresh settlement settings after lookup and ignores unrelated changes" , ( ) =>
450491 Effect . scoped (
451492 Effect . gen ( function * ( ) {
0 commit comments