Skip to content

Commit 4fde2f1

Browse files
committed
fix tests
1 parent 2166ccb commit 4fde2f1

File tree

5 files changed

+57
-34
lines changed

5 files changed

+57
-34
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ describe('loopAgentSteps - runAgentStep vs runProgrammaticStep behavior', () =>
141141
ancestorRunIds: [],
142142
onResponseChunk: () => {},
143143
signal: new AbortController().signal,
144-
tools: {},
145144
}
146145
})
147146

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

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

104103
// Mock analytics and tracing

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

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

packages/agent-runtime/src/__tests__/propose-tools.test.ts

Lines changed: 42 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -294,12 +294,14 @@ export function multiply(a: number, b: number): number {
294294
}
295295
toolResultsCapture.push(step.toolResult)
296296

297+
const firstResult = step.toolResult?.[0]
298+
const unifiedDiff = firstResult?.type === 'json' ? (firstResult.value as { unifiedDiff?: string })?.unifiedDiff : undefined
297299
yield {
298300
toolName: 'set_output',
299301
input: {
300302
toolCalls: [{ toolName: 'propose_str_replace', input: step }],
301303
toolResults: step.toolResult,
302-
unifiedDiffs: step.toolResult?.[0]?.value?.unifiedDiff ?? '',
304+
unifiedDiffs: unifiedDiff ?? '',
303305
},
304306
}
305307
yield { toolName: 'end_turn', input: {} }
@@ -321,9 +323,10 @@ export function multiply(a: number, b: number): number {
321323
const toolResult = toolResultsCapture[0]
322324
expect(toolResult).toBeDefined()
323325
expect(toolResult[0].type).toBe('json')
324-
expect(toolResult[0].value.file).toBe('src/utils.ts')
325-
expect(toolResult[0].value.unifiedDiff).toContain('+export function multiply')
326-
expect(toolResult[0].value.unifiedDiff).toContain('return a * b')
326+
const jsonResult = toolResult[0] as { type: 'json'; value: { file: string; unifiedDiff: string } }
327+
expect(jsonResult.value.file).toBe('src/utils.ts')
328+
expect(jsonResult.value.unifiedDiff).toContain('+export function multiply')
329+
expect(jsonResult.value.unifiedDiff).toContain('return a * b')
327330
})
328331

329332
it('should return error when string not found', async () => {
@@ -351,7 +354,8 @@ export function multiply(a: number, b: number): number {
351354

352355
expect(toolResultsCapture).toHaveLength(1)
353356
const toolResult = toolResultsCapture[0]
354-
expect(toolResult[0].value.errorMessage).toContain('String not found')
357+
const jsonResult = toolResult[0] as { type: 'json'; value: { errorMessage: string } }
358+
expect(jsonResult.value.errorMessage).toContain('String not found')
355359
})
356360

357361
it('should stack multiple replacements on the same file', async () => {
@@ -396,8 +400,10 @@ export function multiply(a: number, b: number): number {
396400
expect(toolResultsCapture).toHaveLength(2)
397401

398402
// Both replacements should succeed
399-
expect(toolResultsCapture[0].result[0].value.unifiedDiff).toContain('// addition')
400-
expect(toolResultsCapture[1].result[0].value.unifiedDiff).toContain('// subtraction')
403+
const result0 = toolResultsCapture[0].result[0] as { type: 'json'; value: { unifiedDiff: string } }
404+
const result1 = toolResultsCapture[1].result[0] as { type: 'json'; value: { unifiedDiff: string } }
405+
expect(result0.value.unifiedDiff).toContain('// addition')
406+
expect(result1.value.unifiedDiff).toContain('// subtraction')
401407

402408
// Final file should have both changes
403409
expect(mockFiles['src/utils.ts']).toContain('// addition')
@@ -431,9 +437,10 @@ export function multiply(a: number, b: number): number {
431437

432438
expect(toolResultsCapture).toHaveLength(1)
433439
const toolResult = toolResultsCapture[0]
434-
expect(toolResult[0].value.file).toBe('src/multiply.ts')
435-
expect(toolResult[0].value.message).toContain('new file')
436-
expect(toolResult[0].value.unifiedDiff).toContain('+export function multiply')
440+
const jsonResult = toolResult[0] as { type: 'json'; value: { file: string; message: string; unifiedDiff: string } }
441+
expect(jsonResult.value.file).toBe('src/multiply.ts')
442+
expect(jsonResult.value.message).toContain('new file')
443+
expect(jsonResult.value.unifiedDiff).toContain('+export function multiply')
437444
})
438445

439446
it('should propose file edit and return unified diff', async () => {
@@ -469,9 +476,10 @@ export function multiply(a: number, b: number): number {
469476

470477
expect(toolResultsCapture).toHaveLength(1)
471478
const toolResult = toolResultsCapture[0]
472-
expect(toolResult[0].value.file).toBe('src/utils.ts')
473-
expect(toolResult[0].value.message).toContain('changes')
474-
expect(toolResult[0].value.unifiedDiff).toContain('+export function multiply')
479+
const jsonResult = toolResult[0] as { type: 'json'; value: { file: string; message: string; unifiedDiff: string } }
480+
expect(jsonResult.value.file).toBe('src/utils.ts')
481+
expect(jsonResult.value.message).toContain('changes')
482+
expect(jsonResult.value.unifiedDiff).toContain('+export function multiply')
475483
})
476484
})
477485

@@ -498,10 +506,12 @@ export function multiply(a: number, b: number): number {
498506
}],
499507
},
500508
}
509+
const step1First = step1.toolResult?.[0]
510+
const step1HasDiff = step1First?.type === 'json' && !!(step1First.value as { unifiedDiff?: string })?.unifiedDiff
501511
receivedToolResults.push({
502512
step: 1,
503513
toolResult: step1.toolResult,
504-
hasUnifiedDiff: !!step1.toolResult?.[0]?.value?.unifiedDiff,
514+
hasUnifiedDiff: step1HasDiff,
505515
})
506516

