@@ -24,18 +24,24 @@ import * as liveUserInputs from '../live-user-inputs'
2424import { runAgentStep } from '../run-agent-step'
2525import { clearAgentGeneratorCache } from '../run-programmatic-step'
2626import { asUserMessage } from '../util/messages'
27- import * as websocketAction from '../websockets/websocket-action'
2827
2928import type { AgentTemplate } from '../templates/types'
30- import type { AgentRuntimeDeps } from '@codebuff/common/types/contracts/agent-runtime'
29+ import type {
30+ AgentRuntimeDeps ,
31+ AgentRuntimeScopedDeps ,
32+ } from '@codebuff/common/types/contracts/agent-runtime'
3133import type { ProjectFileContext } from '@codebuff/common/util/file'
3234import type { WebSocket } from 'ws'
3335
3436describe ( 'runAgentStep - set_output tool' , ( ) => {
3537 let testAgent : AgentTemplate
36- let agentRuntimeImpl : AgentRuntimeDeps = { ...TEST_AGENT_RUNTIME_IMPL }
38+ let agentRuntimeImpl : AgentRuntimeDeps
39+ let agentRuntimeScopedImpl : AgentRuntimeScopedDeps
3740
3841 beforeEach ( async ( ) => {
42+ agentRuntimeImpl = { ...TEST_AGENT_RUNTIME_IMPL }
43+ agentRuntimeScopedImpl = { ...TEST_AGENT_RUNTIME_SCOPED_IMPL }
44+
3945 // Create a test agent that supports set_output
4046 testAgent = {
4147 id : 'test-set-output-agent' ,
@@ -78,32 +84,27 @@ describe('runAgentStep - set_output tool', () => {
7884 spyOn ( liveUserInputs , 'startUserInput' ) . mockImplementation ( ( ) => { } )
7985 spyOn ( liveUserInputs , 'setSessionConnected' ) . mockImplementation ( ( ) => { } )
8086
81- spyOn ( websocketAction , 'requestFiles' ) . mockImplementation (
82- async ( params : { ws : any ; filePaths : string [ ] } ) => {
83- const results : Record < string , string | null > = { }
84- params . filePaths . forEach ( ( p ) => {
85- if ( p === 'src/auth.ts' ) {
86- results [ p ] = 'export function authenticate() { return true; }'
87- } else if ( p === 'src/user.ts' ) {
88- results [ p ] = 'export interface User { id: string; name: string; }'
89- } else {
90- results [ p ] = null
91- }
92- } )
93- return results
94- } ,
95- )
96-
97- spyOn ( websocketAction , 'requestFile' ) . mockImplementation (
98- async ( params : { ws : any ; filePath : string } ) => {
99- if ( params . filePath === 'src/auth.ts' ) {
100- return 'export function authenticate() { return true; }'
101- } else if ( params . filePath === 'src/user.ts' ) {
102- return 'export interface User { id: string; name: string; }'
87+ agentRuntimeScopedImpl . requestFiles = async ( { filePaths } ) => {
88+ const results : Record < string , string | null > = { }
89+ filePaths . forEach ( ( p ) => {
90+ if ( p === 'src/auth.ts' ) {
91+ results [ p ] = 'export function authenticate() { return true; }'
92+ } else if ( p === 'src/user.ts' ) {
93+ results [ p ] = 'export interface User { id: string; name: string; }'
94+ } else {
95+ results [ p ] = null
10396 }
104- return null
105- } ,
106- )
97+ } )
98+ return results
99+ }
100+ agentRuntimeScopedImpl . requestOptionalFile = async ( { filePath } ) => {
101+ if ( filePath === 'src/auth.ts' ) {
102+ return 'export function authenticate() { return true; }'
103+ } else if ( filePath === 'src/user.ts' ) {
104+ return 'export interface User { id: string; name: string; }'
105+ }
106+ return null
107+ }
107108
108109 // Don't mock requestToolCall for integration test - let real tool execution happen
109110
@@ -116,7 +117,6 @@ describe('runAgentStep - set_output tool', () => {
116117
117118 afterEach ( ( ) => {
118119 mock . restore ( )
119- agentRuntimeImpl = { ...TEST_AGENT_RUNTIME_IMPL }
120120 } )
121121
122122 afterAll ( ( ) => {
@@ -363,19 +363,17 @@ describe('runAgentStep - set_output tool', () => {
363363 }
364364
365365 // Mock requestFiles to return test file content
366- spyOn ( websocketAction , 'requestFiles' ) . mockImplementation (
367- async ( params : { ws : any ; filePaths : string [ ] } ) => {
368- const results : Record < string , string | null > = { }
369- params . filePaths . forEach ( ( p ) => {
370- if ( p === 'src/test.ts' ) {
371- results [ p ] = 'export function testFunction() { return "test"; }'
372- } else {
373- results [ p ] = null
374- }
375- } )
376- return results
377- } ,
378- )
366+ agentRuntimeScopedImpl . requestFiles = async ( { filePaths } ) => {
367+ const results : Record < string , string | null > = { }
368+ filePaths . forEach ( ( p ) => {
369+ if ( p === 'src/test.ts' ) {
370+ results [ p ] = 'export function testFunction() { return "test"; }'
371+ } else {
372+ results [ p ] = null
373+ }
374+ } )
375+ return results
376+ }
379377
380378 // Mock the LLM stream to return a response that doesn't end the turn
381379 agentRuntimeImpl . promptAiSdkStream = async function * ( { } ) {
0 commit comments