@@ -17,27 +17,32 @@ vi.mock('@/lib/core/utils/request', () => ({
1717 generateRequestId : vi . fn ( ( ) => 'test-request-id' ) ,
1818} ) )
1919
20- vi . mock ( '@/lib/execution/isolated-vm ' , ( ) => ( {
21- executeInIsolatedVM : vi . fn ( ) ,
20+ vi . mock ( '@/tools ' , ( ) => ( {
21+ executeTool : vi . fn ( ) ,
2222} ) )
2323
24- import { executeInIsolatedVM } from '@/lib/execution/isolated-vm '
24+ import { executeTool } from '@/tools '
2525
26- const mockExecuteInIsolatedVM = executeInIsolatedVM as ReturnType < typeof vi . fn >
26+ const mockExecuteTool = executeTool as ReturnType < typeof vi . fn >
2727
28- function simulateIsolatedVMExecution (
29- code : string ,
30- contextVariables : Record < string , unknown >
31- ) : { result : unknown ; stdout : string ; error ?: { message : string ; name : string } } {
28+ /**
29+ * Simulates what the function_execute tool does when evaluating condition code
30+ */
31+ function simulateConditionExecution ( code : string ) : {
32+ success : boolean
33+ output ?: { result : unknown }
34+ error ?: string
35+ } {
3236 try {
33- const fn = new Function ( ...Object . keys ( contextVariables ) , code )
34- const result = fn ( ...Object . values ( contextVariables ) )
35- return { result, stdout : '' }
37+ // The code is in format: "const context = {...};\nreturn Boolean(...)"
38+ // We need to execute it and return the result
39+ const fn = new Function ( code )
40+ const result = fn ( )
41+ return { success : true , output : { result } }
3642 } catch ( error : any ) {
3743 return {
38- result : null ,
39- stdout : '' ,
40- error : { message : error . message , name : error . name || 'Error' } ,
44+ success : false ,
45+ error : error . message ,
4146 }
4247 }
4348}
@@ -143,8 +148,8 @@ describe('ConditionBlockHandler', () => {
143148
144149 vi . clearAllMocks ( )
145150
146- mockExecuteInIsolatedVM . mockImplementation ( async ( { code, contextVariables } ) => {
147- return simulateIsolatedVMExecution ( code , contextVariables )
151+ mockExecuteTool . mockImplementation ( async ( _toolId : string , params : { code : string } ) => {
152+ return simulateConditionExecution ( params . code )
148153 } )
149154 } )
150155
0 commit comments