mirror of
https://github.com/OPCFoundation/UA-.NETStandard.git
synced 2026-10-20 00:31:32 +08:00
da7412c429
## Summary - support the xRegistry 0.6.0 distinct Resource/Version hierarchy: `Registry -> Group -> Resource -> Versions -> Version` - instantiate stable logical Resource nodes separately from exact Version nodes while preserving existing Version NodeIds - delegate logical Resource FileType operations and Version-view metadata to the selected default Version with handle pinning and shared writer reservations - make Resource and Version delete behavior role-stable and use `MetaEpoch` / `Epoch` respectively - use stable Resource SourceNodes, exact Version SourceNodes and the `Server -> Registry -> Group -> Resource -> Version` notifier chain - keep a model-metadata-gated client fallback for 0.5 flat Servers; 0.6 Servers expose no legacy aliases - target `HasWoTProjection` at the real stable logical Resource node - use `AsyncCustomNodeManager` for the registration, fast-path, and federation managers, with awaited lifecycle, node mutations, event delivery, and cleanup - handle startup rollback, reentrant deletion callbacks, undisclosed file handles, and retryable cleanup without blocking unrelated file operations ## Authoritative dependencies - companion specification: OPCF-Members/spec-drafts#32 at `d3399fca025025a73e5a6b599f850a81d985c060` - OPC UA binding: xregistry/spec#568 - xRegistry event semantics: xregistry/spec#563, merged as `66ee31e47fbadff6ab982ae1516f7d9065e46b64` - companion NodeSet SHA-256: `369f5f3f1814b333e4eeb52bfb4b6a730cdff372505a5f91a54c94f0016ac4cf` ## Review feedback - keep the WoT Connectivity information-model designation at `1.1`; draft revisions update the publication date without changing the model version - eliminate all 198 unique CA1861 diagnostics across 54 files and remove seven obsolete project suppressions - fix the analyzer-clean touched-path CA1307 and the hierarchy follow-up CA1846/CA1851 diagnostics without dropping legacy-TFM compatibility - recover the reconcile queue after callback faults/cancellation and continue accepted pending changes - remove migration guidance for the xRegistry managers, which are new in 2.0 ## Compatibility - public WoT Connectivity model designation remains `1.1` - generated event-record ABI, constructors, options, NodeIds, and stored documents remain compatible - the generic xRegistry managers are new in 2.0 and implement `IAsyncNodeManager`; use `IAsyncNodeManagerFactory` and the async lifecycle hooks (see `docs\XRegistry.md`) - persistence schema and document blobs remain compatible unless noted below ## Validation - merge validation at `980422f76` with upstream `e8bec27d5`: 454 targeted WoT/materialization/model/registry cases and all 327 XRegistry cases passed on both net10.0 and net48; all 29 net10 aggregation sample cases passed - feedback regressions at `308e8ba74`: 55 targeted queue and live registry event/projection/lifecycle cases passed on each of net10.0 and net48 - prior CI: all 266 checks passed at `6489a0908`; the unchanged Ubuntu Core certificate-counter test and dependent jobs passed on the one-time retry ([run 34117304035, attempt 2](https://github.com/OPCFoundation/UA-.NETStandard/actions/runs/34117304035/attempts/2)) - `Opc.Ua.XRegistry.Tests` — 327 passed on net10.0 and net48 for migration commit `32c914aaf` - `Opc.Ua.WotCon.Tests` net10.0 — 1348 passed - `Opc.Ua.WotCon.Bindings.Tests` net10.0 — 683 passed - `Opc.Ua.SourceGeneration.Core.Tests` net10.0 — 3807 passed, 8 skipped - `Opc.Ua.SourceGeneration.Tests` net10.0 — 145 passed - `Opc.Ua.SourceGeneration.Stack.Tests` net10.0 — 94 passed - affected XRegistry and WoT client/server projects build successfully - xRegistry NodeSet is byte-identical to the companion artifact - repository-wide CA1861 inventory — 198 unique diagnostics across 54 files reduced to zero - targeted changed-fixture validation — 1,098 passed, 3 skipped, 0 failed - constrained full `UA.slnx` net10.0 Release build — CA1861 = 0 - `Opc.Ua.XRegistry.Client` net472 and netstandard2.1 builds — 0 warnings, 0 errors - independent shared-array safety review — no significant issues - `git diff --check` The final review regressions cover concurrent reconcile/open, synthetic logical handle collisions across default switches, cross-session Close isolation, shared writer reservations, logical FileType property/change propagation, logical Labels delegation, role-fixed deletion, event sources, model-version gating, and stable `HasWoTProjection` targets. The companion specification and protocol binding are reviewed in the linked PRs above. --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 5c79a1ed-6dab-4522-a9fc-6548caa78ad5 Copilot-Session: b605797f-a97a-4cd0-8f12-016d33c2fd88 Copilot-Session: 7ef369a5-2307-4f71-8a11-15af0e72f240 Copilot-Session: e716d455-8397-4d22-9c5a-398847ab7317
297 lines
13 KiB
C#
297 lines
13 KiB
C#
/* ========================================================================
|
|
* Copyright (c) 2005-2026 The OPC Foundation, Inc. All rights reserved.
|
|
*
|
|
* OPC Foundation MIT License 1.00
|
|
*
|
|
* Permission is hereby granted, free of charge, to any person
|
|
* obtaining a copy of this software and associated documentation
|
|
* files (the "Software"), to deal in the Software without
|
|
* restriction, including without limitation the rights to use,
|
|
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
* copies of the Software, and to permit persons to whom the
|
|
* Software is furnished to do so, subject to the following
|
|
* conditions:
|
|
*
|
|
* The above copyright notice and this permission notice shall be
|
|
* included in all copies or substantial portions of the Software.
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
* OTHER DEALINGS IN THE SOFTWARE.
|
|
*
|
|
* The complete license agreement can be found here:
|
|
* http://opcfoundation.org/License/MIT/1.00/
|
|
* ======================================================================*/
|
|
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using Moq;
|
|
using NUnit.Framework;
|
|
using Opc.Ua.Vision.Server;
|
|
|
|
namespace Opc.Ua.Vision.Tests
|
|
{
|
|
/// <summary>
|
|
/// Pins the wire contract of the Vision Methods.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// A Method is only callable if three things hold: the Method node
|
|
/// exists on the instance, it carries an <c>InputArguments</c>
|
|
/// Property so the stack knows how many arguments to expect, and its
|
|
/// <c>MethodDeclarationId</c> names the type's declaration so a client
|
|
/// calling with the type-declaration MethodId resolves to it. None of
|
|
/// the three held before, and no unit test could see it, because the
|
|
/// dispatcher tests invoke the handler delegates directly and never go
|
|
/// through <c>MethodState.Call</c>.
|
|
/// </remarks>
|
|
[TestFixture]
|
|
[Category("Vision")]
|
|
public sealed class VisionMethodSurfaceTests
|
|
{
|
|
[Test]
|
|
public async Task PipelineWithAnInferenceProviderExposesTheInferenceMethods()
|
|
{
|
|
InferencePipelineState pipeline = await BuildPipelineAsync(
|
|
withInference: true, withFeedback: false).ConfigureAwait(false);
|
|
|
|
Assert.Multiple(() =>
|
|
{
|
|
Assert.That(pipeline.RunInference, Is.Not.Null,
|
|
"A pipeline that can run inference must expose RunInference.");
|
|
Assert.That(pipeline.StartContinuous, Is.Not.Null);
|
|
Assert.That(pipeline.Stop, Is.Not.Null);
|
|
Assert.That(pipeline.Results, Is.Not.Null,
|
|
"RunInference publishes into Results, so the folder must exist.");
|
|
});
|
|
}
|
|
|
|
[Test]
|
|
public async Task RunInferenceDeclaresItsArgumentsSoACallIsNotRefused()
|
|
{
|
|
InferencePipelineState pipeline = await BuildPipelineAsync(
|
|
withInference: true, withFeedback: false).ConfigureAwait(false);
|
|
RunInferenceMethodState method = pipeline.RunInference!;
|
|
|
|
Assert.Multiple(() =>
|
|
{
|
|
Assert.That(method.InputArguments, Is.Not.Null,
|
|
"Without InputArguments the stack expects zero arguments and " +
|
|
"refuses the call with BadTooManyArguments.");
|
|
Assert.That(method.InputArguments!.Value.Count, Is.EqualTo(1));
|
|
Assert.That(method.InputArguments!.Value[0].Name, Is.EqualTo("Timestamp"));
|
|
Assert.That(method.OutputArguments, Is.Not.Null);
|
|
Assert.That(method.OutputArguments!.Value.Count, Is.EqualTo(1));
|
|
Assert.That(method.OutputArguments!.Value[0].Name, Is.EqualTo("ResultId"));
|
|
});
|
|
}
|
|
|
|
[Test]
|
|
public async Task RunInferenceNamesTheTypeDeclarationSoAClientCallResolves()
|
|
{
|
|
await using var fixture = new VisionServerFixture();
|
|
await fixture.StartAsync().ConfigureAwait(false);
|
|
InferencePipelineState pipeline = await BuildPipelineAsync(
|
|
fixture, withInference: true, withFeedback: false).ConfigureAwait(false);
|
|
|
|
NodeId expected = ExpandedNodeId.ToNodeId(
|
|
MethodIds.InferencePipelineType_RunInference,
|
|
fixture.Manager.SystemContext.NamespaceUris);
|
|
|
|
Assert.That(pipeline.RunInference!.MethodDeclarationId, Is.EqualTo(expected),
|
|
"A client calls with the type-declaration MethodId; NodeState.FindMethod " +
|
|
"only matches it against MethodDeclarationId.");
|
|
}
|
|
|
|
[Test]
|
|
public async Task PipelineWithAFeedbackSinkExposesTheFourFeedbackMethods()
|
|
{
|
|
InferencePipelineState pipeline = await BuildPipelineAsync(
|
|
withInference: false, withFeedback: true).ConfigureAwait(false);
|
|
|
|
Assert.That(pipeline.Feedback, Is.Not.Null,
|
|
"A pipeline with a feedback sink must expose the Feedback object.");
|
|
VisionFeedbackState feedback = pipeline.Feedback!;
|
|
Assert.Multiple(() =>
|
|
{
|
|
Assert.That(feedback.SubmitDetections, Is.Not.Null);
|
|
Assert.That(feedback.SubmitInspectionResult, Is.Not.Null);
|
|
Assert.That(feedback.SubmitCorrection, Is.Not.Null);
|
|
Assert.That(feedback.SubmitImageReference, Is.Not.Null);
|
|
});
|
|
}
|
|
|
|
[Test]
|
|
public async Task SubmitCorrectionDeclaresAllSevenArgumentsInOrder()
|
|
{
|
|
InferencePipelineState pipeline = await BuildPipelineAsync(
|
|
withInference: false, withFeedback: true).ConfigureAwait(false);
|
|
SubmitCorrectionMethodState method = pipeline.Feedback!.SubmitCorrection!;
|
|
|
|
var names = new List<string>();
|
|
for (int ii = 0; ii < method.InputArguments!.Value.Count; ii++)
|
|
{
|
|
names.Add(method.InputArguments!.Value[ii].Name ?? string.Empty);
|
|
}
|
|
|
|
Assert.That(
|
|
names,
|
|
Is.EqualTo(s_stringValues1).AsCollection,
|
|
"The order is positional on the wire, so it must match the spec.");
|
|
}
|
|
|
|
[Test]
|
|
public async Task SubmitDetectionsDeclaresTheSceneIsEmptyFlagLast()
|
|
{
|
|
InferencePipelineState pipeline = await BuildPipelineAsync(
|
|
withInference: false, withFeedback: true).ConfigureAwait(false);
|
|
SubmitDetectionsMethodState method = pipeline.Feedback!.SubmitDetections!;
|
|
|
|
var names = new List<string>();
|
|
for (int ii = 0; ii < method.InputArguments!.Value.Count; ii++)
|
|
{
|
|
names.Add(method.InputArguments!.Value[ii].Name ?? string.Empty);
|
|
}
|
|
|
|
Assert.That(names, Is.EqualTo(s_stringValues2).AsCollection,
|
|
"SceneIsEmpty is what makes an empty Detections array a real " +
|
|
"observation, so it has to reach the wire in the position the " +
|
|
"specification gives it.");
|
|
}
|
|
|
|
[Test]
|
|
public async Task PipelineWithoutProvidersExposesNoMethods()
|
|
{
|
|
InferencePipelineState pipeline = await BuildPipelineAsync(
|
|
withInference: false, withFeedback: false).ConfigureAwait(false);
|
|
|
|
Assert.Multiple(() =>
|
|
{
|
|
Assert.That(pipeline.RunInference, Is.Null,
|
|
"A pipeline with no inference provider must not advertise RunInference.");
|
|
Assert.That(pipeline.Feedback, Is.Null,
|
|
"A pipeline with no feedback sink must not advertise Feedback.");
|
|
});
|
|
}
|
|
|
|
[Test]
|
|
public async Task EveryChildTheBuilderCreatesCarriesAReferenceType()
|
|
{
|
|
await using var fixture = new VisionServerFixture();
|
|
await fixture.StartAsync().ConfigureAwait(false);
|
|
InferencePipelineState pipeline = await BuildPipelineAsync(
|
|
fixture, withInference: true, withFeedback: true).ConfigureAwait(false);
|
|
|
|
// A child referenced by nothing cannot be browsed from its parent
|
|
// and a browse path cannot be translated to it, so the client sees
|
|
// an object whose optional children do not exist.
|
|
AssertAllChildrenReferenced(pipeline);
|
|
}
|
|
|
|
[Test]
|
|
public async Task SensorWithAMediaProviderExposesTheMediaMethods()
|
|
{
|
|
await using var fixture = new VisionServerFixture();
|
|
await fixture.StartAsync().ConfigureAwait(false);
|
|
|
|
await fixture.Manager.ConfigureVisionAsync(context =>
|
|
{
|
|
context.Nodes.AddImageSensor("Camera", s => s
|
|
.WithSensorId("SN-CAM")
|
|
.WithModality(VisionSensorModalityEnum.Area2D)
|
|
.UseMediaProvider(new Mock<IVisionMediaProvider>().Object));
|
|
}).ConfigureAwait(false);
|
|
|
|
var sensors = new List<BaseInstanceState>();
|
|
fixture.Manager.Root.Sensors!.GetChildren(null!, sensors);
|
|
var sensor = (ImageSensorState)sensors[0];
|
|
|
|
Assert.That(sensor.Media, Is.Not.Null,
|
|
"A sensor with a media provider must expose the Media object.");
|
|
VisionMediaManagementState media = sensor.Media!;
|
|
Assert.Multiple(() =>
|
|
{
|
|
Assert.That(media.GetStreamEndpoint, Is.Not.Null);
|
|
Assert.That(media.ReleaseStreamEndpoint, Is.Not.Null);
|
|
Assert.That(media.ConfigureStreamEndpoint, Is.Not.Null);
|
|
Assert.That(media.SelectEndpoint, Is.Not.Null);
|
|
Assert.That(media.GetClip, Is.Not.Null);
|
|
Assert.That(media.GetClip!.InputArguments!.Value.Count, Is.EqualTo(5));
|
|
Assert.That(media.GetClip!.OutputArguments!.Value.Count, Is.EqualTo(3));
|
|
});
|
|
}
|
|
|
|
private static void AssertAllChildrenReferenced(NodeState node)
|
|
{
|
|
var children = new List<BaseInstanceState>();
|
|
node.GetChildren(null!, children);
|
|
for (int ii = 0; ii < children.Count; ii++)
|
|
{
|
|
Assert.That(children[ii].ReferenceTypeId.IsNull, Is.False,
|
|
$"'{children[ii].BrowseName.Name}' below '{node.BrowseName.Name}' " +
|
|
"has no reference type, so nothing can reach it.");
|
|
AssertAllChildrenReferenced(children[ii]);
|
|
}
|
|
}
|
|
|
|
private static async Task<InferencePipelineState> BuildPipelineAsync(
|
|
bool withInference,
|
|
bool withFeedback)
|
|
{
|
|
await using var fixture = new VisionServerFixture();
|
|
await fixture.StartAsync().ConfigureAwait(false);
|
|
return await BuildPipelineAsync(fixture, withInference, withFeedback)
|
|
.ConfigureAwait(false);
|
|
}
|
|
|
|
private static async Task<InferencePipelineState> BuildPipelineAsync(
|
|
VisionServerFixture fixture,
|
|
bool withInference,
|
|
bool withFeedback)
|
|
{
|
|
await fixture.Manager.ConfigureVisionAsync(context =>
|
|
{
|
|
context.Nodes.AddPipeline("Detector", p =>
|
|
{
|
|
p.WithPipelineId("detector");
|
|
if (withInference)
|
|
{
|
|
p.UseInferenceProvider(
|
|
new Mock<IVisionInferenceProvider>().Object, onServer: true);
|
|
}
|
|
if (withFeedback)
|
|
{
|
|
p.UseFeedbackSink(new Mock<IVisionFeedbackSink>().Object);
|
|
}
|
|
});
|
|
}).ConfigureAwait(false);
|
|
|
|
var pipelines = new List<BaseInstanceState>();
|
|
fixture.Manager.Root.Pipelines!.GetChildren(null!, pipelines);
|
|
return (InferencePipelineState)pipelines[0];
|
|
}
|
|
|
|
private static readonly string[] s_stringValues1 =
|
|
[
|
|
"ResultId",
|
|
"Purpose",
|
|
"CorrectedDetections",
|
|
"CorrectedCharacteristics",
|
|
"Reason",
|
|
"InlineImage",
|
|
"RetractAll",
|
|
];
|
|
private static readonly string[] s_stringValues2 =
|
|
[
|
|
"Purpose",
|
|
"Detections",
|
|
"FrameReference",
|
|
"InlineImage",
|
|
"SceneIsEmpty",
|
|
];
|
|
}
|
|
}
|