Skip to content

Commit be03a3e

Browse files
committed
Fix tests to account for subagent spawn message
1 parent 9ba0254 commit be03a3e

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

packages/agent-runtime/src/__tests__/spawn-agents-message-history.test.ts

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@ describe('Spawn Agents Message History', () => {
143143
// Verify that the subagent's message history contains the filtered messages
144144
// expireMessages filters based on timeToLive property, not role
145145
// Since the system message doesn't have timeToLive, it will be included
146-
expect(capturedSubAgentState.messageHistory).toHaveLength(4) // System + user + assistant messages
146+
// System + user + assistant messages + spawn message
147+
expect(capturedSubAgentState.messageHistory).toHaveLength(5)
147148

148149
// Verify system message is included (because it has no timeToLive property)
149150
const systemMessages = capturedSubAgentState.messageHistory.filter(
@@ -173,6 +174,14 @@ describe('Spawn Agents Message History', () => {
173174
(msg: any) => msg.content[0]?.text === 'How are you?',
174175
),
175176
).toBeTruthy()
177+
178+
// Verify the subagent spawn message is included with proper structure
179+
const spawnMessage = capturedSubAgentState.messageHistory.find(
180+
(msg: any) => msg.tags?.includes('SUBAGENT_SPAWN'),
181+
)
182+
expect(spawnMessage).toBeTruthy()
183+
expect(spawnMessage.role).toBe('user')
184+
expect(spawnMessage.content[0]?.text).toContain('Subagent child-agent has been spawned')
176185
})
177186

178187
it('should not include conversation history when includeMessageHistory is false', async () => {
@@ -215,8 +224,15 @@ describe('Spawn Agents Message History', () => {
215224
toolCall,
216225
})
217226

218-
// Verify that the subagent's message history is empty when there are no messages to pass
219-
expect(capturedSubAgentState.messageHistory).toHaveLength(0)
227+
// Verify that the subagent's message history contains only the spawn message
228+
// when includeMessageHistory is true (even with empty parent history)
229+
expect(capturedSubAgentState.messageHistory).toHaveLength(1)
230+
231+
// Verify the spawn message structure
232+
const spawnMessage = capturedSubAgentState.messageHistory[0]
233+
expect(spawnMessage.role).toBe('user')
234+
expect(spawnMessage.tags).toContain('SUBAGENT_SPAWN')
235+
expect(spawnMessage.content[0]?.text).toContain('Subagent child-agent has been spawned')
220236
})
221237

222238
it('should handle message history with only system messages', async () => {
@@ -240,10 +256,17 @@ describe('Spawn Agents Message History', () => {
240256

241257
// Verify that system messages without timeToLive are included
242258
// expireMessages only filters messages with timeToLive='userPrompt'
243-
expect(capturedSubAgentState.messageHistory).toHaveLength(2)
259+
// Plus 1 for the subagent spawn message
260+
expect(capturedSubAgentState.messageHistory).toHaveLength(3)
244261
const systemMessages = capturedSubAgentState.messageHistory.filter(
245262
(msg: any) => msg.role === 'system',
246263
)
247264
expect(systemMessages).toHaveLength(2)
265+
266+
// Verify spawn message is present
267+
const spawnMessage = capturedSubAgentState.messageHistory.find(
268+
(msg: any) => msg.tags?.includes('SUBAGENT_SPAWN'),
269+
)
270+
expect(spawnMessage).toBeTruthy()
248271
})
249272
})

0 commit comments

Comments
 (0)