@@ -3,6 +3,11 @@ import {
33 createSerializedBlock ,
44 createSerializedWorkflow ,
55} from '@sim/testing/factories/serialized-block.factory'
6+ import {
7+ evaluateLoopIndexCheck ,
8+ isolatedVmMock ,
9+ isolatedVmMockFns ,
10+ } from '@sim/testing/mocks/isolated-vm.mock'
611import { beforeEach , describe , expect , it , vi } from 'vitest'
712import { BlockType , DEFAULTS } from '@/executor/constants'
813import { DAGExecutor } from '@/executor/execution/executor'
@@ -17,14 +22,7 @@ const { bodyRuns, conditionResult, runaway } = vi.hoisted(() => ({
1722 runaway : { controller : new AbortController ( ) , limit : 30_000 } ,
1823} ) )
1924
20- /** Count conditions resolve to `return Boolean(<index> < <count>)`; user conditions stay opaque. */
21- vi . mock ( '@/lib/execution/isolated-vm' , ( ) => ( {
22- executeInIsolatedVM : vi . fn ( async ( { code } : { code : string } ) => {
23- const indexCheck = / ^ r e t u r n B o o l e a n \( ( \d + ) < ( \d + ) \) $ / . exec ( code )
24- if ( indexCheck ) return { result : Number ( indexCheck [ 1 ] ) < Number ( indexCheck [ 2 ] ) }
25- return { result : bodyRuns . count < conditionResult . stopAfter }
26- } ) ,
27- } ) )
25+ vi . mock ( '@/lib/execution/isolated-vm' , ( ) => isolatedVmMock )
2826
2927vi . mock ( '@/executor/handlers/registry' , ( ) => ( {
3028 createBlockHandlers : ( ) => [
@@ -80,6 +78,10 @@ describe('condition-driven loop iteration ceiling', () => {
8078 bodyRuns . count = 0
8179 conditionResult . stopAfter = Number . POSITIVE_INFINITY
8280 runaway . controller = new AbortController ( )
81+ /** Count conditions evaluate; user conditions stay opaque and hold until `stopAfter`. */
82+ isolatedVmMockFns . mockExecuteInIsolatedVM . mockImplementation ( async ( { code } ) => ( {
83+ result : evaluateLoopIndexCheck ( code ) ?? bodyRuns . count < conditionResult . stopAfter ,
84+ } ) )
8385 } )
8486
8587 it . each ( [
0 commit comments