feat(v3-batch4-wp1): composer/planner emit both Raw + UNS subtrees
Un-darken the address-space composition for the v3 dual namespace. Composer (AddressSpaceComposer): - Raw subtree: RawContainerNode (Folder/Driver/Device/TagGroup as Object/Folder nodes, keyed s=<RawPath>, parent-before-child) + RawTagPlan (raw tag Variables keyed (realm=Raw, s=<RawPath>) carrying DataType / writable / historize+historian tagname / array shape). Native-alarm intent attaches at the RAW tag (ConditionId = RawPath) with the list of referencing equipment UNS paths (one alarm at the raw tag, not one per equipment). - UNS subtree: UnsReferenceVariable per UnsTagReference, keyed (realm=Uns, s=<Area>/<Line>/<Equipment>/<EffectiveName>), carrying its backing RawPath (Organizes UNS->Raw target + fan-out) and inheriting DataType/AccessLevel from the backing raw tag. Effective name = DisplayNameOverride else backing raw Tag.Name. - All RawPaths flow through one shared RawTopology (RawPathResolver + memoised container paths), byte-parity with EquipmentReferenceMap. - Every new node carries an AddressSpaceRealm (so WP3's applier picks the namespace at the call site). Additive/defaulted model changes only — the un-migrated AddressSpaceApplier still compiles. Planner (AddressSpacePlanner.Compute) + AddressSpacePlan: - Per-realm diff sets: RawContainers + RawTags keyed by RawPath (NodeId) so a rename = remove+add; UnsReferenceVariables keyed by the stable UnsTagReferenceId so a backing-tag rename re-points (BackingRawPath moves, NodeId stable) and a display-name-override edit is UNS-only. - PINNED: raw-tag rename = remove+add in Raw AND re-point in UNS. Classifier folds the new sets in (adds->PureAdd, removes->PureRemove, changed->Rebuild safe default). Tests: AddressSpaceComposerDualNamespaceTests (7), AddressSpacePlannerDualNamespaceTests (8, incl. the rename pin), AddressSpaceChangeClassifierDualNamespaceTests (8); reactivated EquipmentNamespaceMaterializationTests' Batch-4-pending case, re-authored to drive the composer over the seeded config (the artifact-decode seam is WP3). Claude-Session: https://claude.ai/code/session_01LVneM3eh1UtJxEisFXgmox
This commit is contained in:
+103
@@ -0,0 +1,103 @@
|
||||
using Shouldly;
|
||||
using Xunit;
|
||||
using ZB.MOM.WW.OtOpcUa.Commons.OpcUa;
|
||||
|
||||
namespace ZB.MOM.WW.OtOpcUa.OpcUaServer.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// v3 Batch 4 (B4-WP1) — the classifier folds the Raw + UNS subtree diff sets into its routing policy:
|
||||
/// raw/uns adds count as adds (PureAdd), removes as removes (PureRemove), and any Changed raw/uns delta
|
||||
/// routes to Rebuild (the safe default — WP3's applier owns surgical refinement).
|
||||
/// </summary>
|
||||
public sealed class AddressSpaceChangeClassifierDualNamespaceTests
|
||||
{
|
||||
private static readonly RawContainerNode Folder = new("Plant", null, "Plant", RawNodeKind.Folder);
|
||||
|
||||
private static RawTagPlan RawTag(string nodeId) =>
|
||||
new("t-1", nodeId, "Plant/Modbus1/PLC-A", "drv-1", "Speed", "Float",
|
||||
Writable: false, Alarm: null, ReferencingEquipmentPaths: Array.Empty<string>());
|
||||
|
||||
private static UnsReferenceVariable UnsRef(string nodeId) =>
|
||||
new("ref-1", "eq-1", nodeId, "Speed", "Plant/Modbus1/PLC-A/Speed", "Float", Writable: false);
|
||||
|
||||
private static AddressSpacePlan Empty() => new(
|
||||
Array.Empty<EquipmentNode>(), Array.Empty<EquipmentNode>(), Array.Empty<AddressSpacePlan.EquipmentDelta>(),
|
||||
Array.Empty<DriverInstancePlan>(), Array.Empty<DriverInstancePlan>(), Array.Empty<AddressSpacePlan.DriverDelta>(),
|
||||
Array.Empty<ScriptedAlarmPlan>(), Array.Empty<ScriptedAlarmPlan>(), Array.Empty<AddressSpacePlan.AlarmDelta>());
|
||||
|
||||
[Fact]
|
||||
public void Added_raw_tag_only_is_PureAdd()
|
||||
{
|
||||
var plan = Empty() with { AddedRawTags = new[] { RawTag("Plant/Modbus1/PLC-A/Speed") } };
|
||||
AddressSpaceChangeClassifier.Classify(plan).ShouldBe(AddressSpaceChangeKind.PureAdd);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Added_raw_container_only_is_PureAdd()
|
||||
{
|
||||
var plan = Empty() with { AddedRawContainers = new[] { Folder } };
|
||||
AddressSpaceChangeClassifier.Classify(plan).ShouldBe(AddressSpaceChangeKind.PureAdd);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Added_uns_reference_only_is_PureAdd()
|
||||
{
|
||||
var plan = Empty() with { AddedUnsReferenceVariables = new[] { UnsRef("filling/line-1/station-1/Speed") } };
|
||||
AddressSpaceChangeClassifier.Classify(plan).ShouldBe(AddressSpaceChangeKind.PureAdd);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Removed_raw_tag_only_is_PureRemove()
|
||||
{
|
||||
var plan = Empty() with { RemovedRawTags = new[] { RawTag("Plant/Modbus1/PLC-A/Speed") } };
|
||||
AddressSpaceChangeClassifier.Classify(plan).ShouldBe(AddressSpaceChangeKind.PureRemove);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Removed_uns_reference_only_is_PureRemove()
|
||||
{
|
||||
var plan = Empty() with { RemovedUnsReferenceVariables = new[] { UnsRef("filling/line-1/station-1/Speed") } };
|
||||
AddressSpaceChangeClassifier.Classify(plan).ShouldBe(AddressSpaceChangeKind.PureRemove);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Raw_rename_add_and_remove_is_AddRemoveMix()
|
||||
{
|
||||
var plan = Empty() with
|
||||
{
|
||||
RemovedRawTags = new[] { RawTag("Plant/Modbus1/PLC-A/Speed") },
|
||||
AddedRawTags = new[] { RawTag("Plant/Modbus1/PLC-A/Velocity") },
|
||||
};
|
||||
AddressSpaceChangeClassifier.Classify(plan).ShouldBe(AddressSpaceChangeKind.AddRemoveMix);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Changed_raw_tag_is_Rebuild()
|
||||
{
|
||||
var plan = Empty() with
|
||||
{
|
||||
ChangedRawTags = new[]
|
||||
{
|
||||
new AddressSpacePlan.RawTagDelta(
|
||||
RawTag("Plant/Modbus1/PLC-A/Speed"),
|
||||
RawTag("Plant/Modbus1/PLC-A/Speed") with { IsHistorized = true }),
|
||||
},
|
||||
};
|
||||
AddressSpaceChangeClassifier.Classify(plan).ShouldBe(AddressSpaceChangeKind.Rebuild);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Uns_reference_repoint_is_Rebuild()
|
||||
{
|
||||
var plan = Empty() with
|
||||
{
|
||||
ChangedUnsReferenceVariables = new[]
|
||||
{
|
||||
new AddressSpacePlan.UnsReferenceDelta(
|
||||
UnsRef("filling/line-1/station-1/Speed"),
|
||||
UnsRef("filling/line-1/station-1/Speed") with { BackingRawPath = "Plant/Modbus1/PLC-A/Velocity" }),
|
||||
},
|
||||
};
|
||||
AddressSpaceChangeClassifier.Classify(plan).ShouldBe(AddressSpaceChangeKind.Rebuild);
|
||||
}
|
||||
}
|
||||
+208
@@ -0,0 +1,208 @@
|
||||
using Shouldly;
|
||||
using Xunit;
|
||||
using ZB.MOM.WW.OtOpcUa.Commons.OpcUa;
|
||||
using ZB.MOM.WW.OtOpcUa.Configuration.Entities;
|
||||
using ZB.MOM.WW.OtOpcUa.Configuration.Enums;
|
||||
|
||||
namespace ZB.MOM.WW.OtOpcUa.OpcUaServer.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// v3 Batch 4 (B4-WP1) — the composer un-darkens BOTH subtrees. Verifies the Raw subtree
|
||||
/// (Folder→Driver→Device→TagGroup container nodes + raw-tag Variables keyed <c>s=<RawPath></c>,
|
||||
/// realm <see cref="AddressSpaceRealm.Raw"/>) and the UNS subtree (one Variable per
|
||||
/// <see cref="UnsTagReference"/> keyed <c>s=<Area>/<Line>/<Equipment>/<EffectiveName></c>,
|
||||
/// realm <see cref="AddressSpaceRealm.Uns"/>, carrying its backing RawPath for the Organizes ref +
|
||||
/// fan-out). Native-alarm intents attach at the RAW tag and carry the referencing equipment paths.
|
||||
/// </summary>
|
||||
public sealed class AddressSpaceComposerDualNamespaceTests
|
||||
{
|
||||
// A raw chain: RawFolder "Plant" → Driver "Modbus1" → Device "PLC-A" → Group "Motors" → tags.
|
||||
// Speed sits under the group; Status directly under the device; Levels is an array tag.
|
||||
private static AddressSpaceComposition ComposeFullFixture()
|
||||
{
|
||||
var folder = new RawFolder { RawFolderId = "raw-plant", ClusterId = "c1", Name = "Plant" };
|
||||
var driver = new DriverInstance
|
||||
{
|
||||
DriverInstanceId = "drv-modbus", ClusterId = "c1", RawFolderId = "raw-plant",
|
||||
Name = "Modbus1", DriverType = "Modbus", DriverConfig = "{}",
|
||||
};
|
||||
var device = new Device { DeviceId = "dev-1", DriverInstanceId = "drv-modbus", Name = "PLC-A", DeviceConfig = "{}" };
|
||||
var group = new TagGroup { TagGroupId = "g1", DeviceId = "dev-1", Name = "Motors" };
|
||||
|
||||
var speed = new Tag
|
||||
{
|
||||
TagId = "t-speed", DeviceId = "dev-1", TagGroupId = "g1", Name = "Speed",
|
||||
DataType = "Float", AccessLevel = TagAccessLevel.ReadWrite,
|
||||
TagConfig = "{\"isHistorized\":true,\"historianTagname\":\"speed_hist\"," +
|
||||
"\"alarm\":{\"alarmType\":\"LimitAlarm\",\"severity\":700}}",
|
||||
};
|
||||
var status = new Tag
|
||||
{
|
||||
TagId = "t-status", DeviceId = "dev-1", Name = "Status",
|
||||
DataType = "Boolean", AccessLevel = TagAccessLevel.Read, TagConfig = "{}",
|
||||
};
|
||||
var levels = new Tag
|
||||
{
|
||||
TagId = "t-levels", DeviceId = "dev-1", Name = "Levels",
|
||||
DataType = "Int32", AccessLevel = TagAccessLevel.Read,
|
||||
TagConfig = "{\"isArray\":true,\"arrayLength\":8}",
|
||||
};
|
||||
|
||||
var area = new UnsArea { UnsAreaId = "area-1", ClusterId = "c1", Name = "filling" };
|
||||
var line = new UnsLine { UnsLineId = "line-1", UnsAreaId = "area-1", Name = "line-1" };
|
||||
var equip = new Equipment { EquipmentId = "eq-1", UnsLineId = "line-1", Name = "station-1", MachineCode = "STATION_001" };
|
||||
|
||||
var refSpeed = new UnsTagReference { UnsTagReferenceId = "ref-speed", EquipmentId = "eq-1", TagId = "t-speed" };
|
||||
var refStatus = new UnsTagReference
|
||||
{
|
||||
UnsTagReferenceId = "ref-status", EquipmentId = "eq-1", TagId = "t-status",
|
||||
DisplayNameOverride = "MachineStatus",
|
||||
};
|
||||
|
||||
return AddressSpaceComposer.Compose(
|
||||
new[] { area }, new[] { line }, new[] { equip },
|
||||
new[] { driver }, Array.Empty<ScriptedAlarm>(),
|
||||
unsTagReferences: new[] { refSpeed, refStatus },
|
||||
tags: new[] { speed, status, levels },
|
||||
rawFolders: new[] { folder },
|
||||
devices: new[] { device },
|
||||
tagGroups: new[] { group });
|
||||
}
|
||||
|
||||
/// <summary>The Raw subtree emits Folder/Driver/Device/TagGroup container nodes keyed by RawPath, each
|
||||
/// realm=Raw, with parents-before-children ordering + correct parent NodeIds.</summary>
|
||||
[Fact]
|
||||
public void Raw_container_nodes_materialise_with_rawpath_nodeids_and_parents()
|
||||
{
|
||||
var c = ComposeFullFixture();
|
||||
|
||||
c.RawContainers.ShouldAllBe(n => n.Realm == AddressSpaceRealm.Raw);
|
||||
|
||||
var folder = c.RawContainers.Single(n => n.Kind == RawNodeKind.Folder);
|
||||
folder.NodeId.ShouldBe("Plant");
|
||||
folder.ParentNodeId.ShouldBeNull(); // cluster root
|
||||
folder.DisplayName.ShouldBe("Plant");
|
||||
|
||||
var driver = c.RawContainers.Single(n => n.Kind == RawNodeKind.Driver);
|
||||
driver.NodeId.ShouldBe("Plant/Modbus1");
|
||||
driver.ParentNodeId.ShouldBe("Plant");
|
||||
|
||||
var device = c.RawContainers.Single(n => n.Kind == RawNodeKind.Device);
|
||||
device.NodeId.ShouldBe("Plant/Modbus1/PLC-A");
|
||||
device.ParentNodeId.ShouldBe("Plant/Modbus1");
|
||||
|
||||
var group = c.RawContainers.Single(n => n.Kind == RawNodeKind.TagGroup);
|
||||
group.NodeId.ShouldBe("Plant/Modbus1/PLC-A/Motors");
|
||||
group.ParentNodeId.ShouldBe("Plant/Modbus1/PLC-A");
|
||||
|
||||
// Sorted by NodeId ordinal ⇒ a parent always precedes each of its children.
|
||||
c.RawContainers.Select(n => n.NodeId)
|
||||
.ShouldBe(new[] { "Plant", "Plant/Modbus1", "Plant/Modbus1/PLC-A", "Plant/Modbus1/PLC-A/Motors" });
|
||||
}
|
||||
|
||||
/// <summary>Raw tags are Variables keyed <c>s=<RawPath></c> (realm=Raw), carrying DataType /
|
||||
/// writable / historize + historian tagname / array shape, and hang under their group (or device).</summary>
|
||||
[Fact]
|
||||
public void Raw_tags_materialise_as_variables_keyed_by_rawpath_with_carried_attributes()
|
||||
{
|
||||
var c = ComposeFullFixture();
|
||||
|
||||
c.RawTags.ShouldAllBe(t => t.Realm == AddressSpaceRealm.Raw);
|
||||
|
||||
var speed = c.RawTags.Single(t => t.TagId == "t-speed");
|
||||
speed.NodeId.ShouldBe("Plant/Modbus1/PLC-A/Motors/Speed");
|
||||
speed.ParentNodeId.ShouldBe("Plant/Modbus1/PLC-A/Motors");
|
||||
speed.DriverInstanceId.ShouldBe("drv-modbus");
|
||||
speed.DataType.ShouldBe("Float");
|
||||
speed.Writable.ShouldBeTrue();
|
||||
speed.IsHistorized.ShouldBeTrue();
|
||||
speed.HistorianTagname.ShouldBe("speed_hist");
|
||||
|
||||
var status = c.RawTags.Single(t => t.TagId == "t-status");
|
||||
status.NodeId.ShouldBe("Plant/Modbus1/PLC-A/Status"); // no group ⇒ under the device
|
||||
status.ParentNodeId.ShouldBe("Plant/Modbus1/PLC-A");
|
||||
status.Writable.ShouldBeFalse();
|
||||
status.IsHistorized.ShouldBeFalse();
|
||||
|
||||
var levels = c.RawTags.Single(t => t.TagId == "t-levels");
|
||||
levels.IsArray.ShouldBeTrue();
|
||||
levels.ArrayLength.ShouldBe(8u);
|
||||
}
|
||||
|
||||
/// <summary>A native-alarm intent attaches at the RAW tag (ConditionId = RawPath) and carries the list
|
||||
/// of referencing equipment UNS folder paths — one alarm at the raw tag, not one per equipment.</summary>
|
||||
[Fact]
|
||||
public void Native_alarm_attaches_at_raw_tag_with_referencing_equipment_paths()
|
||||
{
|
||||
var c = ComposeFullFixture();
|
||||
|
||||
var speed = c.RawTags.Single(t => t.TagId == "t-speed");
|
||||
speed.Alarm.ShouldNotBeNull();
|
||||
speed.Alarm!.AlarmType.ShouldBe("LimitAlarm");
|
||||
speed.Alarm.Severity.ShouldBe(700);
|
||||
speed.ReferencingEquipmentPaths.ShouldBe(new[] { "filling/line-1/station-1" });
|
||||
|
||||
// A non-alarm tag carries no condition + its own referencing-equipment list.
|
||||
var status = c.RawTags.Single(t => t.TagId == "t-status");
|
||||
status.Alarm.ShouldBeNull();
|
||||
status.ReferencingEquipmentPaths.ShouldBe(new[] { "filling/line-1/station-1" });
|
||||
|
||||
// An unreferenced tag has an empty referencing-equipment set.
|
||||
var levels = c.RawTags.Single(t => t.TagId == "t-levels");
|
||||
levels.ReferencingEquipmentPaths.ShouldBeEmpty();
|
||||
}
|
||||
|
||||
/// <summary>Each UnsTagReference emits a UNS Variable keyed
|
||||
/// <c>s=<Area>/<Line>/<Equipment>/<EffectiveName></c> (realm=Uns), carrying its backing
|
||||
/// RawPath (the Organizes target + fan-out) and inheriting DataType + writable from the raw tag. Effective
|
||||
/// name = DisplayNameOverride else the backing raw tag's Name.</summary>
|
||||
[Fact]
|
||||
public void Uns_reference_variables_carry_backing_rawpath_and_inherit_type_and_access()
|
||||
{
|
||||
var c = ComposeFullFixture();
|
||||
|
||||
c.UnsReferenceVariables.ShouldAllBe(v => v.Realm == AddressSpaceRealm.Uns);
|
||||
|
||||
var speedRef = c.UnsReferenceVariables.Single(v => v.UnsTagReferenceId == "ref-speed");
|
||||
speedRef.EffectiveName.ShouldBe("Speed"); // no override ⇒ backing raw tag Name
|
||||
speedRef.NodeId.ShouldBe("filling/line-1/station-1/Speed");
|
||||
speedRef.BackingRawPath.ShouldBe("Plant/Modbus1/PLC-A/Motors/Speed"); // Organizes UNS→Raw + fan-out
|
||||
speedRef.DataType.ShouldBe("Float");
|
||||
speedRef.Writable.ShouldBeTrue(); // inherited from the ReadWrite raw tag
|
||||
|
||||
var statusRef = c.UnsReferenceVariables.Single(v => v.UnsTagReferenceId == "ref-status");
|
||||
statusRef.EffectiveName.ShouldBe("MachineStatus"); // display-name override wins
|
||||
statusRef.NodeId.ShouldBe("filling/line-1/station-1/MachineStatus");
|
||||
statusRef.BackingRawPath.ShouldBe("Plant/Modbus1/PLC-A/Status");
|
||||
statusRef.DataType.ShouldBe("Boolean");
|
||||
statusRef.Writable.ShouldBeFalse(); // inherited from the Read raw tag
|
||||
}
|
||||
|
||||
/// <summary>A composition with no raw/UNS inputs leaves all three new subtree sets empty (the legacy
|
||||
/// convenience overloads + earlier callers keep working).</summary>
|
||||
[Fact]
|
||||
public void No_raw_or_uns_inputs_leaves_both_subtrees_empty()
|
||||
{
|
||||
var c = AddressSpaceComposer.Compose(
|
||||
equipment: Array.Empty<Equipment>(),
|
||||
driverInstances: Array.Empty<DriverInstance>(),
|
||||
scriptedAlarms: Array.Empty<ScriptedAlarm>());
|
||||
|
||||
c.RawContainers.ShouldBeEmpty();
|
||||
c.RawTags.ShouldBeEmpty();
|
||||
c.UnsReferenceVariables.ShouldBeEmpty();
|
||||
}
|
||||
|
||||
/// <summary>The Raw + UNS emit is deterministic — repeated calls produce element-identical output
|
||||
/// (RawTagPlan/UnsReferenceVariable compare by value, so ShouldBe is a content comparison).</summary>
|
||||
[Fact]
|
||||
public void Dual_subtree_emit_is_deterministic()
|
||||
{
|
||||
var a = ComposeFullFixture();
|
||||
var b = ComposeFullFixture();
|
||||
|
||||
a.RawContainers.ShouldBe(b.RawContainers);
|
||||
a.RawTags.ShouldBe(b.RawTags);
|
||||
a.UnsReferenceVariables.ShouldBe(b.UnsReferenceVariables);
|
||||
}
|
||||
}
|
||||
+234
@@ -0,0 +1,234 @@
|
||||
using Shouldly;
|
||||
using Xunit;
|
||||
using ZB.MOM.WW.OtOpcUa.Configuration.Entities;
|
||||
using ZB.MOM.WW.OtOpcUa.Configuration.Enums;
|
||||
|
||||
namespace ZB.MOM.WW.OtOpcUa.OpcUaServer.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// v3 Batch 4 (B4-WP1) — the planner diffs per realm. Raw containers + raw tags diff by RawPath
|
||||
/// (NodeId), so a rename is remove(old)+add(new); UNS reference variables diff by the stable
|
||||
/// <c>UnsTagReferenceId</c>, so a backing-tag rename is a re-point (BackingRawPath moves, NodeId stable)
|
||||
/// and a display-name-override edit is a UNS-only change with no raw delta.
|
||||
/// <para><b>The pinned invariant:</b> a raw-tag rename = remove+add in Raw AND re-point in UNS.</para>
|
||||
/// </summary>
|
||||
public sealed class AddressSpacePlannerDualNamespaceTests
|
||||
{
|
||||
private const string RawFolderName = "Plant";
|
||||
private const string DriverName = "Modbus1";
|
||||
private const string DeviceName = "PLC-A";
|
||||
|
||||
// Compose a fixture with one raw tag (given name) under Plant/Modbus1/PLC-A and one UNS reference to it
|
||||
// (with an optional display-name override so the effective name can be held stable across a raw rename).
|
||||
private static AddressSpaceComposition Compose(string tagName, string? displayOverride)
|
||||
{
|
||||
var folder = new RawFolder { RawFolderId = "raw-plant", ClusterId = "c1", Name = RawFolderName };
|
||||
var driver = new DriverInstance
|
||||
{
|
||||
DriverInstanceId = "drv-modbus", ClusterId = "c1", RawFolderId = "raw-plant",
|
||||
Name = DriverName, DriverType = "Modbus", DriverConfig = "{}",
|
||||
};
|
||||
var device = new Device { DeviceId = "dev-1", DriverInstanceId = "drv-modbus", Name = DeviceName, DeviceConfig = "{}" };
|
||||
var tag = new Tag
|
||||
{
|
||||
TagId = "t-speed", DeviceId = "dev-1", Name = tagName,
|
||||
DataType = "Float", AccessLevel = TagAccessLevel.ReadWrite, TagConfig = "{}",
|
||||
};
|
||||
var area = new UnsArea { UnsAreaId = "area-1", ClusterId = "c1", Name = "filling" };
|
||||
var line = new UnsLine { UnsLineId = "line-1", UnsAreaId = "area-1", Name = "line-1" };
|
||||
var equip = new Equipment { EquipmentId = "eq-1", UnsLineId = "line-1", Name = "station-1", MachineCode = "STATION_001" };
|
||||
var reference = new UnsTagReference
|
||||
{
|
||||
UnsTagReferenceId = "ref-1", EquipmentId = "eq-1", TagId = "t-speed",
|
||||
DisplayNameOverride = displayOverride,
|
||||
};
|
||||
|
||||
return AddressSpaceComposer.Compose(
|
||||
new[] { area }, new[] { line }, new[] { equip },
|
||||
new[] { driver }, Array.Empty<ScriptedAlarm>(),
|
||||
unsTagReferences: new[] { reference },
|
||||
tags: new[] { tag },
|
||||
rawFolders: new[] { folder },
|
||||
devices: new[] { device });
|
||||
}
|
||||
|
||||
/// <summary>A newly-added raw tag surfaces in AddedRawTags (keyed by RawPath); the plan is non-empty.</summary>
|
||||
[Fact]
|
||||
public void Added_raw_tag_goes_to_AddedRawTags()
|
||||
{
|
||||
var prev = Compose("Speed", displayOverride: null);
|
||||
var next = Compose("Speed", displayOverride: null);
|
||||
// prev without the tag: strip RawTags/UNS by composing an empty raw side.
|
||||
var empty = AddressSpaceComposer.Compose(
|
||||
Array.Empty<UnsArea>(), Array.Empty<UnsLine>(), Array.Empty<Equipment>(),
|
||||
Array.Empty<DriverInstance>(), Array.Empty<ScriptedAlarm>());
|
||||
|
||||
var plan = AddressSpacePlanner.Compute(empty, next);
|
||||
|
||||
plan.IsEmpty.ShouldBeFalse();
|
||||
plan.AddedRawTags.Select(t => t.NodeId).ShouldContain("Plant/Modbus1/PLC-A/Speed");
|
||||
plan.RemovedRawTags.ShouldBeEmpty();
|
||||
_ = prev;
|
||||
}
|
||||
|
||||
/// <summary>A disappeared raw tag surfaces in RemovedRawTags.</summary>
|
||||
[Fact]
|
||||
public void Removed_raw_tag_goes_to_RemovedRawTags()
|
||||
{
|
||||
var prev = Compose("Speed", displayOverride: null);
|
||||
var empty = AddressSpaceComposer.Compose(
|
||||
Array.Empty<UnsArea>(), Array.Empty<UnsLine>(), Array.Empty<Equipment>(),
|
||||
Array.Empty<DriverInstance>(), Array.Empty<ScriptedAlarm>());
|
||||
|
||||
var plan = AddressSpacePlanner.Compute(prev, empty);
|
||||
|
||||
plan.RemovedRawTags.Select(t => t.NodeId).ShouldContain("Plant/Modbus1/PLC-A/Speed");
|
||||
plan.AddedRawTags.ShouldBeEmpty();
|
||||
}
|
||||
|
||||
/// <summary>A newly-added UNS reference surfaces in AddedUnsReferenceVariables.</summary>
|
||||
[Fact]
|
||||
public void Added_uns_reference_goes_to_AddedUnsReferenceVariables()
|
||||
{
|
||||
var empty = AddressSpaceComposer.Compose(
|
||||
Array.Empty<UnsArea>(), Array.Empty<UnsLine>(), Array.Empty<Equipment>(),
|
||||
Array.Empty<DriverInstance>(), Array.Empty<ScriptedAlarm>());
|
||||
var next = Compose("Speed", displayOverride: null);
|
||||
|
||||
var plan = AddressSpacePlanner.Compute(empty, next);
|
||||
|
||||
plan.AddedUnsReferenceVariables.Single().UnsTagReferenceId.ShouldBe("ref-1");
|
||||
plan.RemovedUnsReferenceVariables.ShouldBeEmpty();
|
||||
}
|
||||
|
||||
/// <summary>A disappeared UNS reference surfaces in RemovedUnsReferenceVariables.</summary>
|
||||
[Fact]
|
||||
public void Removed_uns_reference_goes_to_RemovedUnsReferenceVariables()
|
||||
{
|
||||
var prev = Compose("Speed", displayOverride: null);
|
||||
var empty = AddressSpaceComposer.Compose(
|
||||
Array.Empty<UnsArea>(), Array.Empty<UnsLine>(), Array.Empty<Equipment>(),
|
||||
Array.Empty<DriverInstance>(), Array.Empty<ScriptedAlarm>());
|
||||
|
||||
var plan = AddressSpacePlanner.Compute(prev, empty);
|
||||
|
||||
plan.RemovedUnsReferenceVariables.Single().UnsTagReferenceId.ShouldBe("ref-1");
|
||||
plan.AddedUnsReferenceVariables.ShouldBeEmpty();
|
||||
}
|
||||
|
||||
/// <summary><b>THE PIN:</b> a raw-tag rename = remove+add in Raw AND re-point in UNS. With a display-name
|
||||
/// override holding the effective name stable, the reference row is unchanged (same UnsTagReferenceId,
|
||||
/// same UNS NodeId) but its backing NodeId moved ⇒ the UNS variable's Organizes target (BackingRawPath)
|
||||
/// re-points via a ChangedUnsReferenceVariables delta.</summary>
|
||||
[Fact]
|
||||
public void Raw_rename_is_remove_add_in_raw_and_repoint_in_uns()
|
||||
{
|
||||
var prev = Compose("Speed", displayOverride: "Spd");
|
||||
var next = Compose("Velocity", displayOverride: "Spd"); // raw tag renamed; effective name held stable
|
||||
|
||||
var plan = AddressSpacePlanner.Compute(prev, next);
|
||||
|
||||
// Raw realm: remove the old RawPath, add the new one (immutable NodeId ⇒ not a Changed delta).
|
||||
plan.RemovedRawTags.Select(t => t.NodeId).ShouldBe(new[] { "Plant/Modbus1/PLC-A/Speed" });
|
||||
plan.AddedRawTags.Select(t => t.NodeId).ShouldBe(new[] { "Plant/Modbus1/PLC-A/Velocity" });
|
||||
plan.ChangedRawTags.ShouldBeEmpty();
|
||||
|
||||
// UNS realm: the reference row is unchanged in identity + NodeId, but re-points to the new RawPath.
|
||||
plan.AddedUnsReferenceVariables.ShouldBeEmpty();
|
||||
plan.RemovedUnsReferenceVariables.ShouldBeEmpty();
|
||||
var repoint = plan.ChangedUnsReferenceVariables.ShouldHaveSingleItem();
|
||||
repoint.Previous.UnsTagReferenceId.ShouldBe("ref-1");
|
||||
repoint.Current.UnsTagReferenceId.ShouldBe("ref-1");
|
||||
repoint.Previous.NodeId.ShouldBe(repoint.Current.NodeId); // effective name stable ⇒ NodeId stable
|
||||
repoint.Previous.BackingRawPath.ShouldBe("Plant/Modbus1/PLC-A/Speed");
|
||||
repoint.Current.BackingRawPath.ShouldBe("Plant/Modbus1/PLC-A/Velocity");
|
||||
|
||||
// The raw container topology (Folder/Driver/Device) is untouched by a tag rename.
|
||||
plan.AddedRawContainers.ShouldBeEmpty();
|
||||
plan.RemovedRawContainers.ShouldBeEmpty();
|
||||
plan.ChangedRawContainers.ShouldBeEmpty();
|
||||
}
|
||||
|
||||
/// <summary>A display-name-override change is a UNS-only change (no raw delta): same reference row id,
|
||||
/// the effective name + UNS NodeId move, the backing RawPath is unchanged.</summary>
|
||||
[Fact]
|
||||
public void Display_name_override_change_is_uns_only_no_raw_change()
|
||||
{
|
||||
var prev = Compose("Speed", displayOverride: "Spd");
|
||||
var next = Compose("Speed", displayOverride: "Speedy"); // only the override changed
|
||||
|
||||
var plan = AddressSpacePlanner.Compute(prev, next);
|
||||
|
||||
// No raw-side change whatsoever.
|
||||
plan.AddedRawTags.ShouldBeEmpty();
|
||||
plan.RemovedRawTags.ShouldBeEmpty();
|
||||
plan.ChangedRawTags.ShouldBeEmpty();
|
||||
plan.AddedRawContainers.ShouldBeEmpty();
|
||||
plan.RemovedRawContainers.ShouldBeEmpty();
|
||||
plan.ChangedRawContainers.ShouldBeEmpty();
|
||||
|
||||
// UNS: same reference row id, effective name + NodeId changed, backing RawPath unchanged.
|
||||
var delta = plan.ChangedUnsReferenceVariables.ShouldHaveSingleItem();
|
||||
delta.Previous.UnsTagReferenceId.ShouldBe("ref-1");
|
||||
delta.Previous.EffectiveName.ShouldBe("Spd");
|
||||
delta.Current.EffectiveName.ShouldBe("Speedy");
|
||||
delta.Previous.NodeId.ShouldNotBe(delta.Current.NodeId);
|
||||
delta.Previous.BackingRawPath.ShouldBe(delta.Current.BackingRawPath);
|
||||
plan.AddedUnsReferenceVariables.ShouldBeEmpty();
|
||||
plan.RemovedUnsReferenceVariables.ShouldBeEmpty();
|
||||
}
|
||||
|
||||
/// <summary>An attribute-only raw-tag edit (historize toggle) keeps the same RawPath ⇒ a
|
||||
/// ChangedRawTags delta (not remove+add).</summary>
|
||||
[Fact]
|
||||
public void Raw_tag_attribute_edit_keeps_nodeid_and_routes_to_ChangedRawTags()
|
||||
{
|
||||
var prev = Compose("Speed", displayOverride: null);
|
||||
// next: same identity + name, but toggle historize on the raw tag.
|
||||
var folder = new RawFolder { RawFolderId = "raw-plant", ClusterId = "c1", Name = RawFolderName };
|
||||
var driver = new DriverInstance
|
||||
{
|
||||
DriverInstanceId = "drv-modbus", ClusterId = "c1", RawFolderId = "raw-plant",
|
||||
Name = DriverName, DriverType = "Modbus", DriverConfig = "{}",
|
||||
};
|
||||
var device = new Device { DeviceId = "dev-1", DriverInstanceId = "drv-modbus", Name = DeviceName, DeviceConfig = "{}" };
|
||||
var tag = new Tag
|
||||
{
|
||||
TagId = "t-speed", DeviceId = "dev-1", Name = "Speed",
|
||||
DataType = "Float", AccessLevel = TagAccessLevel.ReadWrite, TagConfig = "{\"isHistorized\":true}",
|
||||
};
|
||||
var next = AddressSpaceComposer.Compose(
|
||||
Array.Empty<UnsArea>(), Array.Empty<UnsLine>(), Array.Empty<Equipment>(),
|
||||
new[] { driver }, Array.Empty<ScriptedAlarm>(),
|
||||
tags: new[] { tag }, rawFolders: new[] { folder }, devices: new[] { device });
|
||||
|
||||
var prevRawOnly = AddressSpaceComposer.Compose(
|
||||
Array.Empty<UnsArea>(), Array.Empty<UnsLine>(), Array.Empty<Equipment>(),
|
||||
new[] { driver }, Array.Empty<ScriptedAlarm>(),
|
||||
tags: new[] { new Tag { TagId = "t-speed", DeviceId = "dev-1", Name = "Speed", DataType = "Float", AccessLevel = TagAccessLevel.ReadWrite, TagConfig = "{}" } },
|
||||
rawFolders: new[] { folder }, devices: new[] { device });
|
||||
|
||||
var plan = AddressSpacePlanner.Compute(prevRawOnly, next);
|
||||
|
||||
plan.AddedRawTags.ShouldBeEmpty();
|
||||
plan.RemovedRawTags.ShouldBeEmpty();
|
||||
var changed = plan.ChangedRawTags.ShouldHaveSingleItem();
|
||||
changed.Previous.NodeId.ShouldBe(changed.Current.NodeId);
|
||||
changed.Previous.IsHistorized.ShouldBeFalse();
|
||||
changed.Current.IsHistorized.ShouldBeTrue();
|
||||
_ = prev;
|
||||
}
|
||||
|
||||
/// <summary>Identical compositions diff to an empty plan across both realms (fresh list instances must
|
||||
/// not spuriously flag RawTags/UnsReferenceVariables as changed).</summary>
|
||||
[Fact]
|
||||
public void Identical_dual_namespace_compositions_diff_to_empty()
|
||||
{
|
||||
var prev = Compose("Speed", displayOverride: "Spd");
|
||||
var next = Compose("Speed", displayOverride: "Spd");
|
||||
|
||||
var plan = AddressSpacePlanner.Compute(prev, next);
|
||||
|
||||
plan.IsEmpty.ShouldBeTrue();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user