Merge branch 'review/wp6' into review/integration

# Conflicts:
#	docs/requirements/Component-StoreAndForward.md
#	src/ZB.MOM.WW.ScadaBridge.ConfigurationDatabase/Repositories/DeploymentManagerRepository.cs
#	src/ZB.MOM.WW.ScadaBridge.StoreAndForward/StoreAndForwardStorage.cs
#	src/ZB.MOM.WW.ScadaBridge.Transport/Import/BundleImporter.cs
#	tests/ZB.MOM.WW.ScadaBridge.StoreAndForward.Tests/StoreAndForwardStorageTests.cs
This commit is contained in:
Joseph Doherty
2026-12-03 11:03:44 -05:00
84 changed files with 4722 additions and 233 deletions
@@ -0,0 +1,56 @@
using ZB.MOM.WW.ScadaBridge.SiteRuntime.Scripts;
namespace ZB.MOM.WW.ScadaBridge.SiteRuntime.Tests.Scripts;
/// <summary>
/// SRT-7 (WP6 6.2): an Expression trigger is routed by the literal attribute keys it reads,
/// and falls back to all-changes whenever those keys cannot be pinned down.
/// </summary>
public class TriggerExpressionKeysTests
{
/// <summary>Literal root and child reads are extracted as canonical keys.</summary>
[Theory]
[InlineData("(double)Attributes[\"Temp\"] > 50", new[] { "Temp" })]
[InlineData("(double)Attributes[\"A\"] > (double)Attributes[\"B\"] && Attributes[\"A\"] != null", new[] { "A", "B" })]
[InlineData("(double)Children[\"Pump1\"].Attributes[\"Speed\"] > 10", new[] { "Pump1.Speed" })]
[InlineData("Attributes[\"Mode\"] as string == \"Auto\" || (bool)Children[\"V\"].Attributes[\"Open\"]", new[] { "Mode", "V.Open" })]
public void LiteralReads_AreExtracted(string expression, string[] expected)
{
Assert.True(TriggerExpressionKeys.TryExtract(expression, out var keys));
Assert.Equal(expected, keys);
}
/// <summary>Anything that is not a recognised literal read falls back to all-changes.</summary>
[Theory]
[InlineData("true")] // no attribute read (may depend on the clock)
[InlineData("DateTime.UtcNow.Second == 0")]
[InlineData("Attributes[\"A\" + \"B\"] != null")] // non-literal key
[InlineData("Attributes[name] != null")]
[InlineData("Parent != null")]
[InlineData("Children[\"P\"].Attributes[k] != null")] // non-literal child key
[InlineData("Children[c].Attributes[\"S\"] != null")] // non-literal child name
[InlineData("((Func<object>)(() => Attributes))() != null")] // alias of the global
[InlineData("(double)Attributes[\"A\"] > 1 && this.Attributes[\"B\"] != null")]
[InlineData("(double)Attributes[\"A\" > 1")] // parse error
[InlineData("")]
public void UnpinnableReads_FallBack(string expression)
{
Assert.False(TriggerExpressionKeys.TryExtract(expression, out _));
}
/// <summary>Routing decisions for Expression scripts and alarms use the extracted keys.</summary>
[Fact]
public void ExpressionRouting_UsesKeysOrFallsBack()
{
var keyed = TriggerRouting.ForScript("Expression", "{\"expression\":\"(double)Attributes[\\\"A\\\"] > 1\"}");
Assert.Equal(TriggerRoutingKind.MonitoredAttributes, keyed.Kind);
Assert.Equal(new[] { "A" }, keyed.MonitoredAttributeSet);
var alarm = TriggerRouting.ForAlarm("Expression", "{\"expression\":\"Children[\\\"P\\\"].Attributes[\\\"X\\\"] != null\"}");
Assert.Equal(TriggerRoutingKind.MonitoredAttributes, alarm.Kind);
Assert.Equal(new[] { "P.X" }, alarm.MonitoredAttributeSet);
Assert.Equal(TriggerRoutingKind.AllChanges, TriggerRouting.ForScript("Expression", "{\"expression\":\"true\"}").Kind);
Assert.Equal(TriggerRoutingKind.AllChanges, TriggerRouting.ForAlarm("Expression", "not json").Kind);
}
}