@@ -12,7 +12,6 @@ import {
1212} from 'bun:test'
1313
1414import * as messageCostTracker from '../llm-apis/message-cost-tracker'
15- import * as aisdk from '../llm-apis/vercel-ai-sdk/ai-sdk'
1615import { mainPrompt } from '../main-prompt'
1716import * as agentRegistry from '../templates/agent-registry'
1817import * as websocketAction from '../websockets/websocket-action'
@@ -372,29 +371,27 @@ describe('Cost Aggregation Integration Tests', () => {
372371 it ( 'should maintain cost integrity when subagents fail' , async ( ) => {
373372 // Mock scenario where subagent fails after incurring partial costs
374373 let callCount = 0
375- spyOn ( aisdk , 'promptAiSdkStream' ) . mockImplementation (
376- async function * ( options ) {
377- callCount ++
374+ agentRuntimeImpl . promptAiSdkStream = async function * ( options ) {
375+ callCount ++
378376
379- if ( options . onCostCalculated ) {
380- await options . onCostCalculated ( 6 ) // Each call costs 6 credits
381- }
377+ if ( options . onCostCalculated ) {
378+ await options . onCostCalculated ( 6 ) // Each call costs 6 credits
379+ }
382380
383- if ( callCount === 1 ) {
384- // Main agent spawns subagent
385- yield {
386- type : 'text' as const ,
387- text : '<codebuff_tool_call>\n{"cb_tool_name": "spawn_agents", "agents": [{"agent_type": "editor", "prompt": "This will fail"}]}\n</codebuff_tool_call>' ,
388- }
389- } else {
390- // Subagent fails after incurring cost
391- yield { type : 'text' as const , text : 'Some response' }
392- throw new Error ( 'Subagent execution failed' )
381+ if ( callCount === 1 ) {
382+ // Main agent spawns subagent
383+ yield {
384+ type : 'text' as const ,
385+ text : '<codebuff_tool_call>\n{"cb_tool_name": "spawn_agents", "agents": [{"agent_type": "editor", "prompt": "This will fail"}]}\n</codebuff_tool_call>' ,
393386 }
387+ } else {
388+ // Subagent fails after incurring cost
389+ yield { type : 'text' as const , text : 'Some response' }
390+ throw new Error ( 'Subagent execution failed' )
391+ }
394392
395- return 'mock-message-id'
396- } ,
397- )
393+ return 'mock-message-id'
394+ }
398395
399396 const sessionState = getInitialSessionState ( mockFileContext )
400397 sessionState . mainAgentState . agentType = 'base'
0 commit comments