Skip to content

Commit 109f2aa

Browse files
committed
fix tests
1 parent 0b9db4d commit 109f2aa

File tree

2 files changed

+23
-17
lines changed

2 files changed

+23
-17
lines changed

apps/sim/executor/handlers/condition/condition-handler.test.ts

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -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

apps/sim/executor/handlers/condition/condition-handler.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ export async function evaluateConditionExpression(
3838
}
3939

4040
try {
41-
const code = `return Boolean(${resolvedConditionValue})`
41+
const contextSetup = `const context = ${JSON.stringify(evalContext)};`
42+
const code = `${contextSetup}\nreturn Boolean(${resolvedConditionValue})`
4243

4344
const result = await executeTool(
4445
'function_execute',

0 commit comments

Comments
 (0)