Skip to content

Commit 1eaa9ed

Browse files
committed
Fix types/tests
1 parent a35f682 commit 1eaa9ed

File tree

8 files changed

+40
-36
lines changed

8 files changed

+40
-36
lines changed

packages/agent-runtime/src/__tests__/cost-aggregation.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ describe('Cost Aggregation System', () => {
148148
stepsRemaining: 10,
149149
creditsUsed: 50, // Parent starts with some cost
150150
directCreditsUsed: 50,
151+
systemPrompt: 'Test system prompt',
152+
toolDefinitions: {},
151153
}
152154

153155
// Mock executeAgent to return results with different credit costs

packages/agent-runtime/src/__tests__/loop-agent-steps.test.ts

Lines changed: 22 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ describe('loopAgentSteps - runAgentStep vs runProgrammaticStep behavior', () =>
141141
ancestorRunIds: [],
142142
onResponseChunk: () => {},
143143
signal: new AbortController().signal,
144+
tools: {},
144145
}
145146
})
146147

@@ -418,32 +419,24 @@ describe('loopAgentSteps - runAgentStep vs runProgrammaticStep behavior', () =>
418419
})
419420

420421
it('should pass shouldEndTurn: true as stepsComplete when end_turn tool is called', async () => {
421-
// Test that when LLM calls end_turn, shouldEndTurn is correctly passed to runProgrammaticStep
422-
423-
let runProgrammaticStepCalls: any[] = []
424-
425-
// Mock runProgrammaticStep module to capture calls and verify stepsComplete parameter
426-
const mockedRunProgrammaticStep = await mockModule(
427-
'@codebuff/agent-runtime/run-programmatic-step',
428-
() => ({
429-
runProgrammaticStep: async (params: any) => {
430-
runProgrammaticStepCalls.push(params)
431-
// First call: return endTurn false to continue
432-
// Second call: return endTurn true to end the loop
433-
const shouldEnd = runProgrammaticStepCalls.length >= 2
434-
return {
435-
agentState: params.agentState,
436-
endTurn: shouldEnd,
437-
stepNumber: params.stepNumber,
438-
}
439-
},
440-
clearAgentGeneratorCache: () => {},
441-
runIdToStepAll: new Set(),
442-
}),
443-
)
422+
// Test that when LLM calls end_turn, shouldEndTurn (stepsComplete) is correctly passed
423+
// to the handleSteps generator via the step result.
424+
//
425+
// Flow:
426+
// 1. Generator yields 'STEP', runProgrammaticStep returns
427+
// 2. loopAgentSteps calls runAgentStep (LLM), which calls end_turn -> shouldEndTurn = true
428+
// 3. loopAgentSteps calls runProgrammaticStep again with stepsComplete: true
429+
// 4. Generator resumes from yield 'STEP' and receives { stepsComplete: true }
430+
431+
let stepsCompleteValues: boolean[] = []
444432

445433
const mockGeneratorFunction = function* () {
446-
yield 'STEP' // Hand control to LLM
434+
// First STEP - after LLM runs and calls end_turn, we receive stepsComplete: true
435+
const result1 = yield 'STEP'
436+
stepsCompleteValues.push(result1.stepsComplete)
437+
438+
// Since stepsComplete was true, we should end gracefully
439+
yield { toolName: 'end_turn', input: {} }
447440
} as () => StepGenerator
448441

449442
mockTemplate.handleSteps = mockGeneratorFunction
@@ -458,18 +451,11 @@ describe('loopAgentSteps - runAgentStep vs runProgrammaticStep behavior', () =>
458451
localAgentTemplates,
459452
})
460453

461-
mockedRunProgrammaticStep.clear()
462-
463-
// Verify that runProgrammaticStep was called twice:
464-
// 1. First with stepsComplete: false (initial call)
465-
// 2. Second with stepsComplete: true (after LLM called end_turn)
466-
expect(runProgrammaticStepCalls).toHaveLength(2)
467-
468-
// First call should have stepsComplete: false
469-
expect(runProgrammaticStepCalls[0].stepsComplete).toBe(false)
470-
471-
// Second call should have stepsComplete: true (after end_turn tool was called)
472-
expect(runProgrammaticStepCalls[1].stepsComplete).toBe(true)
454+
// Verify that stepsComplete was passed correctly:
455+
// After yielding STEP and LLM running (which calls end_turn),
456+
// the generator receives stepsComplete: true
457+
expect(stepsCompleteValues).toHaveLength(1)
458+
expect(stepsCompleteValues[0]).toBe(true)
473459
})
474460

