@@ -39,18 +39,20 @@ describe('Streaming: Subagent Streaming', () => {
3939 const subagentStarts = collector . getEventsByType ( 'subagent_start' )
4040 const subagentFinishes = collector . getEventsByType ( 'subagent_finish' )
4141
42- // If subagents were spawned, starts and finishes should match
43- if ( subagentStarts . length > 0 ) {
44- // Each started subagent should have a finish
45- for ( const start of subagentStarts ) {
46- const matchingFinish = subagentFinishes . find (
47- ( f ) => f . agentId === start . agentId ,
48- )
49- // Subagent should eventually finish (or the run ends)
50- expect ( start . agentId ) . toBeDefined ( )
51- expect ( start . agentType ) . toBeDefined ( )
52- expect ( start . displayName ) . toBeDefined ( )
53- }
42+ // The prompt should trigger file search which spawns a subagent
43+ // If no subagents were spawned, the test isn't validating what we intend
44+ expect ( subagentStarts . length ) . toBeGreaterThan ( 0 )
45+
46+ // Each started subagent should have a finish
47+ for ( const start of subagentStarts ) {
48+ const matchingFinish = subagentFinishes . find (
49+ ( f ) => f . agentId === start . agentId ,
50+ )
51+ // Subagent should eventually finish
52+ expect ( matchingFinish ) . toBeDefined ( )
53+ expect ( start . agentId ) . toBeDefined ( )
54+ expect ( start . agentType ) . toBeDefined ( )
55+ expect ( start . displayName ) . toBeDefined ( )
5456 }
5557 } ,
5658 DEFAULT_TIMEOUT * 2 ,
@@ -72,6 +74,9 @@ describe('Streaming: Subagent Streaming', () => {
7274
7375 const subagentStarts = collector . getEventsByType ( 'subagent_start' )
7476
77+ // Ensure we actually got subagent events to validate
78+ expect ( subagentStarts . length ) . toBeGreaterThan ( 0 )
79+
7580 for ( const event of subagentStarts ) {
7681 // Required fields
7782 expect ( typeof event . agentId ) . toBe ( 'string' )
@@ -105,22 +110,26 @@ describe('Streaming: Subagent Streaming', () => {
105110 cwd : process . cwd ( ) ,
106111 } )
107112
113+ // Verify we got subagent events (prompt should trigger file exploration)
114+ const subagentStarts = collector . getEventsByType ( 'subagent_start' )
115+ expect ( subagentStarts . length ) . toBeGreaterThan ( 0 )
116+
108117 // Check for subagent chunks in stream
109118 const subagentChunks = collector . streamChunks . filter (
110119 ( c ) : c is Extract < typeof c , { type : 'subagent_chunk' } > =>
111120 typeof c !== 'string' && c . type === 'subagent_chunk' ,
112121 )
113122
114- // If there are subagent events, there might be subagent chunks
115- const subagentStarts = collector . getEventsByType ( 'subagent_start' )
116- if ( subagentStarts . length > 0 && subagentChunks . length > 0 ) {
117- // Verify chunk structure
123+ // If there are subagent chunks, verify their structure
124+ if ( subagentChunks . length > 0 ) {
118125 for ( const chunk of subagentChunks ) {
119126 expect ( chunk . agentId ) . toBeDefined ( )
120127 expect ( chunk . agentType ) . toBeDefined ( )
121128 expect ( typeof chunk . chunk ) . toBe ( 'string' )
122129 }
123130 }
131+ // Note: Subagent chunks may not always be present even with subagent events
132+ // (e.g., if the subagent completes very quickly without streaming)
124133 } ,
125134 DEFAULT_TIMEOUT * 2 ,
126135 )
@@ -140,6 +149,9 @@ describe('Streaming: Subagent Streaming', () => {
140149
141150 const subagentStarts = collector . getEventsByType ( 'subagent_start' )
142151
152+ // Ensure we got subagent events to validate uniqueness
153+ expect ( subagentStarts . length ) . toBeGreaterThan ( 0 )
154+
143155 // Check for duplicates by agentId
144156 const agentIds = subagentStarts . map ( ( s ) => s . agentId )
145157 const uniqueIds = new Set ( agentIds )
0 commit comments