@@ -135,6 +135,10 @@ it("does not commit running state when inherited background routing cannot be re
135135 ) ,
136136 } ) ,
137137 Layer . mock ( ProjectionStore . ProjectionStoreV2 ) ( {
138+ getThreadRecords : ( ) => {
139+ projectionReadCount += 1 ;
140+ return Effect . succeed ( projection ) ;
141+ } ,
138142 getTurnStartContext : ( ) => {
139143 projectionReadCount += 1 ;
140144 return Effect . succeed ( {
@@ -523,6 +527,9 @@ function makeLocalCommandHarness(input: {
523527 ) ;
524528 const exists = vi . fn ( ( ) => Effect . succeed ( true ) ) ;
525529 const createWorktree = vi . fn ( ( ) => Effect . succeed ( { } as never ) ) ;
530+ const getThreadRecords = vi . fn < ProjectionStore . ProjectionStoreV2Shape [ "getThreadRecords" ] > ( ( ) =>
531+ Effect . succeed ( projection ) ,
532+ ) ;
526533 const getTurnStartContext = vi . fn ( ( ) =>
527534 Effect . succeed ( {
528535 ...projection ,
@@ -554,6 +561,7 @@ function makeLocalCommandHarness(input: {
554561 Effect . succeed ( Option . some ( { workspaceRoot : "/tmp/native-account-project" } as never ) ) ,
555562 } ) ,
556563 Layer . mock ( ProjectionStore . ProjectionStoreV2 ) ( {
564+ getThreadRecords,
557565 getTurnStartContext,
558566 getRuntimeRecoveryProjection : ( ) =>
559567 Effect . as ( failReadIfRunning , {
@@ -582,6 +590,7 @@ function makeLocalCommandHarness(input: {
582590 ) ,
583591 ) ;
584592 return {
593+ getThreadRecords,
585594 getTurnStartContext,
586595 setProjection : ( next : OrchestrationV2ThreadProjection ) => {
587596 projection = next ;
@@ -718,6 +727,19 @@ effectIt.effect.each(
718727 } ) . pipe ( Effect . scoped , Effect . provide ( NodeServices . layer ) ) ,
719728) ;
720729
730+ effectIt . effect ( "reads only thread state before taking the startup lease" , ( ) =>
731+ Effect . gen ( function * ( ) {
732+ const harness = makeLocalCommandHarness ( { text : "/logout" , previousNativeSession : true } ) ;
733+ yield * harness . start ;
734+ expect ( harness . getThreadRecords ) . toHaveBeenCalledExactlyOnceWith (
735+ harness . projection ( ) . thread . id ,
736+ [ ] ,
737+ ) ;
738+ expect ( harness . getTurnStartContext ) . toHaveBeenCalledOnce ( ) ;
739+ expect ( harness . projection ( ) . runs . at ( - 1 ) ?. status ) . toBe ( "completed" ) ;
740+ } ) ,
741+ ) ;
742+
721743effectIt . effect ( "reads current startup state after waiting for the workspace lease" , ( ) =>
722744 Effect . gen ( function * ( ) {
723745 const worktreePath = "/tmp/provider-start-fresh-state" ;
@@ -728,15 +750,15 @@ effectIt.effect("reads current startup state after waiting for the workspace lea
728750 worktreePath,
729751 failReadsAfterRunning : true ,
730752 } ) ;
731- const read = harness . getTurnStartContext . getMockImplementation ( ) ! ;
732- harness . getTurnStartContext . mockImplementationOnce ( ( ) =>
733- Deferred . succeed ( readEntered , undefined ) . pipe ( Effect . andThen ( read ( ) ) ) ,
753+ harness . getThreadRecords . mockImplementationOnce ( ( ) =>
754+ Deferred . succeed ( readEntered , undefined ) . pipe ( Effect . as ( harness . projection ( ) ) ) ,
734755 ) ;
735756 const holder = yield * withWorkspaceLease ( worktreePath , Deferred . await ( release ) ) . pipe (
736757 Effect . forkChild ( { startImmediately : true } ) ,
737758 ) ;
738759 const startup = yield * harness . start . pipe ( Effect . forkChild ( { startImmediately : true } ) ) ;
739760 yield * Deferred . await ( readEntered ) ;
761+ expect ( harness . getTurnStartContext ) . not . toHaveBeenCalled ( ) ;
740762 const projection = harness . projection ( ) ;
741763 harness . setProjection ( {
742764 ...projection ,
@@ -764,12 +786,11 @@ effectIt.effect.each(["worktree", "root"])(
764786 ...( initial === "worktree" ? { worktreePath : oldPath } : { } ) ,
765787 failReadsAfterRunning : true ,
766788 } ) ;
767- const read = harness . getTurnStartContext . getMockImplementation ( ) ! ;
768- harness . getTurnStartContext . mockImplementationOnce ( ( ) => {
769- const projection = read ( ) ;
789+ harness . getThreadRecords . mockImplementationOnce ( ( ) => {
790+ const projection = harness . projection ( ) ;
770791 return Deferred . succeed ( readEntered , undefined ) . pipe (
771792 Effect . andThen ( Deferred . await ( releaseOld ) ) ,
772- Effect . andThen ( projection ) ,
793+ Effect . as ( projection ) ,
773794 ) ;
774795 } ) ;
775796 let newLeaseReleased = false ;
0 commit comments