507517
// Second tool call - another propose_str_replace
@@ -516,10 +526,12 @@ export function multiply(a: number, b: number): number {
516526
}],
517527
},
518528
}
529+
const step2First = step2.toolResult?.[0]
530+
const step2HasDiff = step2First?.type === 'json' && !!(step2First.value as { unifiedDiff?: string })?.unifiedDiff
519531
receivedToolResults.push({
520532
step: 2,
521533
toolResult: step2.toolResult,
522-
hasUnifiedDiff: !!step2.toolResult?.[0]?.value?.unifiedDiff,
534+
hasUnifiedDiff: step2HasDiff,
523535
})
524536

525537
// Third tool call - propose_write_file
@@ -531,10 +543,12 @@ export function multiply(a: number, b: number): number {
531543
content: 'export const newFile = true;',
532544
},
533545
}
546+
const step3First = step3.toolResult?.[0]
547+
const step3HasDiff = step3First?.type === 'json' && !!(step3First.value as { unifiedDiff?: string })?.unifiedDiff
534548
receivedToolResults.push({
535549
step: 3,
536550
toolResult: step3.toolResult,
537-
hasUnifiedDiff: !!step3.toolResult?.[0]?.value?.unifiedDiff,
551+
hasUnifiedDiff: step3HasDiff,
538552
})
539553

540554
yield { toolName: 'end_turn', input: {} }
@@ -553,22 +567,25 @@ export function multiply(a: number, b: number): number {
553567
expect(receivedToolResults[0].step).toBe(1)
554568
expect(receivedToolResults[0].toolResult).toBeDefined()
555569
expect(receivedToolResults[0].hasUnifiedDiff).toBe(true)
556-
expect(receivedToolResults[0].toolResult[0].value.file).toBe('src/utils.ts')
557-
expect(receivedToolResults[0].toolResult[0].value.unifiedDiff).toContain('first change')
570+
const step1Result = receivedToolResults[0].toolResult[0] as { type: 'json'; value: { file: string; unifiedDiff: string } }
571+
expect(step1Result.value.file).toBe('src/utils.ts')
572+
expect(step1Result.value.unifiedDiff).toContain('first change')
558573

559574
// Step 2: Should have received tool result with unified diff
560575
expect(receivedToolResults[1].step).toBe(2)
561576
expect(receivedToolResults[1].toolResult).toBeDefined()
562577
expect(receivedToolResults[1].hasUnifiedDiff).toBe(true)
563-
expect(receivedToolResults[1].toolResult[0].value.file).toBe('src/utils.ts')
564-
expect(receivedToolResults[1].toolResult[0].value.unifiedDiff).toContain('second change')
578+
const step2Result = receivedToolResults[1].toolResult[0] as { type: 'json'; value: { file: string; unifiedDiff: string } }
579+
expect(step2Result.value.file).toBe('src/utils.ts')
580+
expect(step2Result.value.unifiedDiff).toContain('second change')
565581

566582
// Step 3: Should have received tool result with unified diff for new file
567583
expect(receivedToolResults[2].step).toBe(3)
568584
expect(receivedToolResults[2].toolResult).toBeDefined()
569585
expect(receivedToolResults[2].hasUnifiedDiff).toBe(true)
570-
expect(receivedToolResults[2].toolResult[0].value.file).toBe('src/new-file.ts')
571-
expect(receivedToolResults[2].toolResult[0].value.message).toContain('new file')
586+
const step3Result = receivedToolResults[2].toolResult[0] as { type: 'json'; value: { file: string; message: string } }
587+
expect(step3Result.value.file).toBe('src/new-file.ts')
588+
expect(step3Result.value.message).toContain('new file')
572589
})
573590

