Catch-all commit for pending work on the task-galaxy-e2e branch that
wasn't part of the FOCAS migration. Grouping by topic so future per-topic
commits can be cherry-picked if needed.
TwinCAT
- src/.../Driver.TwinCAT/AdsTwinCATClient.cs + TwinCATDriverFactoryExtensions.cs:
factory-registration extensions + ADS client refinements.
- src/.../Driver.TwinCAT.Cli/Commands/BrowseCommand.cs: new browse command
for the TwinCAT test-client CLI.
- tests/.../Driver.TwinCAT.IntegrationTests/TwinCAT3SmokeTests.cs + TwinCatProject/:
fixture scaffold with a minimal POU + README pointing at the TCBSD/ESXi
VM for e2e.
- docs/Driver.TwinCAT.Cli.md + docs/drivers/TwinCAT-Test-Fixture.md:
documentation for the above.
- docs/v3/twincat-backlog.md: forward-looking backlog seed.
Admin UI + fleet status
- src/.../Admin/Components/Pages/Clusters/DriversTab.razor + Hosts.razor:
UI refresh for fleet-status rendering.
- src/.../Admin/Hubs/FleetStatusHub.cs + FleetStatusPoller.cs +
Admin/Program.cs: SignalR hub + poller plumbing for live fleet data.
- tests/.../Admin.Tests/FleetStatusPollerTests.cs: poller coverage.
Server + redundancy runtime (Phase 6.3 follow-ups)
- src/.../Server/Hosting/RedundancyPublisherHostedService.cs: HostedService
that owns the RedundancyStatePublisher lifecycle + wires peer reachability.
- src/.../Server/Redundancy/ServerRedundancyNodeWriter.cs: OPC UA
variable-node writer binding ServiceLevel + ServerUriArray to the
publisher's events.
- src/.../Server/Program.cs + Server.csproj: hosted-service registration.
- tests/.../Server.Tests/ServerRedundancyNodeWriterTests.cs +
Server.Tests.csproj: coverage for the above.
Configuration
- src/.../Configuration/Validation/DraftValidator.cs +
tests/.../Configuration.Tests/DraftValidatorTests.cs: draft-validation
refinements.
E2E scripts (shared infrastructure)
- scripts/e2e/README.md + _common.ps1 + test-all.ps1: shared helpers + the
all-drivers test-all runner.
- scripts/e2e/test-opcuaclient.ps1: OPC UA Client e2e runner.
Docs
- docs/v2/implementation/phase-6-{1,2,3,4}*.md + exit-gate-phase-{3,7}.md:
phase-gate + implementation doc updates.
- docs/v2/plan.md: top-level plan refresh.
- docs/v2/redundancy-interop-playbook.md: client interop playbook for the
Phase 6.3 redundancy-runtime work.
Two orphan FOCAS docs remain on disk but deliberately unstaged —
docs/v2/focas-deployment.md and docs/v2/implementation/focas-simulator-plan.md
describe the now-retired Tier-C topology and should either be rewritten
or deleted in a follow-up.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
236 lines
9.7 KiB
C#
236 lines
9.7 KiB
C#
using Shouldly;
|
|
using Xunit;
|
|
using ZB.MOM.WW.OtOpcUa.Configuration.Entities;
|
|
using ZB.MOM.WW.OtOpcUa.Configuration.Enums;
|
|
using ZB.MOM.WW.OtOpcUa.Configuration.Validation;
|
|
|
|
namespace ZB.MOM.WW.OtOpcUa.Configuration.Tests;
|
|
|
|
[Trait("Category", "Unit")]
|
|
public sealed class DraftValidatorTests
|
|
{
|
|
[Theory]
|
|
[InlineData("valid-name", true)]
|
|
[InlineData("line-01", true)]
|
|
[InlineData("_default", true)]
|
|
[InlineData("UPPER", false)]
|
|
[InlineData("with space", false)]
|
|
[InlineData("", false)]
|
|
public void UnsSegment_rule_accepts_lowercase_or_default_only(string name, bool shouldPass)
|
|
{
|
|
var uuid = Guid.NewGuid();
|
|
var draft = new DraftSnapshot
|
|
{
|
|
GenerationId = 1, ClusterId = "c",
|
|
Equipment =
|
|
[
|
|
new Equipment
|
|
{
|
|
EquipmentUuid = uuid,
|
|
EquipmentId = DraftValidator.DeriveEquipmentId(uuid),
|
|
Name = name,
|
|
DriverInstanceId = "d",
|
|
UnsLineId = "line-a",
|
|
MachineCode = "m",
|
|
},
|
|
],
|
|
};
|
|
|
|
var errors = DraftValidator.Validate(draft);
|
|
var hasUnsError = errors.Any(e => e.Code == "UnsSegmentInvalid");
|
|
hasUnsError.ShouldBe(!shouldPass);
|
|
}
|
|
|
|
[Fact]
|
|
public void Cross_cluster_namespace_binding_is_rejected()
|
|
{
|
|
var draft = new DraftSnapshot
|
|
{
|
|
GenerationId = 1, ClusterId = "c-A",
|
|
Namespaces = [new Namespace { NamespaceId = "ns-1", ClusterId = "c-B", NamespaceUri = "urn:x", Kind = NamespaceKind.Equipment }],
|
|
DriverInstances = [new DriverInstance { DriverInstanceId = "d-1", ClusterId = "c-A", NamespaceId = "ns-1", Name = "drv", DriverType = "ModbusTcp", DriverConfig = "{}" }],
|
|
};
|
|
|
|
var errors = DraftValidator.Validate(draft);
|
|
errors.ShouldContain(e => e.Code == "BadCrossClusterNamespaceBinding");
|
|
}
|
|
|
|
[Fact]
|
|
public void Same_cluster_namespace_binding_is_accepted()
|
|
{
|
|
var draft = new DraftSnapshot
|
|
{
|
|
GenerationId = 1, ClusterId = "c-A",
|
|
Namespaces = [new Namespace { NamespaceId = "ns-1", ClusterId = "c-A", NamespaceUri = "urn:x", Kind = NamespaceKind.Equipment }],
|
|
DriverInstances = [new DriverInstance { DriverInstanceId = "d-1", ClusterId = "c-A", NamespaceId = "ns-1", Name = "drv", DriverType = "ModbusTcp", DriverConfig = "{}" }],
|
|
};
|
|
|
|
DraftValidator.Validate(draft).ShouldNotContain(e => e.Code == "BadCrossClusterNamespaceBinding");
|
|
}
|
|
|
|
[Fact]
|
|
public void EquipmentUuid_change_across_generations_is_rejected()
|
|
{
|
|
var oldUuid = Guid.Parse("11111111-1111-1111-1111-111111111111");
|
|
var newUuid = Guid.Parse("22222222-2222-2222-2222-222222222222");
|
|
var eid = DraftValidator.DeriveEquipmentId(oldUuid);
|
|
|
|
var draft = new DraftSnapshot
|
|
{
|
|
GenerationId = 2, ClusterId = "c",
|
|
Equipment = [new Equipment { EquipmentUuid = newUuid, EquipmentId = eid, Name = "eq", DriverInstanceId = "d", UnsLineId = "line-a", MachineCode = "m" }],
|
|
PriorEquipment = [new Equipment { EquipmentUuid = oldUuid, EquipmentId = eid, Name = "eq", DriverInstanceId = "d", UnsLineId = "line-a", MachineCode = "m" }],
|
|
};
|
|
|
|
DraftValidator.Validate(draft).ShouldContain(e => e.Code == "EquipmentUuidImmutable");
|
|
}
|
|
|
|
[Fact]
|
|
public void ZTag_reserved_by_different_uuid_is_rejected()
|
|
{
|
|
var uuid = Guid.NewGuid();
|
|
var otherUuid = Guid.NewGuid();
|
|
|
|
var draft = new DraftSnapshot
|
|
{
|
|
GenerationId = 1, ClusterId = "c",
|
|
Equipment = [new Equipment { EquipmentUuid = uuid, EquipmentId = DraftValidator.DeriveEquipmentId(uuid), Name = "eq", DriverInstanceId = "d", UnsLineId = "line-a", MachineCode = "m", ZTag = "ZT-001" }],
|
|
ActiveReservations = [new ExternalIdReservation { Kind = ReservationKind.ZTag, Value = "ZT-001", EquipmentUuid = otherUuid, ClusterId = "c", FirstPublishedBy = "t" }],
|
|
};
|
|
|
|
DraftValidator.Validate(draft).ShouldContain(e => e.Code == "BadDuplicateExternalIdentifier");
|
|
}
|
|
|
|
[Fact]
|
|
public void EquipmentId_that_does_not_match_derivation_is_rejected()
|
|
{
|
|
var uuid = Guid.NewGuid();
|
|
var draft = new DraftSnapshot
|
|
{
|
|
GenerationId = 1, ClusterId = "c",
|
|
Equipment = [new Equipment { EquipmentUuid = uuid, EquipmentId = "EQ-operator-typed", Name = "eq", DriverInstanceId = "d", UnsLineId = "line-a", MachineCode = "m" }],
|
|
};
|
|
|
|
DraftValidator.Validate(draft).ShouldContain(e => e.Code == "EquipmentIdNotDerived");
|
|
}
|
|
|
|
[Fact]
|
|
public void Galaxy_driver_in_Equipment_namespace_is_rejected()
|
|
{
|
|
var draft = new DraftSnapshot
|
|
{
|
|
GenerationId = 1, ClusterId = "c",
|
|
Namespaces = [new Namespace { NamespaceId = "ns-1", ClusterId = "c", NamespaceUri = "urn:x", Kind = NamespaceKind.Equipment }],
|
|
DriverInstances = [new DriverInstance { DriverInstanceId = "d-1", ClusterId = "c", NamespaceId = "ns-1", Name = "drv", DriverType = "Galaxy", DriverConfig = "{}" }],
|
|
};
|
|
|
|
DraftValidator.Validate(draft).ShouldContain(e => e.Code == "DriverNamespaceKindMismatch");
|
|
}
|
|
|
|
[Fact]
|
|
public void Draft_with_three_violations_surfaces_all_three()
|
|
{
|
|
var uuid = Guid.NewGuid();
|
|
var draft = new DraftSnapshot
|
|
{
|
|
GenerationId = 1, ClusterId = "c-A",
|
|
Namespaces = [new Namespace { NamespaceId = "ns-1", ClusterId = "c-B", NamespaceUri = "urn:x", Kind = NamespaceKind.Equipment }],
|
|
DriverInstances = [new DriverInstance { DriverInstanceId = "d-1", ClusterId = "c-A", NamespaceId = "ns-1", Name = "drv", DriverType = "Galaxy", DriverConfig = "{}" }],
|
|
Equipment = [new Equipment { EquipmentUuid = uuid, EquipmentId = "EQ-wrong", Name = "BAD NAME", DriverInstanceId = "d-1", UnsLineId = "line-a", MachineCode = "m" }],
|
|
};
|
|
|
|
var errors = DraftValidator.Validate(draft);
|
|
errors.ShouldContain(e => e.Code == "BadCrossClusterNamespaceBinding");
|
|
errors.ShouldContain(e => e.Code == "DriverNamespaceKindMismatch");
|
|
errors.ShouldContain(e => e.Code == "EquipmentIdNotDerived");
|
|
errors.ShouldContain(e => e.Code == "UnsSegmentInvalid");
|
|
}
|
|
|
|
// ------------------------------------------------------------------------------------
|
|
// Phase 6.3 task #148 part 2 — ValidateClusterTopology
|
|
// ------------------------------------------------------------------------------------
|
|
|
|
[Theory]
|
|
[InlineData(1, RedundancyMode.None, 1, 0)] // single-node standalone — ok
|
|
[InlineData(2, RedundancyMode.Warm, 2, 0)] // 2-node warm — ok
|
|
[InlineData(2, RedundancyMode.Hot, 2, 0)] // 2-node hot — ok
|
|
[InlineData(1, RedundancyMode.Warm, 1, 1)] // declared mismatch — should flag
|
|
[InlineData(2, RedundancyMode.None, 2, 1)] // None with 2 nodes — should flag
|
|
public void ValidateClusterTopology_checks_declared_pair(
|
|
byte nodeCount, RedundancyMode mode, int enabledNodes, int expectedDeclaredErrors)
|
|
{
|
|
var cluster = BuildCluster(nodeCount: nodeCount, mode: mode);
|
|
var nodes = Enumerable.Range(0, enabledNodes)
|
|
.Select(i => BuildNode($"n-{i}", enabled: true, role: i == 0 ? RedundancyRole.Primary : RedundancyRole.Secondary))
|
|
.ToList();
|
|
|
|
var errors = DraftValidator.ValidateClusterTopology(cluster, nodes);
|
|
errors.Count(e => e.Code == "ClusterRedundancyModeInvalid").ShouldBe(expectedDeclaredErrors);
|
|
}
|
|
|
|
[Fact]
|
|
public void ValidateClusterTopology_flags_disabled_node_mismatch()
|
|
{
|
|
// Declared 2 + Hot, but one node disabled — runtime would boot InvalidTopology.
|
|
var cluster = BuildCluster(nodeCount: 2, mode: RedundancyMode.Hot);
|
|
var nodes = new[]
|
|
{
|
|
BuildNode("primary", enabled: true, role: RedundancyRole.Primary),
|
|
BuildNode("backup", enabled: false, role: RedundancyRole.Secondary),
|
|
};
|
|
|
|
var errors = DraftValidator.ValidateClusterTopology(cluster, nodes);
|
|
errors.ShouldContain(e => e.Code == "ClusterEnabledNodeCountMismatch");
|
|
}
|
|
|
|
[Fact]
|
|
public void ValidateClusterTopology_flags_multiple_Primary()
|
|
{
|
|
var cluster = BuildCluster(nodeCount: 2, mode: RedundancyMode.Hot);
|
|
var nodes = new[]
|
|
{
|
|
BuildNode("a", enabled: true, role: RedundancyRole.Primary),
|
|
BuildNode("b", enabled: true, role: RedundancyRole.Primary),
|
|
};
|
|
|
|
var errors = DraftValidator.ValidateClusterTopology(cluster, nodes);
|
|
errors.ShouldContain(e => e.Code == "ClusterMultiplePrimary");
|
|
}
|
|
|
|
[Fact]
|
|
public void ValidateClusterTopology_returns_no_errors_on_valid_standalone()
|
|
{
|
|
var cluster = BuildCluster(nodeCount: 1, mode: RedundancyMode.None);
|
|
var nodes = new[] { BuildNode("only", enabled: true, role: RedundancyRole.Primary) };
|
|
|
|
var errors = DraftValidator.ValidateClusterTopology(cluster, nodes);
|
|
errors.ShouldBeEmpty();
|
|
}
|
|
|
|
private static ServerCluster BuildCluster(byte nodeCount, RedundancyMode mode) => new()
|
|
{
|
|
ClusterId = "c-test",
|
|
Name = "Test",
|
|
Enterprise = "zb",
|
|
Site = "dev",
|
|
NodeCount = nodeCount,
|
|
RedundancyMode = mode,
|
|
Enabled = true,
|
|
CreatedBy = "t",
|
|
};
|
|
|
|
private static ClusterNode BuildNode(string id, bool enabled, RedundancyRole role) => new()
|
|
{
|
|
NodeId = id,
|
|
ClusterId = "c-test",
|
|
RedundancyRole = role,
|
|
Host = "localhost",
|
|
OpcUaPort = 4840,
|
|
DashboardPort = 5001,
|
|
ApplicationUri = $"urn:{id}",
|
|
ServiceLevelBase = 200,
|
|
Enabled = enabled,
|
|
CreatedBy = "t",
|
|
};
|
|
}
|