@@ -70,11 +70,7 @@ describe('loopAgentSteps - runAgentStep vs runProgrammaticStep behavior', () =>
7070
7171 // Mock file reading updates
7272 mockModule ( '@codebuff/backend/get-file-reading-updates' , ( ) => ( {
73- getFileReadingUpdates : async ( ) => ( {
74- addedFiles : [ ] ,
75- updatedFilePaths : [ ] ,
76- clearReadFileToolResults : false ,
77- } ) ,
73+ getFileReadingUpdates : async ( ) => [ ] ,
7874 } ) )
7975
8076 // Mock async agent manager
@@ -167,16 +163,16 @@ describe('loopAgentSteps - runAgentStep vs runProgrammaticStep behavior', () =>
167163 } )
168164
169165 it ( 'should verify correct STEP behavior - LLM called once after STEP' , async ( ) => {
170- // This test verifies that programmatic agents don't call the LLM ,
171- // and that STEP yielding works correctly without LLM involvement
166+ // This test verifies that when a programmatic agent yields STEP ,
167+ // the LLM should be called once in the next iteration
172168
173169 let stepCount = 0
174170 const mockGeneratorFunction = function * ( ) {
175171 stepCount ++
176172 // Execute a tool, then STEP
177173 yield { toolName : 'read_files' , input : { paths : [ 'file1.txt' ] } }
178- yield 'STEP' // Should pause here
179- // Continue after LLM runs
174+ yield 'STEP' // Should pause here and let LLM run
175+ // Continue after LLM runs (this won't be reached in this test since LLM ends turn)
180176 yield {
181177 toolName : 'write_file' ,
182178 input : { path : 'output.txt' , content : 'test' } ,
@@ -190,14 +186,10 @@ describe('loopAgentSteps - runAgentStep vs runProgrammaticStep behavior', () =>
190186 'test-agent' : mockTemplate ,
191187 }
192188
193- // Mock checkLiveUserInput to return true for multiple iterations
194- let checkCallCount = 0
189+ // Mock checkLiveUserInput to allow the loop to continue
195190 const mockCheckLiveUserInput = require ( '@codebuff/backend/live-user-inputs' )
196191 spyOn ( mockCheckLiveUserInput , 'checkLiveUserInput' ) . mockImplementation (
197- ( ) => {
198- checkCallCount ++
199- return true
200- } ,
192+ ( ) => true , // Always return true to allow loop to continue
201193 )
202194
203195 const result = await loopAgentSteps (
@@ -210,7 +202,6 @@ describe('loopAgentSteps - runAgentStep vs runProgrammaticStep behavior', () =>
210202 params : undefined ,
211203 fingerprintId : 'test-fingerprint' ,
212204 fileContext : mockFileContext ,
213- toolResults : [ ] ,
214205 localAgentTemplates,
215206 userId : TEST_USER_ID ,
216207 clientSessionId : 'test-session' ,
@@ -221,14 +212,12 @@ describe('loopAgentSteps - runAgentStep vs runProgrammaticStep behavior', () =>
221212 console . log ( `LLM calls made: ${ llmCallCount } ` )
222213 console . log ( `Step count: ${ stepCount } ` )
223214
224- // CORRECT BEHAVIOR: After STEP, LLM should be called once, then no more
225- // The programmatic agent yields STEP, then LLM runs once
215+ // CORRECT BEHAVIOR: After STEP, LLM should be called once
216+ // The programmatic agent yields STEP, then LLM runs once and ends turn
226217 expect ( llmCallCount ) . toBe ( 1 ) // LLM called once after STEP
227218
228219 // The programmatic agent should have been called once (yielded STEP)
229220 expect ( stepCount ) . toBe ( 1 )
230-
231- // After STEP, the LLM should run once, then the loop should continue correctly
232221 } )
233222
234223 it ( 'should demonstrate correct behavior when programmatic agent completes without STEP' , async ( ) => {
@@ -260,7 +249,6 @@ describe('loopAgentSteps - runAgentStep vs runProgrammaticStep behavior', () =>
260249 params : undefined ,
261250 fingerprintId : 'test-fingerprint' ,
262251 fileContext : mockFileContext ,
263- toolResults : [ ] ,
264252 localAgentTemplates,
265253 userId : TEST_USER_ID ,
266254 clientSessionId : 'test-session' ,
@@ -301,13 +289,9 @@ describe('loopAgentSteps - runAgentStep vs runProgrammaticStep behavior', () =>
301289 }
302290
303291 // Mock checkLiveUserInput to allow multiple iterations
304- let checkCallCount = 0
305292 const mockCheckLiveUserInput = require ( '@codebuff/backend/live-user-inputs' )
306293 spyOn ( mockCheckLiveUserInput , 'checkLiveUserInput' ) . mockImplementation (
307- ( ) => {
308- checkCallCount ++
309- return checkCallCount <= 5 // Allow enough iterations
310- } ,
294+ ( ) => true , // Always return true to allow loop to continue
311295 )
312296
313297 const result = await loopAgentSteps (
@@ -320,7 +304,6 @@ describe('loopAgentSteps - runAgentStep vs runProgrammaticStep behavior', () =>
320304 params : undefined ,
321305 fingerprintId : 'test-fingerprint' ,
322306 fileContext : mockFileContext ,
323- toolResults : [ ] ,
324307 localAgentTemplates,
325308 userId : TEST_USER_ID ,
326309 clientSessionId : 'test-session' ,
@@ -378,7 +361,6 @@ describe('loopAgentSteps - runAgentStep vs runProgrammaticStep behavior', () =>
378361 params : undefined ,
379362 fingerprintId : 'test-fingerprint' ,
380363 fileContext : mockFileContext ,
381- toolResults : [ ] ,
382364 localAgentTemplates,
383365 userId : TEST_USER_ID ,
384366 clientSessionId : 'test-session' ,
@@ -420,7 +402,6 @@ describe('loopAgentSteps - runAgentStep vs runProgrammaticStep behavior', () =>
420402 params : undefined ,
421403 fingerprintId : 'test-fingerprint' ,
422404 fileContext : mockFileContext ,
423- toolResults : [ ] ,
424405 localAgentTemplates,
425406 userId : TEST_USER_ID ,
426407 clientSessionId : 'test-session' ,
@@ -463,7 +444,6 @@ describe('loopAgentSteps - runAgentStep vs runProgrammaticStep behavior', () =>
463444 params : undefined ,
464445 fingerprintId : 'test-fingerprint' ,
465446 fileContext : mockFileContext ,
466- toolResults : [ ] ,
467447 localAgentTemplates,
468448 userId : TEST_USER_ID ,
469449 clientSessionId : 'test-session' ,
@@ -508,7 +488,6 @@ describe('loopAgentSteps - runAgentStep vs runProgrammaticStep behavior', () =>
508488 params : undefined ,
509489 fingerprintId : 'test-fingerprint' ,
510490 fileContext : mockFileContext ,
511- toolResults : [ ] ,
512491 localAgentTemplates,
513492 userId : TEST_USER_ID ,
514493 clientSessionId : 'test-session' ,
@@ -520,7 +499,7 @@ describe('loopAgentSteps - runAgentStep vs runProgrammaticStep behavior', () =>
520499 expect ( llmCallCount ) . toBe ( 0 )
521500 expect ( result . agentState ) . toBeDefined ( )
522501 expect ( result . agentState . output ?. error ) . toContain (
523- 'Programmatic step failed ' ,
502+ 'Error executing handleSteps for agent test-agent ' ,
524503 )
525504 } )
526505
@@ -570,7 +549,6 @@ describe('loopAgentSteps - runAgentStep vs runProgrammaticStep behavior', () =>
570549 params : undefined ,
571550 fingerprintId : 'test-fingerprint' ,
572551 fileContext : mockFileContext ,
573- toolResults : [ ] ,
574552 localAgentTemplates,
575553 userId : TEST_USER_ID ,
576554 clientSessionId : 'test-session' ,
@@ -628,7 +606,6 @@ describe('loopAgentSteps - runAgentStep vs runProgrammaticStep behavior', () =>
628606 params : undefined ,
629607 fingerprintId : 'test-fingerprint' ,
630608 fileContext : mockFileContext ,
631- toolResults : [ ] ,
632609 localAgentTemplates,
633610 userId : TEST_USER_ID ,
634611 clientSessionId : 'test-session' ,
@@ -684,7 +661,6 @@ describe('loopAgentSteps - runAgentStep vs runProgrammaticStep behavior', () =>
684661 params : undefined ,
685662 fingerprintId : 'test-fingerprint' ,
686663 fileContext : mockFileContext ,
687- toolResults : [ ] ,
688664 localAgentTemplates,
689665 userId : TEST_USER_ID ,
690666 clientSessionId : 'test-session' ,
0 commit comments