v3 B1-WP6: migrate Core + Server test projects to greenfield schema
Fix TESTS only (production already green) so the four in-scope test projects compile + pass under the v3 dark address space: - Core.Abstractions.Tests: drop AllowedNamespaceKinds/NamespaceKindCompatibility from DriverTypeMetadata; rewrite EquipmentTagRefResolver tests to the single-func RawPath-lookup contract (no parseRef/transient cache). - Core.Tests: rewrite EquipmentNodeWalkerTests to EquipmentNamespaceContent(Areas, Lines,Equipment,VirtualTags?,ScriptedAlarms?) — folders + VirtualTags + ScriptedAlarms only; raw-tag variables dark (skipped Batch-4 placeholder). Drop retired Equipment.DriverInstanceId. - Runtime.Tests: rewrite golden corpus + TagConfigCorpusParityTests to the v3 RawPath/RawTagEntry round-trip (byte + TagConfigIntent parity; EquipmentTags dark). Salvage VirtualTag + ScriptedAlarm artifact parity to the new Compose signature. Retire the equipment-tag-materialization parity files (Array/Historize/Alias) and the equipment-device-binding DeviceHost parity to documented skipped placeholders. Skip 34 dark equipment-tag routing/value/alarm/write/discovery actor tests with a shared DarkAddressSpaceReasons constant. Re-key cluster-scoped tests to v3 UNS line->area attribution. - ControlPlane.Tests: ConfigComposer round-trips re-keyed to RawFolder/Device (no Namespaces); tag-config gate resolves driver via Device; deploy-gate collision test re-keyed to UnsEffectiveNameCollision; drop retired BadCrossClusterNamespaceBinding case.
This commit is contained in:
+9
-13
@@ -23,29 +23,25 @@ namespace ZB.MOM.WW.OtOpcUa.ControlPlane.Tests;
|
||||
/// </summary>
|
||||
public sealed class AdminOperationsActorTagConfigGateTests : ControlPlaneActorTestBase
|
||||
{
|
||||
// v3: a raw Tag binds to a Device (Tag.DeviceId), and its driver type is resolved
|
||||
// Tag → Device → DriverInstance.DriverType. The tag-config gate inspects every raw tag against that
|
||||
// resolved driver type. All entity Names must be legal RawPath segments (DraftValidator RawNameInvalid).
|
||||
private static void Seed(IDbContextFactory<OtOpcUaConfigDbContext> dbFactory, string driverType, string tagConfig,
|
||||
string tagName = "flow")
|
||||
{
|
||||
var uuid = Guid.NewGuid();
|
||||
var equipmentId = DraftValidator.DeriveEquipmentId(uuid);
|
||||
using var db = dbFactory.CreateDbContext();
|
||||
db.Namespaces.Add(new Namespace
|
||||
{
|
||||
NamespaceId = "ns-1", ClusterId = "", Kind = NamespaceKind.Equipment, NamespaceUri = "urn:eq",
|
||||
});
|
||||
db.DriverInstances.Add(new DriverInstance
|
||||
{
|
||||
DriverInstanceId = "d-1", ClusterId = "", NamespaceId = "ns-1",
|
||||
DriverInstanceId = "d-1", ClusterId = "",
|
||||
Name = "drv", DriverType = driverType, DriverConfig = "{}",
|
||||
});
|
||||
db.Equipment.Add(new Equipment
|
||||
db.Devices.Add(new Device
|
||||
{
|
||||
EquipmentUuid = uuid, EquipmentId = equipmentId, Name = "pump-01",
|
||||
DriverInstanceId = "d-1", UnsLineId = "line-a", MachineCode = "PUMP01",
|
||||
DeviceId = "dev-1", DriverInstanceId = "d-1", Name = "dev", DeviceConfig = "{}",
|
||||
});
|
||||
db.Tags.Add(new Tag
|
||||
{
|
||||
TagId = "tag-1", DriverInstanceId = "d-1", EquipmentId = equipmentId,
|
||||
TagId = "tag-1", DeviceId = "dev-1",
|
||||
Name = tagName, DataType = "Int16", AccessLevel = TagAccessLevel.Read, TagConfig = tagConfig,
|
||||
});
|
||||
db.SaveChanges();
|
||||
@@ -116,8 +112,8 @@ public sealed class AdminOperationsActorTagConfigGateTests : ControlPlaneActorTe
|
||||
public void Unmapped_galaxy_tag_is_skipped_even_in_error_mode()
|
||||
{
|
||||
var dbFactory = NewInMemoryDbFactory();
|
||||
// Galaxy tag carrying a FullName (passes the DraftValidator Galaxy rule); the inspector has no
|
||||
// Galaxy mapping, so it is skipped regardless of mode.
|
||||
// A Galaxy raw tag (v3: an ordinary Device-bound tag); the inspector has no Galaxy mapping, so it
|
||||
// is skipped regardless of mode — even with a nonsense dataType in its TagConfig.
|
||||
Seed(dbFactory, "GalaxyMxGateway", "{\"FullName\":\"Obj.Attr\",\"dataType\":\"nonsense\"}");
|
||||
var coordinator = CreateTestProbe("coord");
|
||||
var actor = Sys.ActorOf(AdminOperationsActor.Props(
|
||||
|
||||
@@ -175,13 +175,14 @@ public sealed class AdminOperationsActorTests : ControlPlaneActorTestBase
|
||||
db.ConfigEdits.Single().EntityType.ShouldBe("Deployment");
|
||||
}
|
||||
|
||||
/// <summary>Verifies the full DraftValidator gate (reject on ANY error): a Tag↔VirtualTag
|
||||
/// NodeId collision in the live config rejects the deploy (422-mapped
|
||||
/// <see cref="StartDeploymentOutcome.Rejected"/>) before any coordinator dispatch — and inserts
|
||||
/// no Deployment row. The colliding equipment uses a canonical EquipmentId so the rejection is
|
||||
/// <summary>Verifies the full DraftValidator gate (reject on ANY error): a v3 UNS effective-name
|
||||
/// collision — a UnsTagReference (surfacing a raw Tag under an equipment) and a VirtualTag sharing the
|
||||
/// same effective leaf name in that equipment's UNS NodeId space — rejects the deploy (422-mapped
|
||||
/// <see cref="StartDeploymentOutcome.Rejected"/>) before any coordinator dispatch, inserting no
|
||||
/// Deployment row. The colliding equipment uses a canonical EquipmentId so the rejection is
|
||||
/// attributable to the collision rule, not to EquipmentIdNotDerived.</summary>
|
||||
[Fact]
|
||||
public void StartDeployment_rejects_on_Tag_VirtualTag_NodeId_collision()
|
||||
public void StartDeployment_rejects_on_UNS_effective_name_collision()
|
||||
{
|
||||
var uuid = Guid.NewGuid();
|
||||
var equipmentId = Configuration.Validation.DraftValidator.DeriveEquipmentId(uuid);
|
||||
@@ -194,20 +195,32 @@ public sealed class AdminOperationsActorTests : ControlPlaneActorTestBase
|
||||
EquipmentUuid = uuid,
|
||||
EquipmentId = equipmentId,
|
||||
Name = "eq",
|
||||
DriverInstanceId = "d",
|
||||
UnsLineId = "line-a",
|
||||
MachineCode = "m",
|
||||
});
|
||||
// v3: a raw Tag binds to a Device; it reaches the equipment's UNS space via a UnsTagReference.
|
||||
db.DriverInstances.Add(new Configuration.Entities.DriverInstance
|
||||
{
|
||||
DriverInstanceId = "d", ClusterId = "", Name = "drv", DriverType = "Modbus", DriverConfig = "{}",
|
||||
});
|
||||
db.Devices.Add(new Configuration.Entities.Device
|
||||
{
|
||||
DeviceId = "dev", DriverInstanceId = "d", Name = "dev", DeviceConfig = "{}",
|
||||
});
|
||||
db.Tags.Add(new Configuration.Entities.Tag
|
||||
{
|
||||
TagId = "tag-speed",
|
||||
DriverInstanceId = "d",
|
||||
EquipmentId = equipmentId,
|
||||
DeviceId = "dev",
|
||||
Name = "speed",
|
||||
DataType = "Float",
|
||||
AccessLevel = TagAccessLevel.Read,
|
||||
TagConfig = "{}",
|
||||
});
|
||||
db.UnsTagReferences.Add(new Configuration.Entities.UnsTagReference
|
||||
{
|
||||
UnsTagReferenceId = "ref-speed", EquipmentId = equipmentId, TagId = "tag-speed",
|
||||
});
|
||||
// A VirtualTag whose Name collides with the reference's effective name "speed".
|
||||
db.VirtualTags.Add(new Configuration.Entities.VirtualTag
|
||||
{
|
||||
VirtualTagId = "vtag-speed",
|
||||
@@ -228,8 +241,8 @@ public sealed class AdminOperationsActorTests : ControlPlaneActorTestBase
|
||||
var reply = ExpectMsg<StartDeploymentResult>(TimeSpan.FromSeconds(3));
|
||||
reply.Outcome.ShouldBe(StartDeploymentOutcome.Rejected);
|
||||
reply.Message.ShouldNotBeNull();
|
||||
reply.Message.ShouldContain("EquipmentSignalNameCollision"); // the rule's error code
|
||||
reply.Message.ShouldContain("collide"); // the rule's message text
|
||||
reply.Message.ShouldContain("UnsEffectiveNameCollision"); // the v3 rule's error code
|
||||
reply.Message.ShouldContain("collide"); // the rule's message text
|
||||
|
||||
using var verify = dbFactory.CreateDbContext();
|
||||
verify.Deployments.Count().ShouldBe(0);
|
||||
@@ -251,7 +264,6 @@ public sealed class AdminOperationsActorTests : ControlPlaneActorTestBase
|
||||
EquipmentUuid = Guid.NewGuid(),
|
||||
EquipmentId = "EQ-operator-typed", // NOT derived from the UUID
|
||||
Name = "rinser-01",
|
||||
DriverInstanceId = "d",
|
||||
UnsLineId = "line-a",
|
||||
MachineCode = "m",
|
||||
});
|
||||
@@ -273,53 +285,11 @@ public sealed class AdminOperationsActorTests : ControlPlaneActorTestBase
|
||||
verify.Deployments.Count().ShouldBe(0);
|
||||
}
|
||||
|
||||
/// <summary>Verifies that a DriverInstance whose NamespaceId lives in a different cluster
|
||||
/// triggers <c>BadCrossClusterNamespaceBinding</c> and routes to the Rejected branch through
|
||||
/// the actor — no coordinator dispatch, no Deployment row.
|
||||
/// Seeded: Namespace in cluster "MAIN" + DriverInstance in cluster "SITE-A" referencing that
|
||||
/// namespace. NamespaceKind.Equipment + DriverType "Modbus" satisfies the compat rule so
|
||||
/// only the cross-cluster rule fires.</summary>
|
||||
[Fact]
|
||||
public void StartDeployment_rejects_on_cross_cluster_namespace_binding()
|
||||
{
|
||||
const string nsId = "ns-main-equipment";
|
||||
|
||||
var dbFactory = NewInMemoryDbFactory();
|
||||
using (var db = dbFactory.CreateDbContext())
|
||||
{
|
||||
db.Namespaces.Add(new Configuration.Entities.Namespace
|
||||
{
|
||||
NamespaceId = nsId,
|
||||
ClusterId = "MAIN",
|
||||
Kind = Configuration.Enums.NamespaceKind.Equipment,
|
||||
NamespaceUri = "urn:zb:main:equipment",
|
||||
});
|
||||
db.DriverInstances.Add(new Configuration.Entities.DriverInstance
|
||||
{
|
||||
DriverInstanceId = "drv-site-a-01",
|
||||
ClusterId = "SITE-A",
|
||||
NamespaceId = nsId, // cross-cluster: drv is SITE-A, ns is MAIN
|
||||
Name = "site-a-modbus",
|
||||
DriverType = "Modbus", // compatible with Equipment ns — no compat error
|
||||
DriverConfig = "{}",
|
||||
});
|
||||
db.SaveChanges();
|
||||
}
|
||||
|
||||
var coordinator = CreateTestProbe("coord");
|
||||
var actor = Sys.ActorOf(AdminOperationsActor.Props(dbFactory, coordinator.Ref, Enumerable.Empty<IDriverProbe>()));
|
||||
|
||||
actor.Tell(new StartDeployment("joe", CorrelationId.NewId()));
|
||||
|
||||
coordinator.ExpectNoMsg(TimeSpan.FromMilliseconds(500));
|
||||
var reply = ExpectMsg<StartDeploymentResult>(TimeSpan.FromSeconds(3));
|
||||
reply.Outcome.ShouldBe(StartDeploymentOutcome.Rejected);
|
||||
reply.Message.ShouldNotBeNull();
|
||||
reply.Message.ShouldContain("BadCrossClusterNamespaceBinding");
|
||||
|
||||
using var verify = dbFactory.CreateDbContext();
|
||||
verify.Deployments.Count().ShouldBe(0);
|
||||
}
|
||||
// RETIRED (v3): the Namespace entity and its cluster-binding rule (BadCrossClusterNamespaceBinding)
|
||||
// are deleted — the two OPC UA namespaces (Raw/UNS) are implicit and driver instances no longer bind a
|
||||
// Namespace. There is no v3 analog for a cross-cluster namespace binding, so this deploy-gate case is
|
||||
// dropped (per the v3 schema migration). Cluster scoping is now exercised via the UNS line→area→cluster
|
||||
// attribution covered in DeploymentArtifactTests.
|
||||
|
||||
/// <summary>Verifies the warn-only compile-cost advisory: seeding N distinct non-passthrough
|
||||
/// (genuinely-compiled) Script rows yields an <see cref="StartDeploymentOutcome.Accepted"/>
|
||||
|
||||
@@ -87,29 +87,27 @@ public sealed class ConfigComposerTests : ControlPlaneActorTestBase
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that <see cref="ConfigComposer.SnapshotAndFlattenAsync"/> serialises a
|
||||
/// <see cref="Device"/>'s <c>HostAddress</c> into the artifact blob and that
|
||||
/// <see cref="DeploymentArtifact.ParseComposition(ReadOnlySpan{byte})"/> decodes it back
|
||||
/// as the equipment's <see cref="ZB.MOM.WW.OtOpcUa.OpcUaServer.EquipmentNode.DeviceHost"/>
|
||||
/// (follow-up E). Guards the real serialize→decode seam: if ConfigComposer's Device
|
||||
/// serialisation ever drifted, DeviceHost would silently become null in production
|
||||
/// (feature E degrades to a warn-skip) while hand-rolled artifact tests stayed green.
|
||||
/// v3: verifies that <see cref="ConfigComposer.SnapshotAndFlattenAsync"/> serialises a
|
||||
/// <see cref="Device"/>'s endpoint into the artifact blob and that
|
||||
/// <see cref="DeploymentArtifact.ParseDriverInstances(ReadOnlySpan{byte})"/> folds the sole
|
||||
/// device's <c>DeviceConfig</c> up into the driver's merged <c>DriverConfig</c> (single-endpoint
|
||||
/// driver). Guards the real serialize→decode seam: if ConfigComposer's Device serialisation ever
|
||||
/// drifted, the endpoint would silently vanish from the driver config in production (the driver
|
||||
/// wouldn't bind) while hand-rolled artifact tests stayed green. (Pre-v3 this rode
|
||||
/// <c>EquipmentNode.DeviceHost</c>; v3 retired that binding — equipment references raw tags via
|
||||
/// UnsTagReference, and the endpoint reaches the driver via the RawPath device merge.)
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task DeviceHost_survives_ConfigComposer_to_ParseComposition_round_trip()
|
||||
public async Task Device_endpoint_survives_ConfigComposer_to_ParseDriverInstances_round_trip()
|
||||
{
|
||||
var f = NewInMemoryDbFactory();
|
||||
await using (var db = f.CreateDbContext())
|
||||
{
|
||||
db.ServerClusters.Add(NewCluster("c1"));
|
||||
db.Namespaces.Add(new Namespace
|
||||
{
|
||||
NamespaceId = "ns-eq", ClusterId = "c1",
|
||||
Kind = NamespaceKind.Equipment, NamespaceUri = "urn:eq",
|
||||
});
|
||||
db.RawFolders.Add(new RawFolder { RawFolderId = "f1", ClusterId = "c1", Name = "Plant" });
|
||||
db.DriverInstances.Add(new DriverInstance
|
||||
{
|
||||
DriverInstanceId = "drv-1", ClusterId = "c1", NamespaceId = "ns-eq",
|
||||
DriverInstanceId = "drv-1", ClusterId = "c1", RawFolderId = "f1",
|
||||
Name = "Focas", DriverType = "Focas", DriverConfig = "{}",
|
||||
});
|
||||
db.Devices.Add(new Device
|
||||
@@ -117,25 +115,23 @@ public sealed class ConfigComposerTests : ControlPlaneActorTestBase
|
||||
DeviceId = "dev-1", DriverInstanceId = "drv-1",
|
||||
Name = "dev-1", DeviceConfig = "{\"HostAddress\":\"10.9.9.9:8193\"}",
|
||||
});
|
||||
db.UnsAreas.Add(new UnsArea { UnsAreaId = "area-1", ClusterId = "c1", Name = "area-1" });
|
||||
db.UnsLines.Add(new UnsLine { UnsLineId = "line-1", UnsAreaId = "area-1", Name = "line-1" });
|
||||
db.Equipment.Add(new Equipment
|
||||
{
|
||||
EquipmentId = "eq-1", DriverInstanceId = "drv-1", DeviceId = "dev-1",
|
||||
UnsLineId = "line-1", Name = "machine-1", MachineCode = "MACHINE_001",
|
||||
});
|
||||
await db.SaveChangesAsync();
|
||||
}
|
||||
|
||||
await using var readDb = f.CreateDbContext();
|
||||
var artifact = await ConfigComposer.SnapshotAndFlattenAsync(readDb);
|
||||
var composition = DeploymentArtifact.ParseComposition(artifact.Blob);
|
||||
var specs = DeploymentArtifact.ParseDriverInstances(artifact.Blob);
|
||||
|
||||
var node = composition.EquipmentNodes.ShouldHaveSingleItem();
|
||||
node.EquipmentId.ShouldBe("eq-1");
|
||||
node.DriverInstanceId.ShouldBe("drv-1");
|
||||
node.DeviceId.ShouldBe("dev-1");
|
||||
node.DeviceHost.ShouldBe("10.9.9.9:8193");
|
||||
var spec = specs.ShouldHaveSingleItem();
|
||||
spec.DriverInstanceId.ShouldBe("drv-1");
|
||||
|
||||
// The sole device's DeviceConfig endpoint is folded up to the top level of the merged DriverConfig.
|
||||
using var doc = System.Text.Json.JsonDocument.Parse(spec.DriverConfig);
|
||||
doc.RootElement.GetProperty("HostAddress").GetString().ShouldBe("10.9.9.9:8193");
|
||||
|
||||
// And the device is still discoverable by its routing-key name in the reconstructed Devices array.
|
||||
var devices = doc.RootElement.GetProperty("Devices").EnumerateArray().ToList();
|
||||
devices.ShouldHaveSingleItem().GetProperty("DeviceName").GetString().ShouldBe("dev-1");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -160,21 +156,16 @@ public sealed class ConfigComposerTests : ControlPlaneActorTestBase
|
||||
await using (var db = f.CreateDbContext())
|
||||
{
|
||||
db.ServerClusters.Add(NewCluster("c1"));
|
||||
db.Namespaces.Add(new Namespace
|
||||
{
|
||||
NamespaceId = "ns-eq", ClusterId = "c1",
|
||||
Kind = NamespaceKind.Equipment, NamespaceUri = "urn:eq",
|
||||
});
|
||||
db.DriverInstances.Add(new DriverInstance
|
||||
{
|
||||
DriverInstanceId = "drv-1", ClusterId = "c1", NamespaceId = "ns-eq",
|
||||
DriverInstanceId = "drv-1", ClusterId = "c1",
|
||||
Name = "Modbus", DriverType = "Modbus", DriverConfig = "{}",
|
||||
ResilienceConfig = resilienceJson,
|
||||
});
|
||||
// A second instance with no override proves the null case rides the same real composer path.
|
||||
db.DriverInstances.Add(new DriverInstance
|
||||
{
|
||||
DriverInstanceId = "drv-2", ClusterId = "c1", NamespaceId = "ns-eq",
|
||||
DriverInstanceId = "drv-2", ClusterId = "c1",
|
||||
Name = "Modbus2", DriverType = "Modbus", DriverConfig = "{}",
|
||||
});
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
Reference in New Issue
Block a user