fix(client): Client.Shared EndpointSelector uses the shared OpcUaEndpointUrlRewriter (#812)

Client.Shared now project-references Driver.OpcUaClient.Contracts (Core.Abstractions
only, no NuGet/SDK; pinned by ContractsIsDependencyLightTests) and delegates the
host/port rewrite to OpcUaEndpointUrlRewriter, deleting its own copy.

The two copies differed; reconciled toward the client so its pinned behaviour is
unchanged (EndpointSelectorRewriteParityTests, written green against the old copy):
- no-op rewrite (same host case-insensitively + same port) now returns the advertised
  string verbatim in the shared rewriter too (it re-serialised: added a trailing slash
  and case-folded a case-only host difference);
- a real rewrite serialises via AbsoluteUri, not Uri.ToString(), which un-escaped the
  advertised path (/x%20y became /x y) in the driver + browser;
- unusable URLs: the rewriter still falls back to the configured URL (driver/browser);
  the client keeps its loud failure as call-site validation (null -> InvalidOperation,
  unparseable -> UriFormatException).
This commit is contained in:
Joseph Doherty
2026-11-10 22:46:51 -05:00
parent 90491aa8b5
commit d52a3b1c64
4 changed files with 64 additions and 29 deletions
@@ -54,10 +54,28 @@ public sealed class OpcUaClientEndpointRewriteTests
}
[Fact]
public void Host_matching_is_case_insensitive_and_keeps_the_configured_spelling()
public void Host_matching_is_case_insensitive_so_a_case_only_difference_is_not_a_rewrite()
{
// #812: unified with the Client CLI/UI rule — nothing to rewrite, so the advertised string comes back verbatim
// (it used to be re-serialised with the configured spelling; DNS is case-insensitive, so the target is the same).
OpcUaEndpointUrlRewriter.Rewrite("opc.tcp://PLC-A:4840/Server", "OPC.TCP://plc-a:4840/")
.ShouldBe("opc.tcp://plc-a:4840/Server");
.ShouldBe("opc.tcp://PLC-A:4840/Server");
}
[Fact]
public void A_no_op_rewrite_returns_the_advertised_string_verbatim()
{
// #812: no trailing slash appended when nothing changes (the Client CLI/UI's long-standing behaviour).
OpcUaEndpointUrlRewriter.Rewrite("opc.tcp://server:4840", "opc.tcp://server:4840")
.ShouldBe("opc.tcp://server:4840");
}
[Fact]
public void A_rewrite_keeps_the_advertised_path_escaping()
{
// #812: Uri.ToString() un-escapes ("/x%20y" became "/x y"); AbsoluteUri keeps the server's own escaping.
OpcUaEndpointUrlRewriter.Rewrite("opc.tcp://a:4840/x%20y?q=1", "opc.tcp://b:1/")
.ShouldBe("opc.tcp://b:1/x%20y?q=1");
}
[Fact]