Skip to content

Commit d30033d

Browse files
committed
Fix tests
1 parent f97404c commit d30033d

File tree

1 file changed

+16
-73
lines changed

1 file changed

+16
-73
lines changed

backend/src/__tests__/loop-agent-steps.test.ts

Lines changed: 16 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -97,17 +97,6 @@ describe('loopAgentSteps - runAgentStep vs runProgrammaticStep behavior', () =>
9797
mockModule('@codebuff/backend/get-file-reading-updates', () => ({
9898
getFileReadingUpdates: async () => [],
9999
}))
100-
101-
// Mock async agent manager
102-
mockModule('@codebuff/backend/async-agent-manager', () => ({
103-
asyncAgentManager: {
104-
getAgent: () => null,
105-
registerAgent: () => {},
106-
updateAgentState: () => {},
107-
getAndClearMessages: () => [],
108-
getMessages: () => [],
109-
},
110-
}))
111100
})
112101

113102
beforeEach(() => {
@@ -541,55 +530,6 @@ describe('loopAgentSteps - runAgentStep vs runProgrammaticStep behavior', () =>
541530
expect(llmCallCount).toBe(1) // LLM called once after STEP
542531
expect(result.agentState).toBeDefined()
543532
})
544-
545-
it('should respect async agent messages and continue appropriately', async () => {
546-
// Test async agent message handling during loopAgentSteps
547-
548-
const mockGeneratorFunction = function* () {
549-
yield { toolName: 'read_files', input: { paths: ['async-test.txt'] } }
550-
yield 'STEP'
551-
} as () => StepGenerator
552-
553-
mockTemplate.handleSteps = mockGeneratorFunction
554-
555-
const localAgentTemplates = {
556-
'test-agent': mockTemplate,
557-
}
558-
559-
// Mock async agent manager to simulate pending messages
560-
const mockAsyncAgentManager = require('@codebuff/backend/async-agent-manager')
561-
let getMessagesCallCount = 0
562-
spyOn(
563-
mockAsyncAgentManager.asyncAgentManager,
564-
'getMessages',
565-
).mockImplementation(() => {
566-
getMessagesCallCount++
567-
// Return messages on second call to simulate async agent activity
568-
return getMessagesCallCount === 2 ? ['async message'] : []
569-
})
570-
571-
const result = await runLoopAgentStepsWithContext(
572-
new MockWebSocket() as unknown as WebSocket,
573-
{
574-
userInputId: 'test-user-input',
575-
agentType: 'test-agent',
576-
agentState: mockAgentState,
577-
prompt: 'Test async agent messages',
578-
params: undefined,
579-
fingerprintId: 'test-fingerprint',
580-
fileContext: mockFileContext,
581-
localAgentTemplates,
582-
userId: TEST_USER_ID,
583-
clientSessionId: 'test-session',
584-
onResponseChunk: () => {},
585-
},
586-
)
587-
588-
// Should continue when async messages are present
589-
expect(result.agentState).toBeDefined()
590-
expect(getMessagesCallCount).toBeGreaterThan(0)
591-
})
592-
593533
it('should pass shouldEndTurn: true as stepsComplete when end_turn tool is called', async () => {
594534
// Test that when LLM calls end_turn, shouldEndTurn is correctly passed to runProgrammaticStep
595535

@@ -619,19 +559,22 @@ describe('loopAgentSteps - runAgentStep vs runProgrammaticStep behavior', () =>
619559
'test-agent': mockTemplate,
620560
}
621561

622-
await runLoopAgentStepsWithContext(new MockWebSocket() as unknown as WebSocket, {
623-
userInputId: 'test-user-input',
624-
agentType: 'test-agent',
625-
agentState: mockAgentState,
626-
prompt: 'Test shouldEndTurn to stepsComplete flow',
627-
params: undefined,
628-
fingerprintId: 'test-fingerprint',
629-
fileContext: mockFileContext,
630-
localAgentTemplates,
631-
userId: TEST_USER_ID,
632-
clientSessionId: 'test-session',
633-
onResponseChunk: () => {},
634-
})
562+
await runLoopAgentStepsWithContext(
563+
new MockWebSocket() as unknown as WebSocket,
564+
{
565+
userInputId: 'test-user-input',
566+
agentType: 'test-agent',
567+
agentState: mockAgentState,
568+
prompt: 'Test shouldEndTurn to stepsComplete flow',
569+
params: undefined,
570+
fingerprintId: 'test-fingerprint',
571+
fileContext: mockFileContext,
572+
localAgentTemplates,
573+
userId: TEST_USER_ID,
574+
clientSessionId: 'test-session',
575+
onResponseChunk: () => {},
576+
},
577+
)
635578

636579
mockedRunProgrammaticStep.clear()
637580

0 commit comments

Comments
 (0)