@@ -5607,6 +5607,64 @@ it.layer(NodeServices.layer)("server router seam", (it) => {
56075607 } ) . pipe ( Effect . provide ( NodeHttpServer . layerTest ) ) ,
56085608 ) ;
56095609
5610+ it . effect ( "buffers thread events published while the initial snapshot loads" , ( ) =>
5611+ Effect . gen ( function * ( ) {
5612+ const thread = makeDefaultOrchestrationReadModel ( ) . threads [ 0 ] ! ;
5613+ const liveEvents = yield * PubSub . unbounded < OrchestrationEvent > ( ) ;
5614+ const messageEvent = {
5615+ sequence : 2 ,
5616+ eventId : EventId . make ( "event-message" ) ,
5617+ aggregateKind : "thread" ,
5618+ aggregateId : defaultThreadId ,
5619+ occurredAt : "2026-01-01T00:00:01.000Z" ,
5620+ commandId : null ,
5621+ causationEventId : null ,
5622+ correlationId : null ,
5623+ metadata : { } ,
5624+ type : "thread.message-sent" ,
5625+ payload : {
5626+ threadId : defaultThreadId ,
5627+ messageId : MessageId . make ( "message-1" ) ,
5628+ role : "user" ,
5629+ text : "First message" ,
5630+ turnId : null ,
5631+ streaming : false ,
5632+ createdAt : "2026-01-01T00:00:01.000Z" ,
5633+ updatedAt : "2026-01-01T00:00:01.000Z" ,
5634+ } ,
5635+ } satisfies Extract < OrchestrationEvent , { type : "thread.message-sent" } > ;
5636+
5637+ yield * buildAppUnderTest ( {
5638+ layers : {
5639+ orchestrationEngine : {
5640+ streamDomainEvents : Stream . fromPubSub ( liveEvents ) ,
5641+ } ,
5642+ projectionSnapshotQuery : {
5643+ getThreadDetailSnapshot : ( ) =>
5644+ Effect . gen ( function * ( ) {
5645+ yield * Effect . sleep ( "25 millis" ) ;
5646+ yield * PubSub . publish ( liveEvents , messageEvent ) ;
5647+ return Option . some ( { snapshotSequence : 1 , thread } ) ;
5648+ } ) ,
5649+ } ,
5650+ } ,
5651+ } ) ;
5652+
5653+ const wsUrl = yield * getWsServerUrl ( "/ws" ) ;
5654+ const items = yield * Effect . scoped (
5655+ withWsRpcClient ( wsUrl , ( client ) =>
5656+ client [ ORCHESTRATION_WS_METHODS . subscribeThread ] ( {
5657+ threadId : defaultThreadId ,
5658+ } ) . pipe ( Stream . take ( 2 ) , Stream . runCollect ) ,
5659+ ) ,
5660+ ) . pipe ( Effect . timeout ( "2 seconds" ) ) ;
5661+
5662+ assert . equal ( items [ 0 ] ?. kind , "snapshot" ) ;
5663+ assert . equal ( items [ 1 ] ?. kind , "event" ) ;
5664+ assert . equal ( items [ 1 ] ?. kind === "event" ? items [ 1 ] . event . sequence : null , 2 ) ;
5665+ } ) . pipe ( Effect . provide ( NodeHttpServer . layerTest ) , TestClock . withLive ) ,
5666+ ) ;
5667+
56105668 it . effect ( "enriches replayed project events with repository identity metadata" , ( ) =>
56115669 Effect . gen ( function * ( ) {
56125670 const repositoryIdentity = {
0 commit comments