fix(tagconfig): close the four #551 residuals — accept-gate-first Inspect, three authoring rules, CSV/service gate, doc sweep
Gitea #551. 1. CSV import ran no driver-typed config gate. Its typed columns were always strictly parsed, but the free-form TagConfigJson column reached the database unread, so a CSV could author a tag the driver rejects — one that deploys green and reads BadNodeIdUnknown forever. RawTagCsvMapper.Parse now names the offending row in the staged review grid, and RawTreeService enforces the same gate on CreateTag/UpdateTag/ImportTags: a form cannot be the guarantee (the API and any future caller reach none of them, and this repo has no bUnit). A rejected import row is an ERROR — the batch inserts nothing and the row is named — never a skip. Note the brief's premise that manual entry rides ImportTagsAsync is wrong: RawManualTagEntryModal commits row-by-row via CreateTagAsync, which is why the gate had to land on all three write paths. 2/3. The seven pre-#549 Inspect methods ran a hand-list of DescribeInvalidEnum checks, so every rejection cause not on the list was invisible. They are now ACCEPT-GATE-FIRST (the MTConnect/Sql/OpcUaClient/Calculation shape): ask the driver's own reader for the verdict, then explain the refusal, with a catch-all so "the parse rejects but Inspect said nothing" is unreachable. That closes S7's absent dataType, AbCip members[], Modbus stringByteOrder and the type-dependent guards, plus causes the issue did not name (absent region/address/tagPath/symbolPath/topic, TwinCAT Structure, MQTT's Sparkplug tuple). FOCAS and MQTT keep advisories about ACCEPTED blobs, so they diagnose rather than return empty. Authoring half: ModbusTagConfigModel gains stringByteOrder; AbCipTagConfigModel asks the new AbCipTagDefinitionFactory.DescribeInvalidMember; S7TagConfigModel captures whether the SOURCE blob declared dataType and asks S7TagDefinitionFactory.DataTypeKey/DeclaresDataType. One authority per rule. 4. Doc sweep: the six factory Inspect summaries, EquipmentTagConfigInspector's class remarks and AdminOperationsActor's comment all claimed invalid enums are "silently defaulted by the lenient runtime" — false since R2-11 Phase C made the runtime reads strict. They describe rejections now.
This commit is contained in:
@@ -0,0 +1,100 @@
|
||||
using Shouldly;
|
||||
using Xunit;
|
||||
|
||||
namespace ZB.MOM.WW.OtOpcUa.Driver.AbCip.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// Gitea #551 item 3: <see cref="AbCipTagDefinitionFactory.Inspect"/> is <b>accept-gate-first</b> — it
|
||||
/// asks <see cref="AbCipTagDefinitionFactory.FromTagConfig"/> for the verdict and only explains a
|
||||
/// refusal. See <c>ModbusInspectAcceptGateTests</c>'s remarks for why both directions (never stricter,
|
||||
/// never silent) are pinned.
|
||||
/// <para>
|
||||
/// AbCip's uncovered surface was the declared-UDT <c>members</c> array: the mapper rejects the WHOLE
|
||||
/// tag for one member with no <c>name</c> or a typo'd <c>dataType</c>, but neither this gate nor the
|
||||
/// AdminUI editor (which emits only <c>tagPath</c>/<c>dataType</c>/<c>writable</c> and carries
|
||||
/// <c>members</c> through its preserved key bag) ever looked.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
public sealed class AbCipInspectAcceptGateTests
|
||||
{
|
||||
private const string RawPath = "cell/abcip/dev1/T1";
|
||||
|
||||
/// <summary>Blobs the mapper ACCEPTS — the gate must say nothing about any of them.</summary>
|
||||
public static TheoryData<string> Accepted() =>
|
||||
[
|
||||
"""{"tagPath":"Program:Main.Speed","dataType":"DInt"}""",
|
||||
"""{"tagPath":"Speed"}""",
|
||||
"""{"tagPath":"Motor","dataType":"Structure","members":[{"name":"Run","dataType":"Bool"}]}""",
|
||||
// members present but not an ARRAY is ignored by the mapper, so it must be ignored here too.
|
||||
"""{"tagPath":"Speed","members":{"name":"Run"}}""",
|
||||
"""{"tagPath":"Speed","members":[]}""",
|
||||
// A member's writable / writeIdempotent / array keys are all optional.
|
||||
"""{"tagPath":"Motor","members":[{"name":"Run"}]}""",
|
||||
];
|
||||
|
||||
/// <summary>Blobs the mapper REJECTS — the gate must produce at least one warning for each.</summary>
|
||||
public static TheoryData<string> Rejected() =>
|
||||
[
|
||||
"""{"dataType":"DInt"}""", // no tagPath
|
||||
"""{"tagPath":"","dataType":"DInt"}""", // blank tagPath
|
||||
"""{"tagPath":123}""", // tagPath not a string
|
||||
"""{"tagPath":"Speed","dataType":"DIntt"}""", // typo'd top-level dataType
|
||||
"""{"tagPath":"Motor","members":[{"dataType":"Bool"}]}""", // member with no name
|
||||
"""{"tagPath":"Motor","members":[{"name":" ","dataType":"Bool"}]}""", // member with a blank name
|
||||
"""{"tagPath":"Motor","members":[{"name":"Run","dataType":"Booll"}]}""", // typo'd member dataType
|
||||
"""{"tagPath":"Motor","members":["Run"]}""", // member not an object
|
||||
];
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Accepted))]
|
||||
public void A_config_the_mapper_accepts_draws_no_warning(string tagConfig)
|
||||
{
|
||||
AbCipTagDefinitionFactory.FromTagConfig(tagConfig, RawPath, out _).ShouldBeTrue("fixture must be accepted");
|
||||
AbCipTagDefinitionFactory.Inspect(tagConfig).ShouldBeEmpty();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Rejected))]
|
||||
public void A_config_the_mapper_rejects_is_never_passed_over_in_silence(string tagConfig)
|
||||
{
|
||||
AbCipTagDefinitionFactory.FromTagConfig(tagConfig, RawPath, out _).ShouldBeFalse("fixture must be rejected");
|
||||
AbCipTagDefinitionFactory.Inspect(tagConfig).ShouldNotBeEmpty();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void An_absent_tagPath_is_named()
|
||||
=> AbCipTagDefinitionFactory.Inspect("""{"dataType":"DInt"}""")
|
||||
.ShouldContain(w => w.Contains("'tagPath'"));
|
||||
|
||||
[Fact]
|
||||
public void A_typo_in_a_member_dataType_is_named_with_its_index()
|
||||
=> AbCipTagDefinitionFactory.Inspect(
|
||||
"""{"tagPath":"Motor","members":[{"name":"Run","dataType":"Bool"},{"name":"Speed","dataType":"Reall"}]}""")
|
||||
.ShouldContain(w => w.Contains("members[1]") && w.Contains("Reall"));
|
||||
|
||||
[Fact]
|
||||
public void A_member_with_no_name_is_named_with_its_index()
|
||||
=> AbCipTagDefinitionFactory.Inspect("""{"tagPath":"Motor","members":[{"dataType":"Bool"}]}""")
|
||||
.ShouldContain(w => w.Contains("members[0]") && w.Contains("name"));
|
||||
|
||||
// ---- DescribeInvalidMember is the shared authority the AdminUI model asks (one rule, two doors) ----
|
||||
|
||||
[Theory]
|
||||
[InlineData("""{"tagPath":"Motor","members":[{"name":"Run","dataType":"Bool"}]}""", false)]
|
||||
[InlineData("""{"tagPath":"Motor"}""", false)]
|
||||
[InlineData("""{"tagPath":"Motor","members":[]}""", false)]
|
||||
[InlineData("""{"tagPath":"Motor","members":{"name":"Run"}}""", false)]
|
||||
[InlineData("not json at all", false)]
|
||||
[InlineData("""{"tagPath":"Motor","members":[{"name":"Run","dataType":"Booll"}]}""", true)]
|
||||
[InlineData("""{"tagPath":"Motor","members":[{"dataType":"Bool"}]}""", true)]
|
||||
public void DescribeInvalidMember_over_a_string_matches_the_mapper(string tagConfig, bool expectWarning)
|
||||
=> (AbCipTagDefinitionFactory.DescribeInvalidMember(tagConfig) is not null).ShouldBe(expectWarning);
|
||||
|
||||
[Fact]
|
||||
public void A_blank_reference_draws_nothing()
|
||||
=> AbCipTagDefinitionFactory.Inspect(" ").ShouldBeEmpty();
|
||||
|
||||
[Fact]
|
||||
public void Unparseable_json_names_the_json()
|
||||
=> AbCipTagDefinitionFactory.Inspect("{oops").ShouldContain(w => w.Contains("not valid JSON"));
|
||||
}
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
using Shouldly;
|
||||
using Xunit;
|
||||
|
||||
namespace ZB.MOM.WW.OtOpcUa.Driver.AbLegacy.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// Gitea #551: <see cref="AbLegacyTagDefinitionFactory.Inspect"/> is <b>accept-gate-first</b> — it asks
|
||||
/// <see cref="AbLegacyTagDefinitionFactory.FromTagConfig"/> for the verdict and only explains a refusal.
|
||||
/// See <c>ModbusInspectAcceptGateTests</c>'s remarks for why both directions (never stricter, never
|
||||
/// silent) are pinned.
|
||||
/// </summary>
|
||||
public sealed class AbLegacyInspectAcceptGateTests
|
||||
{
|
||||
private const string RawPath = "cell/ablegacy/dev1/T1";
|
||||
|
||||
/// <summary>Blobs the mapper ACCEPTS — the gate must say nothing about any of them.</summary>
|
||||
public static TheoryData<string> Accepted() =>
|
||||
[
|
||||
"""{"address":"N7:0","dataType":"Int"}""",
|
||||
"""{"address":"B3:1/2"}""",
|
||||
"""{"address":"F8:5","dataType":"Float","isArray":true,"arrayLength":10}""",
|
||||
// An over-long array is CLAMPED by the mapper, not rejected — so the gate must stay silent, even
|
||||
// though the AdminUI model refuses it (the un-clamped length also sets OPC UA ArrayDimensions).
|
||||
"""{"address":"F8:5","dataType":"Float","isArray":true,"arrayLength":9999}""",
|
||||
];
|
||||
|
||||
/// <summary>Blobs the mapper REJECTS — the gate must produce at least one warning for each.</summary>
|
||||
public static TheoryData<string> Rejected() =>
|
||||
[
|
||||
"""{"dataType":"Int"}""", // no address
|
||||
"""{"address":"","dataType":"Int"}""", // blank address
|
||||
"""{"address":7,"dataType":"Int"}""", // address not a string
|
||||
"""{"address":"N7:0","dataType":"Intt"}""", // typo'd dataType
|
||||
];
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Accepted))]
|
||||
public void A_config_the_mapper_accepts_draws_no_warning(string tagConfig)
|
||||
{
|
||||
AbLegacyTagDefinitionFactory.FromTagConfig(tagConfig, RawPath, out _).ShouldBeTrue("fixture must be accepted");
|
||||
AbLegacyTagDefinitionFactory.Inspect(tagConfig).ShouldBeEmpty();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Rejected))]
|
||||
public void A_config_the_mapper_rejects_is_never_passed_over_in_silence(string tagConfig)
|
||||
{
|
||||
AbLegacyTagDefinitionFactory.FromTagConfig(tagConfig, RawPath, out _).ShouldBeFalse("fixture must be rejected");
|
||||
AbLegacyTagDefinitionFactory.Inspect(tagConfig).ShouldNotBeEmpty();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void An_absent_address_is_named()
|
||||
=> AbLegacyTagDefinitionFactory.Inspect("""{"dataType":"Int"}""")
|
||||
.ShouldContain(w => w.Contains("'address'"));
|
||||
|
||||
[Fact]
|
||||
public void A_blank_reference_draws_nothing()
|
||||
=> AbLegacyTagDefinitionFactory.Inspect(" ").ShouldBeEmpty();
|
||||
|
||||
[Fact]
|
||||
public void Unparseable_json_names_the_json()
|
||||
=> AbLegacyTagDefinitionFactory.Inspect("{oops").ShouldContain(w => w.Contains("not valid JSON"));
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
using Shouldly;
|
||||
using Xunit;
|
||||
|
||||
namespace ZB.MOM.WW.OtOpcUa.Driver.FOCAS.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// Gitea #551: <see cref="FocasTagDefinitionFactory.Inspect"/> gained an accept gate for its
|
||||
/// <b>rejection</b> diagnosis — see <c>ModbusInspectAcceptGateTests</c>'s remarks for why both
|
||||
/// directions are pinned.
|
||||
/// <para>
|
||||
/// FOCAS is the one factory that deliberately does NOT return empty on accept: two of its warnings
|
||||
/// are <b>advisories</b> about blobs the mapper ACCEPTS but the driver still cannot serve as
|
||||
/// authored — an unparseable FOCAS address (#540, dropped at the driver's own init) and an authored
|
||||
/// <c>writable:true</c> (the wire is read-only). Folding FOCAS into the plain "accept ⇒ empty"
|
||||
/// shape would have silently deleted both, so they are pinned here alongside the new rejections.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
public sealed class FocasInspectAcceptGateTests
|
||||
{
|
||||
private const string RawPath = "cell/focas/dev1/T1";
|
||||
|
||||
/// <summary>Blobs the mapper ACCEPTS <b>and</b> that carry no advisory — the gate must be silent.</summary>
|
||||
public static TheoryData<string> CleanAndAccepted() =>
|
||||
[
|
||||
"""{"address":"R100","dataType":"Int32"}""",
|
||||
"""{"address":"X0.0","dataType":"Bit"}""",
|
||||
"""{"address":"PARAM:1020"}""",
|
||||
"""{"address":"FIXED:Identity/SeriesNumber","dataType":"String"}""",
|
||||
];
|
||||
|
||||
/// <summary>Blobs the mapper REJECTS — the gate must produce at least one warning for each.</summary>
|
||||
public static TheoryData<string> Rejected() =>
|
||||
[
|
||||
"""{"dataType":"Int32"}""", // no address
|
||||
"""{"address":"","dataType":"Int32"}""", // blank address
|
||||
"""{"address":100}""", // address not a string
|
||||
"""{"address":"R100","dataType":"Intt32"}""", // typo'd dataType
|
||||
];
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(CleanAndAccepted))]
|
||||
public void A_clean_config_the_mapper_accepts_draws_no_warning(string tagConfig)
|
||||
{
|
||||
FocasTagDefinitionFactory.FromTagConfig(tagConfig, RawPath, out _).ShouldBeTrue("fixture must be accepted");
|
||||
FocasTagDefinitionFactory.Inspect(tagConfig).ShouldBeEmpty();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Rejected))]
|
||||
public void A_config_the_mapper_rejects_is_never_passed_over_in_silence(string tagConfig)
|
||||
{
|
||||
FocasTagDefinitionFactory.FromTagConfig(tagConfig, RawPath, out _).ShouldBeFalse("fixture must be rejected");
|
||||
FocasTagDefinitionFactory.Inspect(tagConfig).ShouldNotBeEmpty();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void An_absent_address_is_named()
|
||||
=> FocasTagDefinitionFactory.Inspect("""{"dataType":"Int32"}""")
|
||||
.ShouldContain(w => w.Contains("'address'"));
|
||||
|
||||
// ---- The two advisories the accept gate must NOT swallow ----
|
||||
|
||||
[Fact]
|
||||
public void An_unparseable_address_still_warns_even_though_the_mapper_accepts_it()
|
||||
{
|
||||
const string Blob = """{"address":"not-an-address","dataType":"Int32"}""";
|
||||
FocasTagDefinitionFactory.FromTagConfig(Blob, RawPath, out _).ShouldBeTrue("the mapper accepts any non-blank address");
|
||||
FocasTagDefinitionFactory.Inspect(Blob).ShouldContain(w => w.Contains("not parseable"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void An_authored_writable_still_warns_even_though_the_mapper_accepts_it()
|
||||
{
|
||||
const string Blob = """{"address":"R100","dataType":"Int32","writable":true}""";
|
||||
FocasTagDefinitionFactory.FromTagConfig(Blob, RawPath, out _).ShouldBeTrue("the mapper accepts writable:true");
|
||||
FocasTagDefinitionFactory.Inspect(Blob).ShouldContain(w => w.Contains("read-only"));
|
||||
}
|
||||
|
||||
/// <summary>A rejected blob still gets its advisories — the two diagnoses are independent.</summary>
|
||||
[Fact]
|
||||
public void A_rejected_config_reports_the_rejection_and_the_advisory_together()
|
||||
{
|
||||
var warnings = FocasTagDefinitionFactory.Inspect(
|
||||
"""{"address":"not-an-address","dataType":"Intt32","writable":true}""");
|
||||
|
||||
warnings.ShouldContain(w => w.Contains("dataType"));
|
||||
warnings.ShouldContain(w => w.Contains("not parseable"));
|
||||
warnings.ShouldContain(w => w.Contains("read-only"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_blank_reference_draws_nothing()
|
||||
=> FocasTagDefinitionFactory.Inspect(" ").ShouldBeEmpty();
|
||||
|
||||
[Fact]
|
||||
public void Unparseable_json_names_the_json()
|
||||
=> FocasTagDefinitionFactory.Inspect("{oops").ShouldContain(w => w.Contains("not valid JSON"));
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
using Shouldly;
|
||||
using Xunit;
|
||||
|
||||
namespace ZB.MOM.WW.OtOpcUa.Driver.Modbus.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// Gitea #551 items 2/3: <see cref="ModbusTagDefinitionFactory.Inspect"/> is <b>accept-gate-first</b> —
|
||||
/// it asks <see cref="ModbusTagDefinitionFactory.FromTagConfig"/> for the verdict and only explains a
|
||||
/// refusal.
|
||||
/// <para>
|
||||
/// Two properties, and they pull in opposite directions, which is why both are pinned here. The
|
||||
/// gate must never be <b>stricter</b> than the mapper (a warning can be promoted to a blocking
|
||||
/// deploy error by <c>TagConfigValidationMode.Error</c>, so a warning on a blob the driver serves
|
||||
/// would refuse a working config); and it must never be <b>silent</b> on a blob the mapper refuses
|
||||
/// (that tag deploys green and then reads <c>BadNodeIdUnknown</c> forever). The previous hand-list
|
||||
/// of enum checks satisfied the first and failed the second for every cause not on the list —
|
||||
/// an absent <c>region</c>, a bad <c>address</c>, <c>stringByteOrder</c>, and the two
|
||||
/// type-dependent guards.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
public sealed class ModbusInspectAcceptGateTests
|
||||
{
|
||||
private const string RawPath = "cell/modbus/dev1/T1";
|
||||
private const string Clean = """{"region":"HoldingRegisters","address":1,"dataType":"Int16"}""";
|
||||
|
||||
/// <summary>Every blob below is one the mapper ACCEPTS, so the gate must say nothing about it.</summary>
|
||||
public static TheoryData<string> Accepted() =>
|
||||
[
|
||||
Clean,
|
||||
"""{"region":"Coils","address":0,"dataType":"Bool"}""",
|
||||
"""{"region":"HoldingRegisters","address":65535,"dataType":"String","stringLength":10,"stringByteOrder":"LowByteFirst"}""",
|
||||
"""{"region":"HoldingRegisters","address":1,"dataType":"BitInRegister","bitIndex":15}""",
|
||||
// The byte/ushort NARROWING is part of the mapper's rule: bitIndex 256 truncates to bit 0 and is
|
||||
// ACCEPTED. A gate that described the un-narrowed value would refuse a tag the driver serves.
|
||||
"""{"region":"HoldingRegisters","address":1,"dataType":"BitInRegister","bitIndex":256}""",
|
||||
// A non-string enum token reads as ABSENT, not invalid — the mapper accepts it as the default.
|
||||
"""{"region":"HoldingRegisters","address":1,"dataType":3}""",
|
||||
];
|
||||
|
||||
/// <summary>Every blob below is one the mapper REJECTS, so the gate must produce at least one warning.</summary>
|
||||
public static TheoryData<string> Rejected() =>
|
||||
[
|
||||
"""{"address":1,"dataType":"Int16"}""", // no region
|
||||
"""{"region":"HoldingRegisters","dataType":"Int16"}""", // no address
|
||||
"""{"region":"HoldingRegisters","address":-1,"dataType":"Int16"}""", // address < 0
|
||||
"""{"region":"HoldingRegisters","address":65536,"dataType":"Int16"}""", // address > ushort
|
||||
"""{"region":"HoldingRegisters","address":"1","dataType":"Int16"}""", // address not a number
|
||||
"""{"region":"HoldingRegisterz","address":1,"dataType":"Int16"}""", // typo'd region
|
||||
"""{"region":"HoldingRegisters","address":1,"dataType":"Intt16"}""", // typo'd dataType
|
||||
"""{"region":"HoldingRegisters","address":1,"dataType":"Int16","byteOrder":"Bigg"}""", // typo'd byteOrder
|
||||
"""{"region":"HoldingRegisters","address":1,"dataType":"Int16","stringByteOrder":"Nope"}""", // typo'd stringByteOrder
|
||||
"""{"region":"HoldingRegisters","address":1,"dataType":"String"}""", // String with no length
|
||||
"""{"region":"HoldingRegisters","address":1,"dataType":"BitInRegister","bitIndex":16}""", // bit out of range
|
||||
];
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Accepted))]
|
||||
public void A_config_the_mapper_accepts_draws_no_warning(string tagConfig)
|
||||
{
|
||||
ModbusTagDefinitionFactory.FromTagConfig(tagConfig, RawPath, out _).ShouldBeTrue("fixture must be accepted");
|
||||
ModbusTagDefinitionFactory.Inspect(tagConfig).ShouldBeEmpty();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Rejected))]
|
||||
public void A_config_the_mapper_rejects_is_never_passed_over_in_silence(string tagConfig)
|
||||
{
|
||||
ModbusTagDefinitionFactory.FromTagConfig(tagConfig, RawPath, out _).ShouldBeFalse("fixture must be rejected");
|
||||
ModbusTagDefinitionFactory.Inspect(tagConfig).ShouldNotBeEmpty();
|
||||
}
|
||||
|
||||
// ---- The specific causes the issue named, each with a message that points at the right key ----
|
||||
|
||||
[Fact]
|
||||
public void An_absent_region_is_named()
|
||||
=> ModbusTagDefinitionFactory.Inspect("""{"address":1,"dataType":"Int16"}""")
|
||||
.ShouldContain(w => w.Contains("'region'"));
|
||||
|
||||
[Fact]
|
||||
public void An_out_of_range_address_is_named()
|
||||
=> ModbusTagDefinitionFactory.Inspect("""{"region":"Coils","address":70000,"dataType":"Int16"}""")
|
||||
.ShouldContain(w => w.Contains("'address'"));
|
||||
|
||||
/// <summary>Gitea #551 item 3: read strictly by the mapper since R2-11, checked by nothing until now.</summary>
|
||||
[Fact]
|
||||
public void A_typo_in_stringByteOrder_is_named()
|
||||
=> ModbusTagDefinitionFactory.Inspect(
|
||||
"""{"region":"HoldingRegisters","address":1,"dataType":"Int16","stringByteOrder":"HighByteFrist"}""")
|
||||
.ShouldContain(w => w.Contains("stringByteOrder") && w.Contains("HighByteFrist"));
|
||||
|
||||
[Fact]
|
||||
public void A_String_tag_with_no_stringLength_is_named()
|
||||
=> ModbusTagDefinitionFactory.Inspect("""{"region":"HoldingRegisters","address":1,"dataType":"String"}""")
|
||||
.ShouldContain(w => w.Contains("stringLength"));
|
||||
|
||||
[Fact]
|
||||
public void A_BitInRegister_tag_with_a_bit_over_15_is_named()
|
||||
=> ModbusTagDefinitionFactory.Inspect(
|
||||
"""{"region":"HoldingRegisters","address":1,"dataType":"BitInRegister","bitIndex":16}""")
|
||||
.ShouldContain(w => w.Contains("bitIndex"));
|
||||
|
||||
// ---- Framing rules preserved from the pre-#551 shape ----
|
||||
|
||||
[Fact]
|
||||
public void A_blank_reference_draws_nothing()
|
||||
=> ModbusTagDefinitionFactory.Inspect(" ").ShouldBeEmpty();
|
||||
|
||||
/// <summary>
|
||||
/// The pre-existing framing convention, deliberately left alone by #551 and shared by all eleven
|
||||
/// inspectors: a reference that does not START with <c>{</c> is not an equipment-tag TagConfig at
|
||||
/// all, so it draws nothing — even though the mapper would refuse it. Widening this is a separate
|
||||
/// decision about what a TagConfig IS, not about how a refusal is explained.
|
||||
/// </summary>
|
||||
/// <param name="reference">The non-object reference.</param>
|
||||
[Theory]
|
||||
[InlineData("just a string")]
|
||||
[InlineData("[1,2,3]")]
|
||||
[InlineData("42")]
|
||||
public void A_non_object_reference_draws_nothing_because_it_is_not_a_TagConfig(string reference)
|
||||
{
|
||||
ModbusTagDefinitionFactory.FromTagConfig(reference, RawPath, out _).ShouldBeFalse();
|
||||
ModbusTagDefinitionFactory.Inspect(reference).ShouldBeEmpty();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Unparseable_json_names_the_json()
|
||||
=> ModbusTagDefinitionFactory.Inspect("{oops").ShouldContain(w => w.Contains("not valid JSON"));
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
using Shouldly;
|
||||
using Xunit;
|
||||
|
||||
namespace ZB.MOM.WW.OtOpcUa.Driver.Mqtt.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// Gitea #551: <see cref="MqttTagDefinitionFactory.Inspect"/> gained an accept gate — see
|
||||
/// <c>ModbusInspectAcceptGateTests</c>'s remarks for why both directions (never stricter, never silent)
|
||||
/// are pinned.
|
||||
/// <para>
|
||||
/// MQTT's gate is the <b>UNION</b> of its two mappers, because <c>Inspect</c> is handed a blob with
|
||||
/// no mode: the driver's <c>MqttMode</c> decides whether
|
||||
/// <see cref="MqttTagDefinitionFactory.FromTagConfig"/> or
|
||||
/// <see cref="MqttTagDefinitionFactory.FromSparkplugTagConfig"/> reads it, and nothing on a tag row
|
||||
/// says which. Gating on the Plain mapper alone would warn that every correctly-authored Sparkplug
|
||||
/// tag has no topic — the falsification control below is exactly that case.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
public sealed class MqttInspectAcceptGateTests
|
||||
{
|
||||
private const string RawPath = "cell/mqtt/dev1/T1";
|
||||
|
||||
private static bool EitherModeAccepts(string tagConfig)
|
||||
=> MqttTagDefinitionFactory.FromTagConfig(tagConfig, RawPath, out _)
|
||||
|| MqttTagDefinitionFactory.FromSparkplugTagConfig(tagConfig, RawPath, out _);
|
||||
|
||||
/// <summary>Blobs at least one mapper ACCEPTS, with no wildcard advisory — the gate must be silent.</summary>
|
||||
public static TheoryData<string> Accepted() =>
|
||||
[
|
||||
"""{"topic":"plant/line1/temp"}""",
|
||||
"""{"topic":"plant/line1/temp","payloadFormat":"Json","dataType":"Float64","qos":1}""",
|
||||
// Sparkplug: no topic at all, and that is CORRECT — the control this whole union exists for.
|
||||
"""{"groupId":"OtOpcUaSim","edgeNodeId":"EdgeA","metricName":"Temp"}""",
|
||||
"""{"groupId":"OtOpcUaSim","edgeNodeId":"EdgeA","deviceId":"Filler1","metricName":"Node Control/Rebirth"}""",
|
||||
];
|
||||
|
||||
/// <summary>Blobs NEITHER mapper accepts — the gate must produce at least one warning for each.</summary>
|
||||
public static TheoryData<string> Rejected() =>
|
||||
[
|
||||
"{}", // no address of either shape
|
||||
"""{"payloadFormat":"Json","dataType":"String"}""", // still no address
|
||||
"""{"groupId":"G","edgeNodeId":"E"}""", // incomplete Sparkplug tuple
|
||||
"""{"topic":"a/b","payloadFormat":"Jsonn"}""", // typo'd payloadFormat
|
||||
"""{"topic":"a/b","dataType":"Flooat64"}""", // typo'd dataType
|
||||
"""{"topic":"a/b","qos":5}""", // out-of-range qos
|
||||
"""{"groupId":"G","edgeNodeId":"E","metricName":"M","qos":"high"}""", // non-numeric qos, both modes
|
||||
];
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Accepted))]
|
||||
public void A_config_a_mapper_accepts_draws_no_warning(string tagConfig)
|
||||
{
|
||||
EitherModeAccepts(tagConfig).ShouldBeTrue("fixture must be accepted by at least one mode");
|
||||
MqttTagDefinitionFactory.Inspect(tagConfig).ShouldBeEmpty();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Rejected))]
|
||||
public void A_config_neither_mapper_accepts_is_never_passed_over_in_silence(string tagConfig)
|
||||
{
|
||||
EitherModeAccepts(tagConfig).ShouldBeFalse("fixture must be rejected by both modes");
|
||||
MqttTagDefinitionFactory.Inspect(tagConfig).ShouldNotBeEmpty();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_blob_with_no_address_of_either_shape_names_both()
|
||||
{
|
||||
var warnings = MqttTagDefinitionFactory.Inspect("{}");
|
||||
warnings.ShouldContain(w => w.Contains("topic") && w.Contains("metricName"));
|
||||
}
|
||||
|
||||
/// <summary>The wildcard advisory is about an ACCEPTED blob, so the accept gate must not swallow it.</summary>
|
||||
[Fact]
|
||||
public void A_wildcard_topic_still_warns_even_though_the_mapper_accepts_it()
|
||||
{
|
||||
const string Blob = """{"topic":"plant/+/temp"}""";
|
||||
MqttTagDefinitionFactory.FromTagConfig(Blob, RawPath, out _).ShouldBeTrue("a wildcard topic is accepted on purpose");
|
||||
MqttTagDefinitionFactory.Inspect(Blob).ShouldContain(w => w.Contains("wildcard"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_blank_reference_draws_nothing()
|
||||
=> MqttTagDefinitionFactory.Inspect(" ").ShouldBeEmpty();
|
||||
|
||||
[Fact]
|
||||
public void Unparseable_json_names_the_json()
|
||||
=> MqttTagDefinitionFactory.Inspect("{oops").ShouldContain(w => w.Contains("not valid JSON"));
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
using Shouldly;
|
||||
using Xunit;
|
||||
|
||||
namespace ZB.MOM.WW.OtOpcUa.Driver.S7.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// Gitea #551 item 2: <see cref="S7TagDefinitionFactory.Inspect"/> is <b>accept-gate-first</b> — it asks
|
||||
/// <see cref="S7TagDefinitionFactory.FromTagConfig"/> for the verdict and only explains a refusal. See
|
||||
/// <c>ModbusInspectAcceptGateTests</c>'s remarks for why both directions (never stricter, never silent)
|
||||
/// are pinned.
|
||||
/// <para>
|
||||
/// S7 carries the fleet's one unique rule: the reader REQUIRES the <c>dataType</c> key to be
|
||||
/// present. A blob with only an <c>address</c> therefore deploys green and reads
|
||||
/// <c>BadNodeIdUnknown</c> forever — and neither this gate nor the AdminUI model said a word about
|
||||
/// it until #551.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
public sealed class S7InspectAcceptGateTests
|
||||
{
|
||||
private const string RawPath = "cell/s7/dev1/T1";
|
||||
|
||||
/// <summary>Blobs the mapper ACCEPTS — the gate must say nothing about any of them.</summary>
|
||||
public static TheoryData<string> Accepted() =>
|
||||
[
|
||||
"""{"address":"DB1.DBW0","dataType":"Int16"}""",
|
||||
"""{"address":"M0.0","dataType":"Bool"}""",
|
||||
"""{"address":"DB1.DBB0","dataType":"String","stringLength":254}""",
|
||||
// stringLength is irrelevant to a non-String tag, so an out-of-range remnant is ACCEPTED.
|
||||
"""{"address":"DB1.DBW0","dataType":"Int16","stringLength":9999}""",
|
||||
// A non-string dataType token satisfies the PRESENCE rule and then reads as absent ⇒ Int16.
|
||||
"""{"address":"DB1.DBW0","dataType":7}""",
|
||||
];
|
||||
|
||||
/// <summary>Blobs the mapper REJECTS — the gate must produce at least one warning for each.</summary>
|
||||
public static TheoryData<string> Rejected() =>
|
||||
[
|
||||
"""{"dataType":"Int16"}""", // no address
|
||||
"""{"address":"","dataType":"Int16"}""", // blank address
|
||||
"""{"address":123,"dataType":"Int16"}""", // address not a string
|
||||
"""{"address":"DB1.DBW0"}""", // no dataType key at all (#551)
|
||||
"""{"address":"DB1.DBW0","dataType":"Intt16"}""", // typo'd dataType
|
||||
"""{"address":"DB1.DBB0","dataType":"String","stringLength":255}""", // over the 254 S7 limit
|
||||
"""{"address":"DB1.DBB0","dataType":"String","stringLength":-1}""", // negative length
|
||||
];
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Accepted))]
|
||||
public void A_config_the_mapper_accepts_draws_no_warning(string tagConfig)
|
||||
{
|
||||
S7TagDefinitionFactory.FromTagConfig(tagConfig, RawPath, out _).ShouldBeTrue("fixture must be accepted");
|
||||
S7TagDefinitionFactory.Inspect(tagConfig).ShouldBeEmpty();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Rejected))]
|
||||
public void A_config_the_mapper_rejects_is_never_passed_over_in_silence(string tagConfig)
|
||||
{
|
||||
S7TagDefinitionFactory.FromTagConfig(tagConfig, RawPath, out _).ShouldBeFalse("fixture must be rejected");
|
||||
S7TagDefinitionFactory.Inspect(tagConfig).ShouldNotBeEmpty();
|
||||
}
|
||||
|
||||
/// <summary>The headline case: present-and-typo'd was reported; ABSENT was not (Gitea #551 item 2).</summary>
|
||||
[Fact]
|
||||
public void An_absent_dataType_is_named()
|
||||
=> S7TagDefinitionFactory.Inspect("""{"address":"DB1.DBW0"}""")
|
||||
.ShouldContain(w => w.Contains("no 'dataType'"));
|
||||
|
||||
[Fact]
|
||||
public void An_absent_address_is_named()
|
||||
=> S7TagDefinitionFactory.Inspect("""{"dataType":"Int16"}""")
|
||||
.ShouldContain(w => w.Contains("'address'"));
|
||||
|
||||
[Fact]
|
||||
public void An_out_of_range_string_length_is_named()
|
||||
=> S7TagDefinitionFactory.Inspect("""{"address":"DB1.DBB0","dataType":"String","stringLength":255}""")
|
||||
.ShouldContain(w => w.Contains("stringLength"));
|
||||
|
||||
// ---- DeclaresDataType is the shared authority the AdminUI model asks (one rule, two doors) ----
|
||||
|
||||
[Theory]
|
||||
[InlineData("""{"dataType":"Int16"}""", true)]
|
||||
[InlineData("""{"dataType":7}""", true)] // presence is judged on the KEY, not the value
|
||||
[InlineData("""{"dataType":null}""", true)]
|
||||
[InlineData("""{"address":"DB1.DBW0"}""", false)]
|
||||
public void DeclaresDataType_judges_the_key_not_the_value(string tagConfig, bool expected)
|
||||
{
|
||||
using var doc = System.Text.Json.JsonDocument.Parse(tagConfig);
|
||||
S7TagDefinitionFactory.DeclaresDataType(doc.RootElement).ShouldBe(expected);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void A_blank_reference_draws_nothing()
|
||||
=> S7TagDefinitionFactory.Inspect(" ").ShouldBeEmpty();
|
||||
|
||||
[Fact]
|
||||
public void Unparseable_json_names_the_json()
|
||||
=> S7TagDefinitionFactory.Inspect("{oops").ShouldContain(w => w.Contains("not valid JSON"));
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
using Shouldly;
|
||||
using Xunit;
|
||||
|
||||
namespace ZB.MOM.WW.OtOpcUa.Driver.TwinCAT.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// Gitea #551: <see cref="TwinCATTagDefinitionFactory.Inspect"/> is <b>accept-gate-first</b> — it asks
|
||||
/// <see cref="TwinCATTagDefinitionFactory.FromTagConfig"/> for the verdict and only explains a refusal.
|
||||
/// See <c>ModbusInspectAcceptGateTests</c>'s remarks for why both directions (never stricter, never
|
||||
/// silent) are pinned. TwinCAT's uncovered rejections were an absent <c>symbolPath</c> and the
|
||||
/// unsupported <c>Structure</c> data type — a VALID enum name that the mapper still refuses.
|
||||
/// </summary>
|
||||
public sealed class TwinCATInspectAcceptGateTests
|
||||
{
|
||||
private const string RawPath = "cell/twincat/dev1/T1";
|
||||
|
||||
/// <summary>Blobs the mapper ACCEPTS — the gate must say nothing about any of them.</summary>
|
||||
public static TheoryData<string> Accepted() =>
|
||||
[
|
||||
"""{"symbolPath":"MAIN.bStart","dataType":"Bool"}""",
|
||||
"""{"symbolPath":"MAIN.nCount"}""",
|
||||
"""{"symbolPath":"MAIN.aData","dataType":"DInt","isArray":true,"arrayLength":8}""",
|
||||
// A stale arrayLength behind a cleared isArray is scalar, not a rejection.
|
||||
"""{"symbolPath":"MAIN.nCount","dataType":"DInt","arrayLength":8}""",
|
||||
];
|
||||
|
||||
/// <summary>Blobs the mapper REJECTS — the gate must produce at least one warning for each.</summary>
|
||||
public static TheoryData<string> Rejected() =>
|
||||
[
|
||||
"""{"dataType":"Bool"}""", // no symbolPath
|
||||
"""{"symbolPath":"","dataType":"Bool"}""", // blank symbolPath
|
||||
"""{"symbolPath":42}""", // symbolPath not a string
|
||||
"""{"symbolPath":"MAIN.x","dataType":"Booll"}""", // typo'd dataType
|
||||
"""{"symbolPath":"MAIN.udt","dataType":"Structure"}""", // valid NAME the driver still refuses
|
||||
];
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Accepted))]
|
||||
public void A_config_the_mapper_accepts_draws_no_warning(string tagConfig)
|
||||
{
|
||||
TwinCATTagDefinitionFactory.FromTagConfig(tagConfig, RawPath, out _).ShouldBeTrue("fixture must be accepted");
|
||||
TwinCATTagDefinitionFactory.Inspect(tagConfig).ShouldBeEmpty();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(Rejected))]
|
||||
public void A_config_the_mapper_rejects_is_never_passed_over_in_silence(string tagConfig)
|
||||
{
|
||||
TwinCATTagDefinitionFactory.FromTagConfig(tagConfig, RawPath, out _).ShouldBeFalse("fixture must be rejected");
|
||||
TwinCATTagDefinitionFactory.Inspect(tagConfig).ShouldNotBeEmpty();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void An_absent_symbolPath_is_named()
|
||||
=> TwinCATTagDefinitionFactory.Inspect("""{"dataType":"Bool"}""")
|
||||
.ShouldContain(w => w.Contains("'symbolPath'"));
|
||||
|
||||
/// <summary>A rejection an enum-spelling check can never see: the NAME parses, the driver still refuses.</summary>
|
||||
[Fact]
|
||||
public void A_Structure_typed_tag_is_named()
|
||||
=> TwinCATTagDefinitionFactory.Inspect("""{"symbolPath":"MAIN.udt","dataType":"Structure"}""")
|
||||
.ShouldContain(w => w.Contains("Structure"));
|
||||
|
||||
[Fact]
|
||||
public void A_blank_reference_draws_nothing()
|
||||
=> TwinCATTagDefinitionFactory.Inspect(" ").ShouldBeEmpty();
|
||||
|
||||
[Fact]
|
||||
public void Unparseable_json_names_the_json()
|
||||
=> TwinCATTagDefinitionFactory.Inspect("{oops").ShouldContain(w => w.Contains("not valid JSON"));
|
||||
}
|
||||
Reference in New Issue
Block a user