mirror of
https://github.com/OPCFoundation/UA-.NETStandard.git
synced 2026-10-18 06:31:35 +08:00
333de8305b
# Description Regression fence for the NodeSet2 import + code-generation surface. This adds a single, purpose-authored "kitchen-sink" NodeSet2 (`Opc.Ua.CoverageTest.NodeSet2.xml`) plus a small dependent secondary model that deliberately flip a broad set of the knobs defined by `UANodeSet.xsd` (every node class, every `Definition` shape, custom reference types, all five modelling rules, scalar/array/matrix values, a deep branching instance tree, and a wide set of reference relations). The same bytes are then loaded into **real** servers (`ServerFixture<T>` + `ReferenceServer`) through three independent pipelines and validated node-by-node, attribute-by-attribute, reference-by-reference: 1. **Source-generation, hand-written manager** - the XML is consumed at compile time via `<AdditionalFiles ModelSourceGeneratorPrefix="Opc.Ua.CoverageTest">`; the generated `AddOpcUaCoverageTest(context)` composes the predefined nodes inside a `CustomNodeManager2`, so every node materialises as its generated `NodeState` subclass. 2. **Runtime import** - the identical XML is imported at startup through `RuntimeNodeSetNodeManagerFactory` / `AddRuntimeNodeSet`. 3. **Source-generation, generated fluent manager** - a `[NodeManager]`-attributed partial makes the generator emit the whole `FluentNodeManagerBase` manager, factory and typed fluent-builder surface. A shared, data-driven `[TestCaseSource]` battery runs the identical assertions against all three servers, and a cross-pipeline equivalence fixture asserts the three address spaces agree. A dependent **second namespace** (`.../Secondary/`) exercises cross-namespace `HasTypeDefinition`, `HasSubtype` and `HasComponent` references in every pipeline. Authoring the model surfaced two latent source-generator bugs, both fixed here: - `NodeSetToModelDesign` crashed on a top-level `<ServerUris>` table (`StringTable.Append(null)` for the reserved local-server slot). Added a null guard plus a focused regression test (`NodesetServerUrisTests`). - `FluentBuilderGenerator` emitted colliding typed-builder accessors for any model with more than one structure encoding, because `DataTypeEncoding` objects hang off their `DataType` and surfaced as parent-less "root" instances sharing the reserved `DefaultBinary`/`DefaultXml`/`DefaultJson` symbolic names. They are encoding metadata, never fluent-wired, so they are now excluded from the typed builder. A few edges are intentionally not asserted for cross-pipeline equivalence because the pipelines legitimately differ (documented in `CoverageNodeSet/README.md`): type-dictionary / `DataTypeDescription` nodes (the generator regenerates schema rather than emitting them), a handful of ambiguous duplicate-hierarchical / View-`Organizes` edges, and runtime structure stand-ins (structure definitions are validated via the `DataTypeDefinition` round-trip instead). ## Related Issues - Fixes #4251 ## Checklist _Put an `x` in the boxes that apply. You can complete these step by step after opening the PR._ - [ ] I have signed the [CLA](https://opcfoundation.org/license/cla/ContributorLicenseAgreementv1.0.pdf) and read the [CONTRIBUTING](https://github.com/OPCFoundation/UA-.NETStandard/blob/master/CONTRIBUTING.md) doc. - [x] I have added tests that prove my fix is effective or that my feature works and increased code coverage. - [x] I have added all necessary documentation. - [x] I have verified that my changes do not introduce (new) build or analyzer warnings. - [x] I ran **all** tests locally using the **UA.slnx** solution against at least .net **framework** and .net **10**, and all passed. - [ ] I fixed **all** failing and flaky tests in the CI pipelines and **all** CodeQL warnings. - [ ] I have addressed **all** PR feedback received. --------- Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: romanett <7413710+romanett@users.noreply.github.com>
122 lines
4.9 KiB
C#
122 lines
4.9 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 Opc.Ua.CoverageTest;
|
|
using Opc.Ua.CoverageTestSecondary;
|
|
using Quickstarts.ReferenceServer;
|
|
|
|
namespace Opc.Ua.Server.Tests.CoverageNodeSet
|
|
{
|
|
/// <summary>
|
|
/// A <see cref="ReferenceServer"/> that hosts the kitchen-sink coverage
|
|
/// model through the <b>source-generation</b> pipeline. The model XML is
|
|
/// consumed at compile time via
|
|
/// <c><AdditionalFiles ModelSourceGeneratorPrefix="Opc.Ua.CoverageTest"></c>;
|
|
/// the generated <c>AddOpcUaCoverageTest</c> extension composes the
|
|
/// predefined nodes — each authored node materialising as its strongly
|
|
/// typed, generated <see cref="NodeState"/> subclass — inside the
|
|
/// hand-written <see cref="CoverageTestNodeManager"/>.
|
|
/// </summary>
|
|
public sealed class CoverageTestSourceGenServer : ReferenceServer
|
|
{
|
|
/// <summary>
|
|
/// The model namespace URI shared by both coverage pipelines.
|
|
/// </summary>
|
|
public const string NamespaceUri = CoverageTestCatalogue.NamespaceUri;
|
|
|
|
/// <summary>
|
|
/// Initializes the server and registers the source-generation node
|
|
/// manager factory for the coverage model.
|
|
/// </summary>
|
|
/// <param name="telemetry">
|
|
/// Telemetry context forwarded to the base server.
|
|
/// </param>
|
|
public CoverageTestSourceGenServer(ITelemetryContext telemetry)
|
|
: base(telemetry)
|
|
{
|
|
AddNodeManager(new CoverageTestNodeManagerFactory());
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// The <see cref="INodeManagerFactory"/> for the source-generation coverage
|
|
/// node manager.
|
|
/// </summary>
|
|
public sealed class CoverageTestNodeManagerFactory : INodeManagerFactory
|
|
{
|
|
/// <inheritdoc/>
|
|
public ArrayOf<string> NamespacesUris =>
|
|
[CoverageTestCatalogue.NamespaceUri, CoverageTestCatalogue.SecondaryNamespaceUri];
|
|
|
|
/// <inheritdoc/>
|
|
public INodeManager Create(IServerInternal server, ApplicationConfiguration configuration)
|
|
{
|
|
return new CoverageTestNodeManager(server, configuration);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// A <see cref="CustomNodeManager2"/> that composes the coverage model from
|
|
/// the source-generated <c>AddOpcUaCoverageTest</c> extension. It owns both
|
|
/// the primary and the secondary (dependent) namespaces and composes both
|
|
/// generated node sets.
|
|
/// </summary>
|
|
public sealed class CoverageTestNodeManager : CustomNodeManager2
|
|
{
|
|
/// <summary>
|
|
/// Initializes the node manager for the coverage model namespaces.
|
|
/// </summary>
|
|
/// <param name="server">
|
|
/// The server that owns the node manager.
|
|
/// </param>
|
|
/// <param name="configuration">
|
|
/// The application configuration.
|
|
/// </param>
|
|
public CoverageTestNodeManager(
|
|
IServerInternal server,
|
|
ApplicationConfiguration configuration)
|
|
: base(
|
|
server,
|
|
configuration,
|
|
CoverageTestCatalogue.NamespaceUri,
|
|
CoverageTestCatalogue.SecondaryNamespaceUri)
|
|
{
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
protected override NodeStateCollection LoadPredefinedNodes(ISystemContext context)
|
|
{
|
|
var predefinedNodes = new NodeStateCollection();
|
|
predefinedNodes.AddOpcUaCoverageTest(context);
|
|
predefinedNodes.AddOpcUaCoverageTestSecondary(context);
|
|
return predefinedNodes;
|
|
}
|
|
}
|
|
}
|