v3(b1-modbus): RawPath identity seam — RawTagEntry-driven Modbus driver

Wave-B EXEMPLAR. Retire the pre-declared/blob-parse tag model; the driver now
builds its RawPath -> definition table from the artifact's RawTagEntry set via a
pure mapper.

- Contracts: rename ModbusEquipmentTagParser -> ModbusTagDefinitionFactory;
  TryParse(reference) -> FromTagConfig(tagConfig, rawPath) (def.Name = rawPath,
  no leading-brace heuristic); add inverse ToTagConfig(def) serializer; keep all
  strict-enum reads + guards; also read stringByteOrder/deadband/coalesceProhibited
  so a RawTagEntry round-trips the full authored def. Inspect() unchanged.
- Options: Tags(IReadOnlyList<ModbusTagDefinition>) -> RawTags(IReadOnlyList<RawTagEntry>).
- Driver: _tagsByName -> _tagsByRawPath (Ordinal); resolver byRawPath-only; build
  the table from RawTags at Initialize threading entry.WriteIdempotent onto each def;
  Discover/Teardown updated.
- Factory: remove ModbusTagDto/BuildTag/ValidateStringLength + ConfigDto.Tags; bind
  RawTags from driver-config JSON.
- CLI ModbusCommandBase.BuildOptions: serialise typed defs -> RawTagEntry via ToTagConfig.
- Tests: migrate Tags= -> RawTags via ModbusRawTags.Entries helper; parser tests ->
  FromTagConfig(rawPath); factory String-length/enum tests re-seated on the mapper seam.
- Propagated rename to ControlPlane EquipmentTagConfigInspector (outside Modbus projects).

Modbus.Tests 315/315, Addressing.Tests 161/161, Cli.Tests 72/72 green.
Docker-gated Driver.Modbus.IntegrationTests left untouched (won't compile against
the new API; expected).
This commit is contained in:
Joseph Doherty
2026-07-15 19:50:10 -04:00
parent 906800abc0
commit aafb9d4929
27 changed files with 362 additions and 362 deletions
@@ -1,14 +1,15 @@
using Shouldly;
using Xunit;
using ZB.MOM.WW.OtOpcUa.Core.Abstractions;
namespace ZB.MOM.WW.OtOpcUa.Driver.Modbus.Tests;
/// <summary>
/// CONV-4 (Modbus leg) — Modbus keys per-host resilience per SLAVE UNIT
/// (<c>host:port/unitN</c>). An equipment tag must carry its own <c>unitId</c> so multi-unit
/// equipment tags key their own breaker; <see cref="ModbusDriver.ResolveHost"/> must resolve
/// the equipment ref through the resolver rather than only matching authored names. Scope:
/// <c>unitId</c> ONLY — the parser's other strictness gaps are R2-11's.
/// (<c>host:port/unitN</c>). An authored raw tag carries its own <c>unitId</c> in its TagConfig so
/// multi-unit tags key their own breaker; <see cref="ModbusDriver.ResolveHost"/> resolves a RawPath
/// through the driver's authored RawPath → definition table. Under v3 the reference is always a
/// RawPath — an unauthored RawPath falls back to the driver-level host.
/// </summary>
[Trait("Category", "Unit")]
public sealed class ModbusUnitIdResolveHostTests
@@ -21,43 +22,55 @@ public sealed class ModbusUnitIdResolveHostTests
public ValueTask DisposeAsync() => ValueTask.CompletedTask;
}
private static ModbusDriver NewDriver() => new(
new ModbusDriverOptions { Host = "10.0.0.1", Port = 502, UnitId = 1, Probe = new ModbusProbeOptions { Enabled = false } },
"modbus-1", _ => new NoopTransport());
private static async Task<ModbusDriver> NewDriverAsync(params RawTagEntry[] rawTags)
{
var drv = new ModbusDriver(
new ModbusDriverOptions
{
Host = "10.0.0.1", Port = 502, UnitId = 1, RawTags = rawTags,
Probe = new ModbusProbeOptions { Enabled = false },
},
"modbus-1", _ => new NoopTransport());
await drv.InitializeAsync("{}", CancellationToken.None);
return drv;
}
/// <summary>The parser reads an optional unitId into the transient definition.</summary>
/// <summary>The mapper reads an optional unitId into the definition.</summary>
[Fact]
public void Parser_reads_optional_unitId()
public void FromTagConfig_reads_optional_unitId()
{
var json = """{"region":"HoldingRegisters","address":0,"dataType":"Int16","unitId":7}""";
ModbusEquipmentTagParser.TryParse(json, out var def).ShouldBeTrue();
ModbusTagDefinitionFactory.FromTagConfig(json, "cell/modbus/dev1/U7", out var def).ShouldBeTrue();
def.Name.ShouldBe("cell/modbus/dev1/U7");
def.UnitId.ShouldBe((byte)7);
}
/// <summary>An absent unitId leaves the definition on the driver-level default (null override).</summary>
[Fact]
public void Parser_absent_unitId_is_null()
public void FromTagConfig_absent_unitId_is_null()
{
var json = """{"region":"HoldingRegisters","address":0,"dataType":"Int16"}""";
ModbusEquipmentTagParser.TryParse(json, out var def).ShouldBeTrue();
ModbusTagDefinitionFactory.FromTagConfig(json, "cell/modbus/dev1/U0", out var def).ShouldBeTrue();
def.UnitId.ShouldBeNull();
}
/// <summary>An equipment ref carrying a unitId keys its own per-unit host name.</summary>
/// <summary>An authored RawPath carrying a unitId keys its own per-unit host name.</summary>
[Fact]
public void EquipmentTag_WithUnitId_ResolvesPerUnitHostName()
public async Task RawPath_WithUnitId_ResolvesPerUnitHostName()
{
var drv = NewDriver();
const string rawPath = "cell/modbus/dev1/U7";
var json = """{"region":"HoldingRegisters","address":0,"dataType":"Int16","unitId":7}""";
drv.ResolveHost(json).ShouldBe("10.0.0.1:502/unit7");
var drv = await NewDriverAsync(new RawTagEntry(rawPath, json, false));
drv.ResolveHost(rawPath).ShouldBe("10.0.0.1:502/unit7");
}
/// <summary>An equipment ref without a unitId keys the driver-level unit host name.</summary>
/// <summary>An authored RawPath without a unitId keys the driver-level unit host name.</summary>
[Fact]
public void EquipmentTag_WithoutUnitId_KeysDriverDefaultUnit()
public async Task RawPath_WithoutUnitId_KeysDriverDefaultUnit()
{
var drv = NewDriver();
const string rawPath = "cell/modbus/dev1/U0";
var json = """{"region":"HoldingRegisters","address":0,"dataType":"Int16"}""";
drv.ResolveHost(json).ShouldBe("10.0.0.1:502/unit1");
var drv = await NewDriverAsync(new RawTagEntry(rawPath, json, false));
drv.ResolveHost(rawPath).ShouldBe("10.0.0.1:502/unit1");
}
}