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.
72 lines
3.3 KiB
C#
72 lines
3.3 KiB
C#
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"));
|
|
}
|