feat(opcua): compose Equipment VirtualTag plans from VirtualTag+Script rows

This commit is contained in:
Joseph Doherty
2026-06-07 04:54:36 -04:00
parent 45fa198494
commit ae14d98658
2 changed files with 120 additions and 1 deletions
@@ -111,6 +111,77 @@ public sealed class Phase7ComposerPurityTests
p.DependencyRefs.ShouldHaveSingleItem();
}
/// <summary>Compose joins a <see cref="VirtualTag"/> to its <see cref="Script"/> by ScriptId,
/// emitting one <see cref="EquipmentVirtualTagPlan"/> carrying the script source as the
/// Expression and the parsed <c>ctx.GetTag("…")</c> literals as DependencyRefs.</summary>
[Fact]
public void Compose_emits_equipment_virtualtag_plan_joined_to_script()
{
var vt = new VirtualTag
{
VirtualTagId = "vt-1",
EquipmentId = "eq-1",
Name = "speed-rpm",
DataType = "Float64",
ScriptId = "s-1",
};
var script = new Script
{
ScriptId = "s-1",
Name = "speed-script",
SourceCode = "return ctx.GetTag(\"TestMachine_001.TestDouble\").Value;",
SourceHash = "hash-1",
};
var result = Phase7Composer.Compose(
Array.Empty<UnsArea>(), Array.Empty<UnsLine>(), Array.Empty<Equipment>(),
Array.Empty<DriverInstance>(), Array.Empty<ScriptedAlarm>(),
Array.Empty<Tag>(), Array.Empty<Namespace>(),
virtualTags: new[] { vt },
scripts: new[] { script });
var plan = result.EquipmentVirtualTags.ShouldHaveSingleItem();
plan.VirtualTagId.ShouldBe("vt-1");
plan.EquipmentId.ShouldBe("eq-1");
plan.FolderPath.ShouldBe("");
plan.Name.ShouldBe("speed-rpm");
plan.DataType.ShouldBe("Float64");
plan.Expression.ShouldBe("return ctx.GetTag(\"TestMachine_001.TestDouble\").Value;");
plan.DependencyRefs.ShouldBe(new[] { "TestMachine_001.TestDouble" });
}
/// <summary>DependencyRefs are the distinct <c>ctx.GetTag("…")</c> literals in first-seen
/// order — a repeated ref collapses to one.</summary>
[Fact]
public void Compose_extracts_distinct_dependency_refs()
{
var vt = new VirtualTag
{
VirtualTagId = "vt-1",
EquipmentId = "eq-1",
Name = "sum",
DataType = "Float64",
ScriptId = "s-1",
};
var script = new Script
{
ScriptId = "s-1",
Name = "sum-script",
SourceCode = "return ctx.GetTag(\"A.X\").Value + ctx.GetTag(\"B.Y\").Value + ctx.GetTag(\"A.X\").Value;",
SourceHash = "hash-1",
};
var result = Phase7Composer.Compose(
Array.Empty<UnsArea>(), Array.Empty<UnsLine>(), Array.Empty<Equipment>(),
Array.Empty<DriverInstance>(), Array.Empty<ScriptedAlarm>(),
Array.Empty<Tag>(), Array.Empty<Namespace>(),
virtualTags: new[] { vt },
scripts: new[] { script });
var plan = result.EquipmentVirtualTags.ShouldHaveSingleItem();
plan.DependencyRefs.ShouldBe(new[] { "A.X", "B.Y" });
}
private static Equipment NewEquipment(string id) => new()
{
EquipmentId = id,