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:
+55
-46
@@ -4,10 +4,12 @@ using Shouldly;
|
||||
using Xunit;
|
||||
using ZB.MOM.WW.OtOpcUa.Commons.Interfaces;
|
||||
using ZB.MOM.WW.OtOpcUa.Commons.Messages.Admin;
|
||||
using ZB.MOM.WW.OtOpcUa.Commons.OpcUa;
|
||||
using ZB.MOM.WW.OtOpcUa.Configuration;
|
||||
using ZB.MOM.WW.OtOpcUa.Configuration.Entities;
|
||||
using ZB.MOM.WW.OtOpcUa.Configuration.Enums;
|
||||
using ZB.MOM.WW.OtOpcUa.Configuration.Validation;
|
||||
using ZB.MOM.WW.OtOpcUa.OpcUaServer;
|
||||
using ZB.MOM.WW.OtOpcUa.Runtime.Drivers;
|
||||
|
||||
namespace ZB.MOM.WW.OtOpcUa.Host.IntegrationTests;
|
||||
@@ -15,15 +17,21 @@ namespace ZB.MOM.WW.OtOpcUa.Host.IntegrationTests;
|
||||
/// <summary>
|
||||
/// End-to-end deploy of a UNS folder hierarchy through the <b>real</b> <c>ConfigComposer</c>: seed a
|
||||
/// 1-area / 1-line / 1-equipment UNS plus a v3 raw-tag chain (RawFolder → DriverInstance → Device →
|
||||
/// Tag), <c>StartDeployment</c>, then assert the deployment's persisted artifact decodes (via
|
||||
/// Tag) + a <see cref="UnsTagReference"/> projecting the raw tag into the equipment, <c>StartDeployment</c>,
|
||||
/// then assert the deployment's persisted artifact decodes (via
|
||||
/// <see cref="DeploymentArtifact.ParseComposition"/>).
|
||||
/// <para>
|
||||
/// <b>v3 DARK address space (Batch 1):</b> the composer + artifact deliberately emit an EMPTY
|
||||
/// equipment-tag plan set — raw-tag variable nodes are lit up in Batch 4's dual-namespace UNS↔Raw
|
||||
/// fan-out. So the live assertion here is the DARK contract: the Area/Line/Equipment folder nodes
|
||||
/// decode with their friendly UNS names, and <c>EquipmentTags</c> is empty EVEN THOUGH a raw tag was
|
||||
/// seeded. The full equipment-signal materialization (raw tag → EquipmentTag with FullName) is
|
||||
/// preserved as a Batch-4-pending Skipped test below (the plan explicitly says keep it, don't delete).
|
||||
/// <b>v3 dual namespace (Batch 4):</b> the <c>AddressSpaceComposer</c> un-darkens BOTH subtrees. The
|
||||
/// <see cref="Deploying_a_uns_hierarchy_carries_folder_nodes_and_leaves_equipment_tags_dark"/> case pins the
|
||||
/// artifact-decode invariant that the retired equipment-namespace <c>EquipmentTags</c> set stays EMPTY
|
||||
/// (values now flow through the raw + UNS variable nodes). The
|
||||
/// <see cref="Composing_the_seeded_config_emits_the_raw_tag_and_uns_reference_variables"/> case drives the
|
||||
/// real <c>AddressSpaceComposer</c> over the SAME seeded config (loaded back from the deploy DB) and pins
|
||||
/// the Batch-4 dual-tree: the seeded raw tag surfaces as a Raw-realm Variable keyed by its RawPath, and the
|
||||
/// UnsTagReference surfaces as a UNS-realm Variable carrying that RawPath (the Organizes target + fan-out).
|
||||
/// <para><i>Note:</i> the composer is what WP1 lights up; the artifact-decode seam
|
||||
/// (<c>DeploymentArtifact.ParseComposition</c>) is migrated by WP3, so the dual-tree assertion runs through
|
||||
/// the composer directly rather than the full deploy → artifact round-trip.</para>
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// The OPC UA address-space browse is exercised separately against a real SDK node manager in
|
||||
@@ -33,12 +41,6 @@ namespace ZB.MOM.WW.OtOpcUa.Host.IntegrationTests;
|
||||
/// </summary>
|
||||
public sealed class EquipmentNamespaceMaterializationTests
|
||||
{
|
||||
private const string Batch4Pending =
|
||||
"v3 dark address space: equipment-tag variable plans (raw tag → EquipmentTag with FullName) do " +
|
||||
"not materialize until Batch 4 (dual-namespace UNS↔Raw fan-out). The composer + artifact emit an " +
|
||||
"empty equipment-tag plan set this batch; re-enable this full-materialization assertion (re-authored " +
|
||||
"against the UnsTagReference fan-out) when Batch 4 lights the raw/UNS variable nodes.";
|
||||
|
||||
private static CancellationToken Ct => TestContext.Current.CancellationToken;
|
||||
|
||||
// Equipment.EquipmentId must equal DraftValidator.DeriveEquipmentId(EquipmentUuid) — the
|
||||
@@ -95,47 +97,49 @@ public sealed class EquipmentNamespaceMaterializationTests
|
||||
composition.EquipmentTags.ShouldBeEmpty();
|
||||
}
|
||||
|
||||
/// <summary>BATCH-4-PENDING: the full equipment-signal materialization — the seeded raw tag decodes
|
||||
/// (via the real ConfigComposer → ParseComposition) into an EquipmentTag carrying its FullName. Dark
|
||||
/// until Batch 4's UNS↔Raw fan-out; preserved (not deleted) so re-enabling is a one-line change once
|
||||
/// the equipment-tag plan set is lit up.</summary>
|
||||
[Fact(Skip = Batch4Pending)]
|
||||
public async Task Deploying_an_equipment_namespace_carries_the_signal_into_the_artifact()
|
||||
/// <summary>BATCH-4 dual namespace: the real <see cref="AddressSpaceComposer"/> over the seeded config
|
||||
/// (loaded back from the deploy DB) emits BOTH subtrees — the seeded raw tag as a Raw-realm Variable
|
||||
/// keyed by its RawPath, and the UnsTagReference as a UNS-realm Variable carrying that RawPath (the
|
||||
/// Organizes UNS→Raw target + fan-out source) and inheriting the raw tag's DataType. Drives the composer
|
||||
/// directly (not the artifact-decode round-trip, which WP3 migrates).</summary>
|
||||
[Fact]
|
||||
public async Task Composing_the_seeded_config_emits_the_raw_tag_and_uns_reference_variables()
|
||||
{
|
||||
await using var harness = await TwoNodeClusterHarness.StartAsync();
|
||||
await harness.SeedDefaultClusterAsync("c1");
|
||||
await SeedUnsHierarchyAsync(harness);
|
||||
|
||||
await using var scope = harness.NodeA.Services.CreateAsyncScope();
|
||||
var client = scope.ServiceProvider.GetRequiredService<IAdminOperationsClient>();
|
||||
await using var db = await CreateDbAsync(harness);
|
||||
var composition = AddressSpaceComposer.Compose(
|
||||
await db.UnsAreas.AsNoTracking().ToListAsync(Ct),
|
||||
await db.UnsLines.AsNoTracking().ToListAsync(Ct),
|
||||
await db.Equipment.AsNoTracking().ToListAsync(Ct),
|
||||
await db.DriverInstances.AsNoTracking().ToListAsync(Ct),
|
||||
await db.ScriptedAlarms.AsNoTracking().ToListAsync(Ct),
|
||||
unsTagReferences: await db.UnsTagReferences.AsNoTracking().ToListAsync(Ct),
|
||||
tags: await db.Tags.AsNoTracking().ToListAsync(Ct),
|
||||
rawFolders: await db.RawFolders.AsNoTracking().ToListAsync(Ct),
|
||||
devices: await db.Devices.AsNoTracking().ToListAsync(Ct),
|
||||
tagGroups: await db.TagGroups.AsNoTracking().ToListAsync(Ct));
|
||||
|
||||
var result = await client.StartDeploymentAsync(createdBy: "alice@test", Ct);
|
||||
result.Outcome.ShouldBe(StartDeploymentOutcome.Accepted, $"Deploy not accepted: {result.Message}");
|
||||
var deploymentId = result.DeploymentId!.Value.Value;
|
||||
// Raw subtree: the seeded raw tag is a Raw-realm Variable keyed by its RawPath (Plant/Modbus/dev-1/Speed).
|
||||
var rawTag = composition.RawTags.ShouldHaveSingleItem();
|
||||
rawTag.TagId.ShouldBe("tag-speed");
|
||||
rawTag.Realm.ShouldBe(AddressSpaceRealm.Raw);
|
||||
rawTag.NodeId.ShouldBe("Plant/Modbus/dev-1/Speed");
|
||||
rawTag.DataType.ShouldBe("Float");
|
||||
|
||||
var artifact = Array.Empty<byte>();
|
||||
await WaitForAsync(async () =>
|
||||
{
|
||||
await using var db = await CreateDbAsync(harness);
|
||||
var d = await db.Deployments.AsNoTracking()
|
||||
.FirstOrDefaultAsync(x => x.DeploymentId == deploymentId, Ct);
|
||||
if (d is { ArtifactBlob.Length: > 0 })
|
||||
{
|
||||
artifact = d.ArtifactBlob;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}, TimeSpan.FromSeconds(15));
|
||||
// UNS subtree: the UnsTagReference is a UNS-realm Variable carrying the backing RawPath + inherited type.
|
||||
var unsVar = composition.UnsReferenceVariables.ShouldHaveSingleItem();
|
||||
unsVar.Realm.ShouldBe(AddressSpaceRealm.Uns);
|
||||
unsVar.EquipmentId.ShouldBe(EquipmentId);
|
||||
unsVar.NodeId.ShouldBe("filling/line-1/station-1/Speed");
|
||||
unsVar.EffectiveName.ShouldBe("Speed");
|
||||
unsVar.BackingRawPath.ShouldBe("Plant/Modbus/dev-1/Speed"); // Organizes UNS→Raw + fan-out
|
||||
unsVar.DataType.ShouldBe("Float");
|
||||
|
||||
var composition = DeploymentArtifact.ParseComposition(artifact);
|
||||
|
||||
// Batch 4: the raw tag surfaces as an EquipmentTag with FullName pulled from TagConfig.
|
||||
var tag = composition.EquipmentTags.ShouldHaveSingleItem();
|
||||
tag.TagId.ShouldBe("tag-speed");
|
||||
tag.EquipmentId.ShouldBe(EquipmentId);
|
||||
tag.Name.ShouldBe("Speed");
|
||||
tag.DataType.ShouldBe("Float");
|
||||
tag.FullName.ShouldBe("40001");
|
||||
// The retired equipment-namespace tag path stays empty (values flow through raw + UNS now).
|
||||
composition.EquipmentTags.ShouldBeEmpty();
|
||||
}
|
||||
|
||||
private static async Task SeedUnsHierarchyAsync(TwoNodeClusterHarness harness)
|
||||
@@ -170,6 +174,11 @@ public sealed class EquipmentNamespaceMaterializationTests
|
||||
Name = "Speed", DataType = "Float", AccessLevel = TagAccessLevel.Read,
|
||||
TagConfig = "{\"FullName\":\"40001\"}",
|
||||
});
|
||||
// v3 Batch 4: the equipment projects the raw tag by reference (reference-only UNS).
|
||||
db.UnsTagReferences.Add(new UnsTagReference
|
||||
{
|
||||
UnsTagReferenceId = "ref-speed", EquipmentId = EquipmentId, TagId = "tag-speed",
|
||||
});
|
||||
|
||||
await db.SaveChangesAsync(Ct);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user