05b424788f
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.
101 lines
5.2 KiB
C#
101 lines
5.2 KiB
C#
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"));
|
|
}
|