574591
it('should collect tool calls and results for output', async () => {
@@ -607,8 +624,9 @@ export function multiply(a: number, b: number): number {
607624
toolName: 'propose_str_replace',
608625
input: step1,
609626
})
610-
if (step1.toolResult?.[0]?.value) {
611-
capturedToolResults.push(step1.toolResult[0].value)
627+
const step1First = step1.toolResult?.[0]
628+
if (step1First?.type === 'json' && step1First.value) {
629+
capturedToolResults.push(step1First.value)
612630
}
613631

614632
// Generate unified diffs string from captured results

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

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ describe('Spawn Agents Permissions', () => {
2929
typeof handleSpawnAgents,
3030
'agentState' | 'agentTemplate' | 'localAgentTemplates' | 'toolCall'
3131
>
32+
let handleSpawnAgentInlineBaseParams: ParamsExcluding<
33+
typeof handleSpawnAgentInline,
34+
'agentState' | 'agentTemplate' | 'localAgentTemplates' | 'toolCall'
35+
>
3236

3337
const createMockAgent = (
3438
id: string,
@@ -67,12 +71,16 @@ describe('Spawn Agents Permissions', () => {
6771
sendSubagentChunk: mockSendSubagentChunk,
6872
signal: new AbortController().signal,
6973
system: 'Test system prompt',
70-
tools: {},
7174
userId: TEST_USER_ID,
7275
userInputId: 'test-input',
7376
writeToClient: () => {},
7477
}
7578

79+
handleSpawnAgentInlineBaseParams = {
80+
...handleSpawnAgentsBaseParams,
81+
tools: {},
82+
}
83+
7684
// Mock sendSubagentChunk
7785
mockSendSubagentChunk = mock(() => {})
7886

@@ -426,7 +434,7 @@ describe('Spawn Agents Permissions', () => {
426434

427435
// Should not throw
428436
await handleSpawnAgentInline({
429-
...handleSpawnAgentsBaseParams,
437+
...handleSpawnAgentInlineBaseParams,
430438
agentState: sessionState.mainAgentState,
431439
agentTemplate: parentAgent,
432440
localAgentTemplates: { thinker: childAgent },
@@ -443,7 +451,7 @@ describe('Spawn Agents Permissions', () => {
443451
const toolCall = createInlineSpawnToolCall('reviewer') // Try to spawn reviewer
444452

445453
const result = handleSpawnAgentInline({
446-
...handleSpawnAgentsBaseParams,
454+
...handleSpawnAgentInlineBaseParams,
447455
agentState: sessionState.mainAgentState,
448456
agentTemplate: parentAgent,
449457
localAgentTemplates: { reviewer: childAgent },
@@ -462,7 +470,7 @@ describe('Spawn Agents Permissions', () => {
462470
const toolCall = createInlineSpawnToolCall('nonexistent')
463471

464472
const result = handleSpawnAgentInline({
465-
...handleSpawnAgentsBaseParams,
473+
...handleSpawnAgentInlineBaseParams,
466474
agentState: sessionState.mainAgentState,
467475
agentTemplate: parentAgent,
468476
localAgentTemplates: {}, // Empty - agent not found
@@ -481,7 +489,7 @@ describe('Spawn Agents Permissions', () => {
481489

482490
// Should not throw
483491
await handleSpawnAgentInline({
484-
...handleSpawnAgentsBaseParams,
492+
...handleSpawnAgentInlineBaseParams,
485493
agentState: sessionState.mainAgentState,
486494
agentTemplate: parentAgent,
487495
localAgentTemplates: { 'codebuff/thinker@1.0.0': childAgent },
@@ -499,7 +507,7 @@ describe('Spawn Agents Permissions', () => {
499507

500508
// Should not throw
501509
await handleSpawnAgentInline({
502-
...handleSpawnAgentsBaseParams,
510+
...handleSpawnAgentInlineBaseParams,
503511
agentState: sessionState.mainAgentState,
504512
agentTemplate: parentAgent,
505513
localAgentTemplates: {
@@ -519,7 +527,7 @@ describe('Spawn Agents Permissions', () => {
519527
const toolCall = createInlineSpawnToolCall('codebuff/thinker@2.0.0')
520528

521529
const result = handleSpawnAgentInline({
522-
...handleSpawnAgentsBaseParams,
530+
...handleSpawnAgentInlineBaseParams,
523531
agentState: sessionState.mainAgentState,
524532
agentTemplate: parentAgent,
525533
localAgentTemplates: { 'codebuff/thinker@2.0.0': childAgent },

0 commit comments

Comments
 (0)