@@ -5015,11 +5015,45 @@ it.layer(layerTest)("OrchestrationV2LayerLive lifecycle", (it) => {
50155015
50165016 yield * send ( 1 , "queue_after_active" ) ;
50175017 yield * orchestrator . resumeQueuedRuns ;
5018- const queued = ( yield * orchestrator . getThreadProjection ( threadId ) ) . runs . find (
5019- ( run ) => run . userMessageId === MessageId . make ( `${ threadId } :1` ) ,
5020- ) ;
5018+ const runFor = ( index : number ) =>
5019+ Effect . map ( orchestrator . getThreadProjection ( threadId ) , ( { runs } ) =>
5020+ runs . find ( ( run ) => run . userMessageId === MessageId . make ( `${ threadId } :${ index } ` ) ) ,
5021+ ) ;
5022+ const queued = yield * runFor ( 1 ) ;
50215023 assert . equal ( queued ?. status , "queued" ) ;
50225024 assert . notEqual ( queued ?. queueHeld , true ) ;
5025+
5026+ yield * orchestrator . dispatch ( {
5027+ type : "message.dispatch" ,
5028+ commandId : CommandId . make ( `${ threadId } :2` ) ,
5029+ threadId,
5030+ messageId : MessageId . make ( `${ threadId } :2` ) ,
5031+ manualContinuationOfRunId : limited . id ,
5032+ text : "Continue where you left off." ,
5033+ attachments : [ ] ,
5034+ createdBy : "user" ,
5035+ creationSource : "web" ,
5036+ dispatchMode : { type : "start_immediately" } ,
5037+ } ) ;
5038+ const continuation = yield * runFor ( 2 ) ;
5039+ assert . equal ( continuation ?. status , "starting" ) ;
5040+ assert . equal ( ( yield * runFor ( 1 ) ) ?. status , "queued" ) ;
5041+ const completedAt = yield * DateTime . now ;
5042+ yield * eventSink . write ( {
5043+ events : [
5044+ {
5045+ id : EventId . make ( `${ threadId } :continuation:completed` ) ,
5046+ type : "run.updated" ,
5047+ threadId,
5048+ runId : continuation ! . id ,
5049+ providerInstanceId : continuation ! . providerInstanceId ,
5050+ occurredAt : completedAt ,
5051+ payload : { ...continuation ! , status : "completed" , startedAt : completedAt , completedAt } ,
5052+ } ,
5053+ ] ,
5054+ } ) ;
5055+ yield * orchestrator . resumeQueuedRuns ;
5056+ assert . equal ( ( yield * runFor ( 1 ) ) ?. status , "starting" ) ;
50235057 } ) ,
50245058 ) ;
50255059
0 commit comments