475461
it('should continue loop when handleSteps returns endTurn: false even if LLM calls end_turn', async () => {

packages/agent-runtime/src/__tests__/main-prompt.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ describe('mainPrompt', () => {
9898
onResponseChunk: () => {},
9999
localAgentTemplates: mockLocalAgentTemplates,
100100
signal: new AbortController().signal,
101+
tools: {},
101102
}
102103

103104
// Mock analytics and tracing

packages/agent-runtime/src/__tests__/malformed-tool-call.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ describe('malformed tool call error handling', () => {
8484
fullResponse: '',
8585
prompt: '',
8686
signal: new AbortController().signal,
87+
tools: {},
8788
}
8889

8990
// Mock analytics and tracing

packages/agent-runtime/src/__tests__/n-parameter.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ describe('n parameter and GENERATE_N functionality', () => {
259259
stepNumber: 1,
260260
logger,
261261
signal: new AbortController().signal,
262+
tools: {},
262263
})
263264

264265
expect(result.generateN).toBe(nValue)
@@ -298,6 +299,7 @@ describe('n parameter and GENERATE_N functionality', () => {
298299
stepNumber: 1,
299300
logger,
300301
signal: new AbortController().signal,
302+
tools: {},
301303
})
302304

303305
expect(result.generateN).toBeUndefined()
@@ -362,6 +364,7 @@ describe('n parameter and GENERATE_N functionality', () => {
362364
stepNumber: 1,
363365
logger,
364366
signal: new AbortController().signal,
367+
tools: {},
365368
}
366369

367370
// First call: programmatic step yields GENERATE_N
@@ -444,6 +447,7 @@ describe('n parameter and GENERATE_N functionality', () => {
444447
stepNumber: 1,
445448
logger,
446449
signal: new AbortController().signal,
450+
tools: {},
447451
}
448452

449453
// First call: execute read_files and yield GENERATE_N
@@ -539,6 +543,7 @@ describe('n parameter and GENERATE_N functionality', () => {
539543
stepNumber: 1,
540544
logger,
541545
signal: new AbortController().signal,
546+
tools: {},
542547
}
543548

544549
// First GENERATE_N
@@ -603,6 +608,7 @@ describe('n parameter and GENERATE_N functionality', () => {
603608
stepNumber: 1,
604609
logger,
605610
signal: new AbortController().signal,
611+
tools: {},
606612
})
607613

608614
expect(result.generateN).toBe(1)
@@ -641,6 +647,7 @@ describe('n parameter and GENERATE_N functionality', () => {
641647
stepNumber: 1,
642648
logger,
643649
signal: new AbortController().signal,
650+
tools: {},
644651
}
645652

646653
await runProgrammaticStep(mockParams)
@@ -687,6 +694,7 @@ describe('n parameter and GENERATE_N functionality', () => {
687694
stepNumber: 1,
688695
logger,
689696
signal: new AbortController().signal,
697+
tools: {},
690698
}
691699

692700
await runProgrammaticStep(mockParams)
@@ -730,6 +738,7 @@ describe('n parameter and GENERATE_N functionality', () => {
730738
stepNumber: 1,
731739
logger,
732740
signal: new AbortController().signal,
741+
tools: {},
733742
}
734743

735744
const result1 = await runProgrammaticStep(mockParams)
@@ -792,6 +801,7 @@ describe('n parameter and GENERATE_N functionality', () => {
792801
stepNumber: 1,
793802
logger,
794803
signal: new AbortController().signal,
804+
tools: {},
795805
}
796806

797807
// First call yields GENERATE_N
@@ -839,6 +849,7 @@ describe('n parameter and GENERATE_N functionality', () => {
839849
stepNumber: 1,
840850
logger,
841851
signal: new AbortController().signal,
852+
tools: {},
842853
})
843854

844855
// Should still set generateN even though endTurn will be true

packages/agent-runtime/src/__tests__/prompt-caching-subagents.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ describe('Prompt Caching for Subagents with inheritParentSystemPrompt', () => {
136136
ancestorRunIds: [],
137137
onResponseChunk: () => {},
138138
signal: new AbortController().signal,
139+
tools: {},
139140
}
140141
})
141142

packages/agent-runtime/src/__tests__/run-programmatic-step.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ describe('runProgrammaticStep', () => {
135135
system: 'Test system prompt',
136136
stepsComplete: false,
137137
stepNumber: 1,
138+
tools: {},
138139

139140
logger,
140141
signal: new AbortController().signal,

packages/agent-runtime/src/__tests__/sandbox-generator.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ describe('QuickJS Sandbox Generator', () => {
8989
stepsComplete: false,
9090
stepNumber: 1,
9191
signal: new AbortController().signal,
92+
tools: {},
9293
}
9394
})
9495

0 commit comments

Comments
 (0)