@@ -152,9 +152,13 @@ describe("environment shell synchronization", () => {
152152 } ) ,
153153 ) ;
154154
155- it . live ( "applies one chunk of live events as one state change" , ( ) =>
155+ it . live . each ( [
156+ { bufferSize : Infinity , expectedSequences : [ 51 ] } ,
157+ // RpcClient defaults to a 16-event buffer, which splits larger server chunks.
158+ { bufferSize : 16 , expectedSequences : [ 17 , 33 , 49 , 51 ] } ,
159+ ] ) ( "batches live events with a $bufferSize event buffer" , ( { bufferSize, expectedSequences } ) =>
156160 Effect . gen ( function * ( ) {
157- const events = yield * Queue . unbounded < OrchestrationShellStreamItem > ( ) ;
161+ const events = yield * Queue . bounded < OrchestrationShellStreamItem > ( bufferSize ) ;
158162 const client = {
159163 [ ORCHESTRATION_WS_METHODS . subscribeShell ] : ( ) => Stream . fromQueue ( events ) ,
160164 } as unknown as WsRpcProtocolClient ;
@@ -210,27 +214,29 @@ describe("environment shell synchronization", () => {
210214 Stream . runHead ,
211215 ) ;
212216
213- // A bulk action (snooze 30 threads) reaches the client as one server
214- // coalesced chunk. The shell state must change once for it, not 30 times.
217+ // Observe before publishing so no batch can arrive before the subscription.
215218 const observed = yield * SubscriptionRef . changes ( shellState ) . pipe (
216219 Stream . drop ( 1 ) ,
217220 Stream . takeUntil (
218- ( state ) => Option . isSome ( state . snapshot ) && state . snapshot . value . threads . length === 30 ,
221+ ( state ) => Option . isSome ( state . snapshot ) && state . snapshot . value . threads . length === 50 ,
219222 ) ,
220223 Stream . runCollect ,
221- Effect . forkScoped ,
224+ Effect . forkScoped ( { startImmediately : true } ) ,
222225 ) ;
223226 yield * Queue . offerAll (
224227 events ,
225- Array . from ( { length : 30 } , ( _ , index ) => ( {
228+ Array . from ( { length : 50 } , ( _ , index ) => ( {
226229 kind : "thread-upserted" as const ,
227230 sequence : 2 + index ,
228231 thread : { id : `thread-${ index } ` } as never ,
229232 } ) ) ,
230233 ) ;
231234 const states = yield * Fiber . join ( observed ) ;
232- expect ( states ) . toHaveLength ( 1 ) ;
233- expect ( Option . getOrThrow ( states [ 0 ] ! . snapshot ) . snapshotSequence ) . toBe ( 31 ) ;
235+ const snapshots = states . map ( ( state ) => Option . getOrThrow ( state . snapshot ) ) ;
236+ expect ( snapshots . map ( ( snapshot ) => snapshot . snapshotSequence ) ) . toEqual ( expectedSequences ) ;
237+ expect ( snapshots . at ( - 1 ) ! . threads . map ( ( thread ) => thread . id ) ) . toEqual (
238+ Array . from ( { length : 50 } , ( _ , index ) => `thread-${ index } ` ) ,
239+ ) ;
234240 } ) . pipe ( Effect . scoped ) ,
235241 ) ;
236242
0 commit comments