Skip to content

Commit c5a7eb9

Browse files
committed
fix unit tests
1 parent 9e787fd commit c5a7eb9

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

backend/src/__tests__/subagent-streaming.test.ts

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ describe('Subagent Streaming', () => {
2727
let mockSendSubagentChunk: Mock<SendSubagentChunk>
2828
let mockLoopAgentSteps: Mock<(typeof runAgentStep)['loopAgentSteps']>
2929
let mockAgentTemplate: any
30+
let mockWriteToClient: Mock<
31+
Parameters<typeof handleSpawnAgents>[0]['writeToClient']
32+
>
3033

3134
beforeEach(() => {
3235
// Setup common mock agent template
@@ -93,6 +96,8 @@ describe('Subagent Streaming', () => {
9396
}
9497
})
9598

99+
mockWriteToClient = mock(() => {})
100+
96101
// Mock assembleLocalAgentTemplates
97102
spyOn(
98103
{ assembleLocalAgentTemplates },
@@ -144,7 +149,7 @@ describe('Subagent Streaming', () => {
144149
fileContext: mockFileContext,
145150
clientSessionId: 'test-session',
146151
userInputId: 'test-input',
147-
writeToClient: () => {},
152+
writeToClient: mockWriteToClient,
148153
getLatestState: () => ({ messages: [] }),
149154
state: {
150155
ws,
@@ -163,21 +168,28 @@ describe('Subagent Streaming', () => {
163168
await result
164169

165170
// Verify that subagent streaming messages were sent
166-
expect(mockSendSubagentChunk).toHaveBeenCalledTimes(4)
171+
expect(mockSendSubagentChunk).toHaveBeenCalledTimes(2)
172+
expect(mockWriteToClient).toHaveBeenCalledTimes(2)
167173

168174
// First streaming chunk is a labled divider
175+
expect(mockWriteToClient).toHaveBeenNthCalledWith(1, {
176+
type: 'subagent_start',
177+
agentId: 'thinker',
178+
displayName: 'Thinker',
179+
onlyChild: true,
180+
})
169181

170-
// Check second streaming chunk
171-
expect(mockSendSubagentChunk).toHaveBeenNthCalledWith(2, {
182+
// Check first streaming chunk
183+
expect(mockSendSubagentChunk).toHaveBeenNthCalledWith(1, {
172184
userInputId: 'test-input',
173185
agentId: expect.any(String),
174186
agentType: 'thinker',
175187
chunk: 'Thinking about the problem...',
176188
prompt: 'Think about this problem',
177189
})
178190

179-
// Check third streaming chunk
180-
expect(mockSendSubagentChunk).toHaveBeenNthCalledWith(3, {
191+
// Check second streaming chunk
192+
expect(mockSendSubagentChunk).toHaveBeenNthCalledWith(2, {
181193
userInputId: 'test-input',
182194
agentId: expect.any(String),
183195
agentType: 'thinker',
@@ -186,6 +198,12 @@ describe('Subagent Streaming', () => {
186198
})
187199

188200
// Last streaming chunk is a labeled divider
201+
expect(mockWriteToClient).toHaveBeenNthCalledWith(2, {
202+
type: 'subagent_finish',
203+
agentId: 'thinker',
204+
displayName: 'Thinker',
205+
onlyChild: true,
206+
})
189207
})
190208

191209
it('should include correct agentId and agentType in streaming messages', async () => {

0 commit comments

Comments
 (0)