Skip to content

Commit

Permalink
Include transient variables in merged variables for JavaScriptEngine …
Browse files Browse the repository at this point in the history
…Access (#4769)

## Summary
This pull request introduces changes to the handling of transient variables in the `WorkflowExecutionContext.cs`. The aim is to include transient variables in the merged variables collection, enhancing their accessibility to the JavaScriptEngine. This change is expected to improve the functionality and flexibility of variable handling within workflows.

## Changes
- Modified the `GetMergedVariables()` method in `WorkflowExecutionContext.cs` to start the aggregation with the TransientState and then merge the `WorkflowInstance.Variables` at the end. This ensures that transient variables are included in the merged variables.

## Added
- A new test case in `WorkflowExecutionContextTests.cs` to verify that transient variables set in the execution context are retrievable in the merged variable collection after the changes.

## Impact
These changes allow for transient variables to be more accessible and functional within the JavaScriptEngine, enhancing the overall workflow execution capabilities.

Co-authored-by: JoostVanVelthoven <j.vanvelthoven@effytool.nl>
  • Loading branch information
JoostVanVelthoven and JoostVanVelthoven authored Jan 15, 2024
1 parent 83b6bc4 commit 8f39424
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,17 @@ public Variables GetMergedVariables()
{
var scopes = WorkflowInstance.Scopes.ToList();

var mergedVariables = scopes.Select(x => x.Variables).Aggregate(WorkflowInstance.Variables, (current, next) =>
{
var combined = current.Data.MergedWith(next.Data);
return new Variables(combined);
});

return mergedVariables;
var mergedVariables = scopes.Select(x => x.Variables)
.Aggregate(WorkflowInstance.Variables, (current, next) =>
{
var combined = current.Data.MergedWith(next.Data);
return new Variables(combined);
});

var finalCombined = TransientState?.Data != null
? mergedVariables.Data.MergedWith(TransientState.Data)
: mergedVariables.Data;
return new Variables(finalCombined);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,17 @@ public void PurgeVariables_clears_workflow_execution_context_workflow_instance_v

Assert.Empty(sut.WorkflowInstance.Variables.Data);
}

[Theory(DisplayName = "Transient variables should be retrievable in merged variable collection"), AutoMoqData]
public void TransientVariableSetInExecutionContext_ShouldBeRetrievable([WithAutofixtureResolution, Frozen] IServiceProvider serviceProvider,
[OmitOnRecursion] WorkflowExecutionContext workflowExecutionContext,
IActivityBlueprint activityBlueprint,
CancellationToken cancellationToken)
{
var sut = new ActivityExecutionContext(serviceProvider, workflowExecutionContext, activityBlueprint, null, false, cancellationToken);
sut.SetTransientVariable("foo", "bar");

Assert.Equal("bar", sut.GetVariable("foo"));
}
}
}

0 comments on commit 8f39424

Please sign in to comment.