feat(grpc-data): X0 review - tolerate any unknown bit at the artifact/catalog seam; drop diagnostics for exports and mappings
- ValidateDeployed ignores every bit outside Understood (understood subset still validated); P02's two 1<<30 rows become 'tolerated, grants nothing'. - UnknownOperationDrops: Warning + counter tagged kind=connection|export|mapping, counted once per row per accepted artifact change; collected under each lock, logged after release. Mappings masked at Stage. - Surfaced via DataConnectionDiagnosticsSnapshot (DroppedUnknownOperations, MappingsWithDroppedOperations) and NodeDiagnosticsSnapshot.DroppedExportOperations. - End-to-end test: 1<<30 through parse -> catalog compile -> mapping stage -> runtime apply. - DataConnectionProtoContract.Validate() now runs at AddOtOpcUaDataConnections.
This commit is contained in:
+23
-2
@@ -188,7 +188,6 @@ public sealed class GrpcDataArtifactReadTests
|
||||
[InlineData("Endpoints", "null")]
|
||||
[InlineData("Endpoints", "[\"http://node-b:7443\"]")]
|
||||
[InlineData("AllowedOperations", "0")]
|
||||
[InlineData("AllowedOperations", "1073741824")]
|
||||
[InlineData("MaxBatchItems", "0")]
|
||||
[InlineData("Revision", "0")]
|
||||
public void Malformed_enabled_connection_fails_closed_with_row_diagnostics(
|
||||
@@ -235,7 +234,6 @@ public sealed class GrpcDataArtifactReadTests
|
||||
[InlineData("Realm", "0")]
|
||||
[InlineData("RootEntityId", "\"missing-origin\"")]
|
||||
[InlineData("RootKind", "\"RemoteNamespaceMapping\"")]
|
||||
[InlineData("AllowedOperations", "1073741824")]
|
||||
[InlineData("Revision", "0")]
|
||||
public void Malformed_enabled_export_cannot_become_a_broad_or_reexport_grant(
|
||||
string field,
|
||||
@@ -251,6 +249,29 @@ public sealed class GrpcDataArtifactReadTests
|
||||
error.Message.ShouldContain("export-a");
|
||||
}
|
||||
|
||||
[Trait("Phase", "X0")]
|
||||
// X0 (plan section 4.3): an operation bit this build does not understand, e.g. one a newer central authored, is
|
||||
// TOLERATED at the parse seam and grants nothing downstream. Before X0 it failed the whole row closed (and with it
|
||||
// the snapshot). Only the understood subset is validated; an all-unknown row parses and is inert.
|
||||
[Theory]
|
||||
[InlineData(1073741824, 0)]
|
||||
[InlineData(5 | 1073741824, 5)]
|
||||
[InlineData(5 | 32, 5)]
|
||||
public void Unknown_operation_bit_on_a_connection_or_export_parses_and_grants_nothing(int authored, int understood)
|
||||
{
|
||||
var root = Fixture();
|
||||
root["DataConnections"]![0]!["AllowedOperations"] = authored;
|
||||
root["DataExports"]![0]!["AllowedOperations"] = authored;
|
||||
using var parsed = DeploymentArtifact.Open(Blob(root));
|
||||
|
||||
var connection = parsed.ParseDataConnections(NodeA).ShouldHaveSingleItem();
|
||||
var export = parsed.ParseDataExports(NodeA).ShouldHaveSingleItem();
|
||||
connection.AllowedOperations.ShouldBe((DataOperations)authored, "rows are returned as authored");
|
||||
(connection.AllowedOperations & DataOperationSets.Understood).ShouldBe((DataOperations)understood);
|
||||
(export.AllowedOperations & DataOperationSets.Understood).ShouldBe((DataOperations)understood);
|
||||
(DataOperationSets.Understood & (DataOperations)1073741824).ShouldBe(DataOperations.None, "the bit is never granted");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Missing_connection_array_does_not_leave_an_enabled_orphan_mount()
|
||||
{
|
||||
|
||||
+86
@@ -152,6 +152,92 @@ public sealed class GrpcDataCatalogStagingTests : RuntimeActorTestBase
|
||||
runtime.Active.ShouldBeEmpty();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// X0 end to end (plan §4.3): an operation bit no build defines (1 << 30) on one connection, one export and one mapping
|
||||
/// flows through the REAL artifact parse, origin catalog compile, mapping stage and consumer runtime. Every other
|
||||
/// connection/export stays up, the bit is never granted anywhere, and each drop is visible in diagnostics.
|
||||
/// </summary>
|
||||
[Fact(Timeout = 30000), Trait("Phase", "X0")]
|
||||
public async Task X0_unknown_operation_bit_flows_through_parse_catalog_mapping_and_runtime_and_is_never_granted()
|
||||
{
|
||||
const DataOperations Unknown = (DataOperations)(1 << 30);
|
||||
const DataOperations Bmr = DataOperations.Browse | DataOperations.Metadata | DataOperations.Read;
|
||||
var root = JsonNode.Parse(Artifact())!.AsObject();
|
||||
root["DataConnectionScopeVersion"] = 1;
|
||||
DataConnection Connection(string id, DataOperations operations) => new()
|
||||
{
|
||||
DataConnectionId = id, ClusterId = "cluster", Revision = 1, Enabled = true, ConsumerNodeIds = ["node-a"],
|
||||
TargetMode = DataTargetMode.Node, Consistency = DataConsistency.Primary, ExpectedClusterId = "remote-cluster",
|
||||
ExpectedNodeId = "remote", Endpoints = ["https://remote.example:8443"], SecretReference = "secret:data/" + id,
|
||||
SecretScopeClusterId = "cluster", AllowedOperations = operations, MaxMessageBytes = 65536, MaxBatchItems = 16,
|
||||
MaxPageItems = 16, MaxStreams = 2, MaxMonitoredItems = 16, MaxPendingBytes = 65536, TimeoutMilliseconds = 5000,
|
||||
};
|
||||
root["DataConnections"] = JsonSerializer.SerializeToNode(new[] { Connection("link", Bmr | Unknown), Connection("plain", Bmr) });
|
||||
root["DataExports"]![0]!["AllowedOperations"] = (int)(Bmr | Unknown);
|
||||
root["DataExports"]!.AsArray().Add(JsonNode.Parse("""
|
||||
{"DataExportId":"uns","ClusterId":"cluster","Enabled":true,"Realm":2,"RootKind":"Cluster","RootEntityId":"cluster","PrincipalId":"other","AllowedOperations":7}
|
||||
"""));
|
||||
var mapping = TestMapping(); mapping.ConsumerNodeIds = ["node-a"]; mapping.RemoteNamespaceUri = V3NodeIds.RawNamespaceUri;
|
||||
mapping.AllowedOperations = DataOperations.Browse | Unknown;
|
||||
root["RemoteNamespaceMappings"] = JsonSerializer.SerializeToNode(new[] { mapping });
|
||||
var bytes = Encoding.UTF8.GetBytes(root.ToJsonString());
|
||||
|
||||
// Origin side: the catalog compiles (pre-X0 it threw "Origin catalog configuration is invalid").
|
||||
var authority = new DataPlaneAuthorityState();
|
||||
var coordinator = NewCoordinator(authority, new CatalogActivation());
|
||||
var policy = new DataOperationPolicy(authority, new TriePermissionEvaluator(authority.Tries, TimeProvider.System), TimeProvider.System);
|
||||
using var resolver = new RemoteNamespaceResolver(new ProjectedCatalogCache(8, 32, TimeProvider.System, policy),
|
||||
new BrowseContinuationRegistry(8, TimeProvider.System), new MissingProjectionSource(), policy, 8, 2);
|
||||
using var mappings = new ProjectedMappingDeploymentRuntime(coordinator, resolver);
|
||||
var attempt = Prepare(coordinator, bytes);
|
||||
using var parsed = DeploymentArtifact.Open(bytes);
|
||||
var connections = parsed.ParseDataConnections(Node.Value);
|
||||
mappings.Stage(attempt, parsed.ParseRemoteNamespaceMappings(Node.Value), connections);
|
||||
coordinator.Complete(attempt, true).ShouldBeTrue();
|
||||
var catalog = coordinator.Current.ShouldNotBeNull();
|
||||
catalog.ExportOperations("peer").ShouldBe(Bmr, "the unknown export bit is never granted");
|
||||
catalog.ExportOperations("other").ShouldBe(Bmr, "the unaffected export is up");
|
||||
catalog.DroppedUnknownOperations.ShouldBe(new Dictionary<string, DataOperations> { ["raw"] = Unknown });
|
||||
|
||||
// Mapping stage: masked, placed, counted per connection.
|
||||
mappings.Active.ShouldHaveSingleItem().Mapping.AllowedOperations.ShouldBe(DataOperations.Browse);
|
||||
mappings.DroppedUnknownOperations.ShouldBe(new Dictionary<string, DataOperations> { ["map"] = Unknown });
|
||||
var mappingDrops = mappings.CaptureDroppedByConnection();
|
||||
mappingDrops.ShouldBe(new Dictionary<string, int> { ["link"] = 1 });
|
||||
|
||||
// Consumer runtime: both connections are up; the bit is never granted; diagnostics carry the drops.
|
||||
await using var runtime = new DataConnectionDeploymentRuntime(Node.Value, "cluster", new X0Security(), new X0Activator(), 4);
|
||||
runtime.Apply(new(1, attempt.Revision, connections));
|
||||
foreach (var id in new[] { "link", "plain" })
|
||||
{
|
||||
DataConnectionDeploymentLease? lease = null;
|
||||
for (var i = 0; i < 250 && !runtime.TryAcquire(id, out lease); i++) await Task.Delay(20, TestContext.Current.CancellationToken);
|
||||
lease.ShouldNotBeNull(id);
|
||||
using (lease) lease.AllowedOperations.ShouldBe(Bmr, id);
|
||||
}
|
||||
var diagnostics = runtime.CaptureDiagnostics(null, mappingDrops).ToDictionary(x => x.ConnectionId);
|
||||
diagnostics["link"].DroppedUnknownOperations.ShouldBe(Unknown);
|
||||
diagnostics["link"].MappingsWithDroppedOperations.ShouldBe(1);
|
||||
diagnostics["plain"].DroppedUnknownOperations.ShouldBe(DataOperations.None);
|
||||
diagnostics["plain"].MappingsWithDroppedOperations.ShouldBe(0);
|
||||
}
|
||||
|
||||
private sealed class X0Security : IDataConnectionSecurityProvider
|
||||
{
|
||||
public event Action<string>? Changed { add { } remove { } }
|
||||
public ValueTask<DataConnectionSecurity?> ResolveAsync(string connectionId, Uri endpoint, CancellationToken cancellationToken) =>
|
||||
ValueTask.FromResult<DataConnectionSecurity?>(new("1", "trust", "key", () => new X0NoNetwork()));
|
||||
}
|
||||
private sealed class X0NoNetwork : HttpMessageHandler
|
||||
{
|
||||
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) =>
|
||||
throw new InvalidOperationException("This test must not use the network.");
|
||||
}
|
||||
private sealed class X0Activator : IDataConnectionScopeActivator
|
||||
{
|
||||
public Task SetScopeAsync(long version, IReadOnlyDictionary<string, string> allowlist, CancellationToken cancellationToken) => Task.CompletedTask;
|
||||
}
|
||||
|
||||
private static RemoteNamespaceMapping TestMapping() => new() { RemoteNamespaceMappingId = "map", ClusterId = "cluster",
|
||||
DataConnectionId = "link", Revision = 1, Enabled = true, Realm = DataRealm.Raw, RemoteRealm = DataRealm.Raw,
|
||||
LocalParentKind = "RawFolder", LocalParentId = "folder", BranchName = "Remote", RemoteRootEntityId = "remote-root",
|
||||
|
||||
+12
-2
@@ -36,7 +36,7 @@ public sealed class GrpcDataUnknownOperationToleranceTests
|
||||
await using var runtime = new DataConnectionDeploymentRuntime("node-a", "owner", new Security(), activator, 4);
|
||||
var history = Definition("history", DataOperations.Read | DataOperations.Browse | DataOperations.HistoryRead | DataOperations.AlarmShelve);
|
||||
var plain = Definition("plain", DataOperations.Read | DataOperations.Subscribe);
|
||||
var future = Definition("future", (DataOperations)(1 << 20) | DataOperations.AlarmSubscribe);
|
||||
var future = Definition("future", (DataOperations)(1 << 30) | DataOperations.AlarmSubscribe);
|
||||
|
||||
// The pre-X0 runtime threw ArgumentException("Unknown operation.") here for the whole snapshot.
|
||||
Should.NotThrow(() => runtime.Apply(new(1, "artifact-1", [history, plain, future])));
|
||||
@@ -50,9 +50,15 @@ public sealed class GrpcDataUnknownOperationToleranceTests
|
||||
runtime.DroppedUnknownOperations.ShouldBe(new Dictionary<string, DataOperations>(StringComparer.OrdinalIgnoreCase)
|
||||
{
|
||||
["history"] = DataOperations.HistoryRead | DataOperations.AlarmShelve,
|
||||
["future"] = (DataOperations)(1 << 20) | DataOperations.AlarmSubscribe,
|
||||
["future"] = (DataOperations)(1 << 30) | DataOperations.AlarmSubscribe,
|
||||
});
|
||||
runtime.UnknownOperationRowsDropped.ShouldBe(2);
|
||||
// The production reader: the node diagnostics snapshot carries each row's dropped bits.
|
||||
var diagnostics = runtime.CaptureDiagnostics().ToDictionary(x => x.ConnectionId);
|
||||
diagnostics["history"].DroppedUnknownOperations.ShouldBe(DataOperations.HistoryRead | DataOperations.AlarmShelve);
|
||||
diagnostics["plain"].DroppedUnknownOperations.ShouldBe(DataOperations.None);
|
||||
diagnostics["future"].DroppedUnknownOperations.ShouldBe((DataOperations)(1 << 30) | DataOperations.AlarmSubscribe);
|
||||
diagnostics["plain"].MappingsWithDroppedOperations.ShouldBeNull("no mapping evidence was supplied");
|
||||
// The input rows are not mutated: the drop is the node's reading, not a rewrite of the artifact.
|
||||
history.AllowedOperations.ShouldBe(DataOperations.Read | DataOperations.Browse | DataOperations.HistoryRead | DataOperations.AlarmShelve);
|
||||
activator.Allowlists.Last().Keys.Order(StringComparer.OrdinalIgnoreCase).ShouldBe(["future", "history", "plain"]);
|
||||
@@ -71,6 +77,10 @@ public sealed class GrpcDataUnknownOperationToleranceTests
|
||||
runtime.Apply(new(2, "artifact-2", [Definition("history", DataOperations.Read)]));
|
||||
runtime.DroppedUnknownOperations.ShouldBeEmpty();
|
||||
runtime.UnknownOperationRowsDropped.ShouldBe(1);
|
||||
|
||||
// A -> B -> A is an accepted artifact CHANGE each time, so it recounts (documented semantics).
|
||||
runtime.Apply(new(3, "artifact-1", [Definition("history", DataOperations.Read | DataOperations.HistoryRead)]));
|
||||
runtime.UnknownOperationRowsDropped.ShouldBe(2);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
Reference in New Issue
Block a user