MCPcopy
hub / github.com/simstudioai/sim / createControllableReadyProc

Function createControllableReadyProc

apps/sim/lib/execution/isolated-vm.test.ts:99–131  ·  view source on GitHub ↗

* A ready worker whose execution is held open until ControllableReadyProc.release * is called. ControllableReadyProc.dispatched resolves the moment the worker * receives its `execute` message — i.e. once the scheduler has counted the execution as * active — giving tests a determin

()

Source from the content-addressed store, hash-verified

97 * its `ready` event is emitted only after the module attaches its listeners.
98 */
99function createControllableReadyProc(): ControllableReadyProc {
100 let markDispatched: () => void = () => {}
101 const dispatched = new Promise<void>((resolve) => {
102 markDispatched = resolve
103 })
104 let proc: MockProc | undefined
105 let lastExecutionId = 0
106
107 const spawn: SpawnFactory = () => {
108 const current = createBaseProc()
109 current.send = (message: unknown) => {
110 const msg = message as { type?: string; executionId?: number }
111 if (msg.type === 'execute') {
112 lastExecutionId = msg.executionId ?? 0
113 markDispatched()
114 }
115 return true
116 }
117 setImmediate(() => current.emit('message', { type: 'ready' }))
118 proc = current
119 return current
120 }
121
122 const release = (result: unknown = 'released') => {
123 proc?.emit('message', {
124 type: 'result',
125 executionId: lastExecutionId,
126 result: { result, stdout: '' },
127 })
128 }
129
130 return { spawn, dispatched, release }
131}
132
133function createReadyFetchProxyProc(fetchMessage: { url: string; optionsJson?: string }): MockProc {
134 const proc = createBaseProc()

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected