@@ -294,6 +294,63 @@ describe('ContextEnrichmentService', () => {
294294 } ) ;
295295 } ) ;
296296
297+ it ( "should set an error value when step isn't found (getStepById returns undefined)" , async ( ) => {
298+ const mockFlow = {
299+ version : {
300+ trigger : { id : 'trigger-id' } ,
301+ } ,
302+ } as PopulatedFlow ;
303+
304+ const mockInputContext = {
305+ flowId : mockFlowId ,
306+ flowVersionId : mockFlowVersionId ,
307+ steps : [
308+ {
309+ id : 'step-unknown' ,
310+ variables : [
311+ {
312+ name : 'variable1' ,
313+ value : '{{some.expression}}' ,
314+ } ,
315+ ] ,
316+ } ,
317+ ] ,
318+ } ;
319+
320+ mockFlowService . getOnePopulatedOrThrow . mockResolvedValue ( mockFlow ) ;
321+ mockAccessTokenManager . generateEngineToken . mockResolvedValue (
322+ mockEngineToken ,
323+ ) ;
324+ mockFlowHelper . getAllStepIds . mockReturnValue ( [ 'step-unknown' ] ) ;
325+ mockFlowHelper . getStepById . mockReturnValue ( undefined ) ;
326+ mockFlowStepTestOutputService . listEncrypted . mockResolvedValue ( [ ] ) ;
327+ mockGroupStepOutputsById . mockReturnValue ( { } ) ;
328+
329+ const result = await enrichContext ( mockInputContext , mockProjectId ) ;
330+
331+ expect ( result ) . toEqual ( {
332+ flowId : mockFlowId ,
333+ flowVersionId : mockFlowVersionId ,
334+ currentStepId : undefined ,
335+ currentStepData : '' ,
336+ steps : [
337+ {
338+ id : 'step-unknown' ,
339+ variables : [
340+ {
341+ name : 'variable1' ,
342+ value :
343+ 'Failed to resolve variable: Step not found in the workflow.' ,
344+ } ,
345+ ] ,
346+ } ,
347+ ] ,
348+ } ) ;
349+
350+ // Ensure engine is not called when step cannot be found
351+ expect ( mockEngineRunner . executeVariable ) . not . toHaveBeenCalled ( ) ;
352+ } ) ;
353+
297354 it ( 'should handle engine runner exceptions' , async ( ) => {
298355 const mockFlow = {
299356 version : {
0 commit comments