@@ -145,6 +145,46 @@ describe('createMessageEngine', () => {
145145 expect ( snapshotsForRequestState ) . toHaveLength ( expectedRequestStateSequence . length )
146146 } )
147147
148+ it ( 'keeps notifying other subscribers when one subscriber throws' , ( ) => {
149+ const adapter = createNativeMessageAdapter ( )
150+ adapter . initialize ( {
151+ requestState : 'idle' ,
152+ processingState : undefined ,
153+ messages : [ ] ,
154+ } )
155+
156+ const errorSpy = vi . spyOn ( console , 'error' ) . mockImplementation ( ( ) => { } )
157+ const healthyListener = vi . fn ( )
158+
159+ adapter . subscribe ( 'requestState' , ( ) => {
160+ throw new Error ( 'subscriber failed' )
161+ } )
162+ adapter . subscribe ( 'requestState' , healthyListener )
163+
164+ adapter . mutate ( 'requestState' , ( draft ) => {
165+ draft . requestState = 'processing'
166+ draft . processingState = 'requesting'
167+ } )
168+
169+ expect ( healthyListener ) . toHaveBeenNthCalledWith (
170+ 1 ,
171+ expect . objectContaining ( {
172+ requestState : 'idle' ,
173+ processingState : undefined ,
174+ } ) ,
175+ )
176+ expect ( healthyListener ) . toHaveBeenNthCalledWith (
177+ 2 ,
178+ expect . objectContaining ( {
179+ requestState : 'processing' ,
180+ processingState : 'requesting' ,
181+ } ) ,
182+ )
183+ expect ( errorSpy ) . toHaveBeenCalled ( )
184+
185+ errorSpy . mockRestore ( )
186+ } )
187+
148188 it ( 'runs onBeforeRequest with current request body before assistant is appended' , async ( ) => {
149189 const onBeforeRequest = vi . fn ( )
150190 const engine = createTestMessageEngine ( {
0 commit comments