@@ -4678,6 +4678,28 @@ describe("SessionRunnerLLM", () => {
46784678 expect ( userTexts ( s . requests [ 2 ] ) ) . toEqual ( [ "Start working" , "Wait until continuation ends" ] )
46794679 } )
46804680
4681+ scenario ( "the queue.deliver hook merges only the queued prompts before a queued control" , function * ( s ) {
4682+ const hooks = yield * PluginHooks . Service
4683+ const bus = yield * Bus . Service
4684+ const seen : Array < ReadonlyArray < string > > = [ ]
4685+ yield * hooks . register ( "session" , "experimental.queue.deliver" , ( event ) =>
4686+ Effect . sync ( ( ) => {
4687+ seen . push ( event . prompts . map ( ( prompt ) => prompt . text ) )
4688+ event . take = event . prompts . length
4689+ } ) ,
4690+ )
4691+ for ( const text of [ "A" , "B" ] ) yield * s . session . prompt ( { sessionID, text, delivery : "queue" , resume : false } )
4692+ const compaction = yield * s . session . compact ( { sessionID, delivery : "queue" } )
4693+ yield * s . session . prompt ( { sessionID, text : "C" , delivery : "queue" , resume : false } )
4694+
4695+ yield * SessionInbox . promote ( s . db , bus , sessionID , "input" , hooks )
4696+
4697+ expect ( seen ) . toEqual ( [ [ "A" , "B" ] ] )
4698+ expect ( ( yield * s . messages ) . flatMap ( ( message ) => ( message . type === "user" ? [ message . text ] : [ ] ) ) ) . toEqual ( [ "A\nB" ] )
4699+ const left = yield * s . inbox
4700+ expect ( left . map ( ( item ) => ( item . type === "user" ? item . payload . text : item . id ) ) ) . toEqual ( [ compaction . id , "C" ] )
4701+ } )
4702+
46814703 for ( const take of [ 3 , 2 , 1 ] as const )
46824704 scenario (
46834705 `delivers the ${ take === 1 ? "oldest queued prompt alone" : `oldest ${ take } queued prompts as one message` } when the queue.deliver hook takes ${ take } ` ,
0 commit comments