feat(siteruntime): thread ParentExecutionId into the routed script's ScriptRuntimeContext
This commit is contained in:
@@ -3,6 +3,7 @@ using Akka.TestKit.Xunit2;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
using ScadaLink.Commons.Messages.Deployment;
|
||||
using ScadaLink.Commons.Messages.InboundApi;
|
||||
using ScadaLink.Commons.Messages.Lifecycle;
|
||||
using ScadaLink.Commons.Types.Enums;
|
||||
using ScadaLink.Commons.Types.Flattening;
|
||||
@@ -68,6 +69,28 @@ public class DeploymentManagerActorTests : TestKit, IDisposable
|
||||
return JsonSerializer.Serialize(config);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds a config carrying a single callable (no-trigger) script that
|
||||
/// returns a constant — enough for an inbound <see cref="RouteToCallRequest"/>
|
||||
/// to be routed end-to-end through the Instance/Script/ScriptExecution actors.
|
||||
/// </summary>
|
||||
private static string MakeConfigWithScriptJson(string instanceName, string scriptName)
|
||||
{
|
||||
var config = new FlattenedConfiguration
|
||||
{
|
||||
InstanceUniqueName = instanceName,
|
||||
Attributes =
|
||||
[
|
||||
new ResolvedAttribute { CanonicalName = "TestAttr", Value = "42", DataType = "Int32" }
|
||||
],
|
||||
Scripts =
|
||||
[
|
||||
new ResolvedScript { CanonicalName = scriptName, Code = "return 7;" }
|
||||
]
|
||||
};
|
||||
return JsonSerializer.Serialize(config);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task DeploymentManager_CreatesInstanceActors_FromStoredConfigs()
|
||||
{
|
||||
@@ -240,4 +263,57 @@ public class DeploymentManagerActorTests : TestKit, IDisposable
|
||||
var response = ExpectMsg<DeploymentStatusResponse>(TimeSpan.FromSeconds(5));
|
||||
Assert.Equal(DeploymentStatus.Success, response.Status);
|
||||
}
|
||||
|
||||
// ── Audit Log #23 (ParentExecutionId, Task 4): inbound-API routing ──
|
||||
|
||||
[Fact]
|
||||
public async Task RouteInboundApiCall_WithParentExecutionId_RoutesToScriptSuccessfully()
|
||||
{
|
||||
// A RouteToCallRequest carrying a ParentExecutionId (the inbound
|
||||
// request's ExecutionId) must be mapped to a ScriptCallRequest and
|
||||
// routed end-to-end through the Instance/Script/ScriptExecution actors.
|
||||
// The additive ParentExecutionId field must not break that routing.
|
||||
var actor = CreateDeploymentManager();
|
||||
await Task.Delay(500); // empty startup
|
||||
|
||||
actor.Tell(new DeployInstanceCommand(
|
||||
"dep-route", "RoutedPump", "sha256:route",
|
||||
MakeConfigWithScriptJson("RoutedPump", "DoWork"), "admin", DateTimeOffset.UtcNow));
|
||||
ExpectMsg<DeploymentStatusResponse>(TimeSpan.FromSeconds(5));
|
||||
await Task.Delay(1000); // let the InstanceActor + ScriptActor spin up
|
||||
|
||||
var parentExecutionId = Guid.NewGuid();
|
||||
actor.Tell(new RouteToCallRequest(
|
||||
"route-corr-1", "RoutedPump", "DoWork",
|
||||
Parameters: null, DateTimeOffset.UtcNow, ParentExecutionId: parentExecutionId));
|
||||
|
||||
var response = ExpectMsg<RouteToCallResponse>(TimeSpan.FromSeconds(10));
|
||||
Assert.Equal("route-corr-1", response.CorrelationId);
|
||||
Assert.True(response.Success, $"Routed call failed: {response.ErrorMessage}");
|
||||
Assert.Equal(7, Convert.ToInt32(response.ReturnValue));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task RouteInboundApiCall_WithoutParentExecutionId_StillRoutes()
|
||||
{
|
||||
// A routed call with no ParentExecutionId (e.g. the Central UI sandbox)
|
||||
// is the additive-default path — it must route exactly as before.
|
||||
var actor = CreateDeploymentManager();
|
||||
await Task.Delay(500);
|
||||
|
||||
actor.Tell(new DeployInstanceCommand(
|
||||
"dep-route2", "RoutedPump2", "sha256:route2",
|
||||
MakeConfigWithScriptJson("RoutedPump2", "DoWork"), "admin", DateTimeOffset.UtcNow));
|
||||
ExpectMsg<DeploymentStatusResponse>(TimeSpan.FromSeconds(5));
|
||||
await Task.Delay(1000);
|
||||
|
||||
// No ParentExecutionId argument — exercises the additive `= null` default.
|
||||
actor.Tell(new RouteToCallRequest(
|
||||
"route-corr-2", "RoutedPump2", "DoWork",
|
||||
Parameters: null, DateTimeOffset.UtcNow));
|
||||
|
||||
var response = ExpectMsg<RouteToCallResponse>(TimeSpan.FromSeconds(10));
|
||||
Assert.Equal("route-corr-2", response.CorrelationId);
|
||||
Assert.True(response.Success, $"Routed call failed: {response.ErrorMessage}");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user