@@ -109,27 +109,18 @@ class MockStateSync {
109109 hydrateActiveDraft = vi . fn ( ( ) => this . activeDraftSignal ( ) ) ;
110110}
111111
112+ async function * createMockStream ( chunks : string [ ] ) : AsyncIterable < LlmResponse > {
113+ for ( const content of chunks ) {
114+ yield { content} ;
115+ }
116+ }
117+
112118class MockLlmClient {
113119 chat = vi . fn ( ) ;
114120 chatStream = vi . fn ( async ( messages : LlmMessage [ ] ) : Promise < LlmStreamResponse > => {
115- const contentStream : AsyncIterable < string > = {
116- [ Symbol . asyncIterator ] ( ) {
117- const chunks = [
118- '{"version": "v0.9", "createSurface": {"surfaceId": "s1", ' + '"catalogId": "basic"}}\n' ,
119- ] ;
120- let idx = 0 ;
121- return {
122- async next ( ) : Promise < IteratorResult < string > > {
123- if ( idx < chunks . length ) {
124- const value = chunks [ idx ] ;
125- idx ++ ;
126- return { value, done : false } ;
127- }
128- return { value : undefined , done : true } ;
129- } ,
130- } ;
131- } ,
132- } ;
121+ const contentStream = createMockStream ( [
122+ '{"version": "v0.9", "createSurface": {"surfaceId": "s1", ' + '"catalogId": "basic"}}\n' ,
123+ ] ) ;
133124 const complete = Promise . resolve (
134125 '{"version": "v0.9", "createSurface": {"surfaceId": "s1", ' + '"catalogId": "basic"}}\n' ,
135126 ) ;
@@ -289,20 +280,7 @@ describe('ChatCoordinator Pipeline & State Integration', () => {
289280 'Filler text following block...' ;
290281
291282 llmClientMock . chatStream = vi . fn ( async ( ) : Promise < LlmStreamResponse > => {
292- const contentStream : AsyncIterable < string > = {
293- [ Symbol . asyncIterator ] ( ) {
294- const chunks = [ corruptedRawOutput ] ;
295- let idx = 0 ;
296- return {
297- async next ( ) : Promise < IteratorResult < string > > {
298- if ( idx < chunks . length ) {
299- return { value : chunks [ idx ++ ] , done : false } ;
300- }
301- return { value : undefined , done : true } ;
302- } ,
303- } ;
304- } ,
305- } ;
283+ const contentStream = createMockStream ( [ corruptedRawOutput ] ) ;
306284 return { contentStream, complete : Promise . resolve ( corruptedRawOutput ) } ;
307285 } ) ;
308286
@@ -338,20 +316,7 @@ describe('ChatCoordinator Pipeline & State Integration', () => {
338316 '{"version": "v0.9", "updateComponents": {"surfaceId": "s2", "components": [{"id": "c1", "name": "TextField"}]}}' ;
339317
340318 llmClientMock . chatStream = vi . fn ( async ( ) : Promise < LlmStreamResponse > => {
341- const contentStream : AsyncIterable < string > = {
342- [ Symbol . asyncIterator ] ( ) {
343- const chunks = [ legacyRawOutput ] ;
344- let idx = 0 ;
345- return {
346- async next ( ) : Promise < IteratorResult < string > > {
347- if ( idx < chunks . length ) {
348- return { value : chunks [ idx ++ ] , done : false } ;
349- }
350- return { value : undefined , done : true } ;
351- } ,
352- } ;
353- } ,
354- } ;
319+ const contentStream = createMockStream ( [ legacyRawOutput ] ) ;
355320 return { contentStream, complete : Promise . resolve ( legacyRawOutput ) } ;
356321 } ) ;
357322
@@ -389,20 +354,7 @@ describe('ChatCoordinator Pipeline & State Integration', () => {
389354 ']}}\n' ;
390355
391356 llmClientMock . chatStream = vi . fn ( async ( ) : Promise < LlmStreamResponse > => {
392- const contentStream : AsyncIterable < string > = {
393- [ Symbol . asyncIterator ] ( ) {
394- const chunks = [ typosRawOutput ] ;
395- let idx = 0 ;
396- return {
397- async next ( ) : Promise < IteratorResult < string > > {
398- if ( idx < chunks . length ) {
399- return { value : chunks [ idx ++ ] , done : false } ;
400- }
401- return { value : undefined , done : true } ;
402- } ,
403- } ;
404- } ,
405- } ;
357+ const contentStream = createMockStream ( [ typosRawOutput ] ) ;
406358 return { contentStream, complete : Promise . resolve ( typosRawOutput ) } ;
407359 } ) ;
408360
@@ -592,7 +544,7 @@ describe('ChatCoordinator Pipeline & State Integration', () => {
592544 await Promise . resolve ( ) ;
593545
594546 // Wait for the scheduled microtask to execute
595- await new Promise ( resolve => queueMicrotask ( resolve ) ) ;
547+ await new Promise < void > ( resolve => queueMicrotask ( ( ) => resolve ( ) ) ) ;
596548
597549 // Verify dynamic flushes wipes resets instantly execute!
598550 expect ( chatStateMock . chatHistory ( ) ) . toEqual ( [ ] ) ;
@@ -676,20 +628,7 @@ describe('ChatCoordinator Pipeline & State Integration', () => {
676628 '{"version": "v0.9", "updateComponents": {"surfaceId": "s1", "components": [{"id": "c1", "component": "TextField"}]}}' ;
677629
678630 llmClientMock . chatStream = vi . fn ( async ( ) : Promise < LlmStreamResponse > => {
679- const contentStream : AsyncIterable < string > = {
680- [ Symbol . asyncIterator ] ( ) {
681- const chunks = [ jsonlOutput ] ;
682- let idx = 0 ;
683- return {
684- async next ( ) : Promise < IteratorResult < string > > {
685- if ( idx < chunks . length ) {
686- return { value : chunks [ idx ++ ] , done : false } ;
687- }
688- return { value : undefined , done : true } ;
689- } ,
690- } ;
691- } ,
692- } ;
631+ const contentStream = createMockStream ( [ jsonlOutput ] ) ;
693632 return { contentStream, complete : Promise . resolve ( jsonlOutput ) } ;
694633 } ) ;
695634
@@ -718,20 +657,7 @@ describe('ChatCoordinator Pipeline & State Integration', () => {
718657 '{"version": "v0.9", "updateComponents": {"surfaceId": "s1", "components": [{"id": "c1", "component": "TextField"}]' ;
719658
720659 llmClientMock . chatStream = vi . fn ( async ( ) : Promise < LlmStreamResponse > => {
721- const contentStream : AsyncIterable < string > = {
722- [ Symbol . asyncIterator ] ( ) {
723- const chunks = [ truncatedJsonlOutput ] ;
724- let idx = 0 ;
725- return {
726- async next ( ) : Promise < IteratorResult < string > > {
727- if ( idx < chunks . length ) {
728- return { value : chunks [ idx ++ ] , done : false } ;
729- }
730- return { value : undefined , done : true } ;
731- } ,
732- } ;
733- } ,
734- } ;
660+ const contentStream = createMockStream ( [ truncatedJsonlOutput ] ) ;
735661 return { contentStream, complete : Promise . resolve ( truncatedJsonlOutput ) } ;
736662 } ) ;
737663
@@ -758,20 +684,7 @@ describe('ChatCoordinator Pipeline & State Integration', () => {
758684 '{"version": "v0.9", "updateComponents": { {{{ corrupt' ;
759685
760686 llmClientMock . chatStream = vi . fn ( async ( ) : Promise < LlmStreamResponse > => {
761- const contentStream : AsyncIterable < string > = {
762- [ Symbol . asyncIterator ] ( ) {
763- const chunks = [ corruptedJsonlOutput ] ;
764- let idx = 0 ;
765- return {
766- async next ( ) : Promise < IteratorResult < string > > {
767- if ( idx < chunks . length ) {
768- return { value : chunks [ idx ++ ] , done : false } ;
769- }
770- return { value : undefined , done : true } ;
771- } ,
772- } ;
773- } ,
774- } ;
687+ const contentStream = createMockStream ( [ corruptedJsonlOutput ] ) ;
775688 return { contentStream, complete : Promise . resolve ( corruptedJsonlOutput ) } ;
776689 } ) ;
777690
0 commit comments