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:
+25
-54
@@ -7,9 +7,10 @@ namespace ZB.MOM.WW.OtOpcUa.Driver.Modbus.Tests;
|
||||
/// Regression coverage for Driver.Modbus-009: two configuration edge cases that previously
|
||||
/// silently produced wrong wire behaviour.
|
||||
/// (1) <c>StringLength = 0</c> for a <c>String</c>-typed tag — used to flow into an FC03
|
||||
/// with quantity 0, a spec-illegal request the PLC rejects with exception 03. Now bind-time
|
||||
/// validation in <c>ModbusDriverFactoryExtensions</c> rejects the misconfiguration with a
|
||||
/// clear diagnostic.
|
||||
/// with quantity 0, a spec-illegal request the PLC rejects with exception 03. In v3 the guard
|
||||
/// moved to the pure mapper (<see cref="ModbusTagDefinitionFactory.FromTagConfig"/>): a String
|
||||
/// tag with <c>stringLength < 1</c> fails to map (⇒ the driver skips it / surfaces
|
||||
/// <c>BadNodeIdUnknown</c>) instead of the factory throwing at bind time.
|
||||
/// (2) Sub-second <see cref="TimeSpan"/> values on <c>ModbusKeepAliveOptions.Time</c> /
|
||||
/// <c>Interval</c> — the int-cast in <c>EnableKeepAlive</c> truncated <c>500 ms</c> to
|
||||
/// <c>0</c>, which most OSes interpret as "use the default", silently defeating the
|
||||
@@ -19,71 +20,41 @@ namespace ZB.MOM.WW.OtOpcUa.Driver.Modbus.Tests;
|
||||
[Trait("Category", "Unit")]
|
||||
public sealed class ModbusEdgeCaseValidationTests
|
||||
{
|
||||
/// <summary>Verifies that string tags with zero length are rejected during factory creation.</summary>
|
||||
private const string RawPath = "cell/modbus/dev1/Greeting";
|
||||
|
||||
/// <summary>Verifies that a String tag with an explicit zero length fails to map.</summary>
|
||||
[Fact]
|
||||
public void Factory_rejects_String_tag_with_StringLength_zero_via_structured_form()
|
||||
public void Mapper_rejects_String_tag_with_StringLength_zero_explicit()
|
||||
{
|
||||
const string json = """
|
||||
{
|
||||
"host": "10.0.0.10",
|
||||
"tags": [
|
||||
{ "name": "Greeting", "region": "HoldingRegisters", "address": 100, "dataType": "String", "stringLength": 0 }
|
||||
]
|
||||
}
|
||||
""";
|
||||
var ex = Should.Throw<InvalidOperationException>(
|
||||
() => ModbusDriverFactoryExtensions.CreateInstance("modbus-1", json));
|
||||
ex.Message.ShouldContain("StringLength");
|
||||
ex.Message.ShouldContain("Greeting");
|
||||
const string json = """{"region":"HoldingRegisters","address":100,"dataType":"String","stringLength":0}""";
|
||||
ModbusTagDefinitionFactory.FromTagConfig(json, RawPath, out _).ShouldBeFalse();
|
||||
}
|
||||
|
||||
/// <summary>Verifies that omitted string length defaults to zero and is rejected.</summary>
|
||||
/// <summary>Verifies that a String tag with an omitted length (defaults to zero) fails to map.</summary>
|
||||
[Fact]
|
||||
public void Factory_rejects_String_tag_with_StringLength_zero_via_missing_field()
|
||||
public void Mapper_rejects_String_tag_with_StringLength_zero_missing_field()
|
||||
{
|
||||
// No stringLength → defaults to 0. Same misconfiguration via a different DTO shape.
|
||||
const string json = """
|
||||
{
|
||||
"host": "10.0.0.10",
|
||||
"tags": [
|
||||
{ "name": "Greeting", "region": "HoldingRegisters", "address": 100, "dataType": "String" }
|
||||
]
|
||||
}
|
||||
""";
|
||||
var ex = Should.Throw<InvalidOperationException>(
|
||||
() => ModbusDriverFactoryExtensions.CreateInstance("modbus-1", json));
|
||||
ex.Message.ShouldContain("StringLength");
|
||||
// No stringLength → defaults to 0. Same misconfiguration via a different blob shape.
|
||||
const string json = """{"region":"HoldingRegisters","address":100,"dataType":"String"}""";
|
||||
ModbusTagDefinitionFactory.FromTagConfig(json, RawPath, out _).ShouldBeFalse();
|
||||
}
|
||||
|
||||
/// <summary>Verifies that string tags with length one are accepted.</summary>
|
||||
/// <summary>Verifies that a String tag with length one maps successfully.</summary>
|
||||
[Fact]
|
||||
public void Factory_accepts_String_tag_with_StringLength_one()
|
||||
public void Mapper_accepts_String_tag_with_StringLength_one()
|
||||
{
|
||||
const string json = """
|
||||
{
|
||||
"host": "10.0.0.10",
|
||||
"tags": [
|
||||
{ "name": "Greeting", "region": "HoldingRegisters", "address": 100, "dataType": "String", "stringLength": 1 }
|
||||
]
|
||||
}
|
||||
""";
|
||||
Should.NotThrow(() => ModbusDriverFactoryExtensions.CreateInstance("modbus-1", json));
|
||||
const string json = """{"region":"HoldingRegisters","address":100,"dataType":"String","stringLength":1}""";
|
||||
ModbusTagDefinitionFactory.FromTagConfig(json, RawPath, out var def).ShouldBeTrue();
|
||||
def.StringLength.ShouldBe((ushort)1);
|
||||
}
|
||||
|
||||
/// <summary>Verifies that non-string tags are unaffected by string length zero.</summary>
|
||||
/// <summary>Verifies that non-String tags are unaffected by a zero string length.</summary>
|
||||
[Fact]
|
||||
public void Factory_accepts_non_String_tag_with_StringLength_zero()
|
||||
public void Mapper_accepts_non_String_tag_with_StringLength_zero()
|
||||
{
|
||||
// The validation only kicks in for String tags — Int16 tags with StringLength=0 are normal.
|
||||
const string json = """
|
||||
{
|
||||
"host": "10.0.0.10",
|
||||
"tags": [
|
||||
{ "name": "Level", "region": "HoldingRegisters", "address": 100, "dataType": "Int16" }
|
||||
]
|
||||
}
|
||||
""";
|
||||
Should.NotThrow(() => ModbusDriverFactoryExtensions.CreateInstance("modbus-1", json));
|
||||
// The guard only kicks in for String tags — Int16 tags with StringLength=0 are normal.
|
||||
const string json = """{"region":"HoldingRegisters","address":100,"dataType":"Int16"}""";
|
||||
ModbusTagDefinitionFactory.FromTagConfig(json, RawPath, out _).ShouldBeTrue();
|
||||
}
|
||||
|
||||
/// <summary>Verifies that sub-second time spans are rounded up to at least one second.</summary>
|
||||
|
||||
Reference in New Issue
Block a user