test(grpc-data): H3 live gate harness (H01-H06, SqlServer and QuestDB origins)

rig.py up --history --history-backend questdb adds a run-owned QuestDB for the
SOURCE historian. History seed profile: mappings grant HistoryRead, the CLI
principal's CONSUMER HistoryRead comes only from mapping-scoped grants, text is
historized (per-type aggregate refusal), new acl_permissions mutation.
history_gate.py drives H01-H06 through the Client CLI on projected NodeIds
resolved by browse from the mapping anchor, compares with the origin, and
restores the baseline after every scenario. The node probe reports the
origin's open history continuations (LocalDataServices.HistoryOpenContinuations,
now public).
This commit is contained in:
Joseph Doherty
2026-11-24 00:42:46 -05:00
parent b50019db9c
commit 8341c7f4ae
7 changed files with 535 additions and 9 deletions
+21 -6
View File
@@ -172,7 +172,7 @@ try
var root = mutation.RootElement;
string[] allowedFields = ["connection_id", "target_mode", "target_node_id", "consistency", "consumer_node_ids", "connection_enabled", "connection_allowed_operations",
"mapping_enabled", "write_through", "allowed_operations", "export_id", "export_enabled", "export_allowed_operations", "source_redundancy_mode", "consumer_redundancy_mode",
"control_redundancy_mode", "rename_tag", "upsert_tag", "upsert_reference", "remove_tag_id", "disable_feature", "key_action", "key_expiry_seconds", "upsert_connection", "upsert_mapping", "upsert_export", "remove_mapping_id", "maintenance_mode"];
"control_redundancy_mode", "rename_tag", "upsert_tag", "upsert_reference", "remove_tag_id", "disable_feature", "key_action", "key_expiry_seconds", "upsert_connection", "upsert_mapping", "upsert_export", "remove_mapping_id", "maintenance_mode", "acl_permissions"];
if (root.ValueKind != JsonValueKind.Object || root.EnumerateObject().Any(property => !allowedFields.Contains(property.Name, StringComparer.Ordinal)))
throw new InvalidOperationException("unknown fixture mutation field");
await using var db = await factory.CreateDbContextAsync();
@@ -283,7 +283,13 @@ try
await db.UnsTagReferences.Where(x => x.TagId == removeTag.GetString()).ExecuteDeleteAsync();
await db.Tags.Where(x => x.TagId == removeTag.GetString()).ExecuteDeleteAsync();
}
if (root.TryGetProperty("disable_feature", out var disable) && disable.GetBoolean())
if (root.TryGetProperty("acl_permissions", out var aclPermissions))
{
// H3: {"node_acl_id": "...", "permission_flags": <int>} — one existing row's flags (baseline restore reverts it).
var acl = await db.NodeAcls.SingleAsync(x => x.NodeAclId == aclPermissions.GetProperty("node_acl_id").GetString());
acl.PermissionFlags = (NodePermissions)aclPermissions.GetProperty("permission_flags").GetInt32();
}
if (root.TryGetProperty("disable_feature", out var disable) && disable.GetBoolean())
{
foreach (var row in await db.DataConnections.ToListAsync()) { row.Enabled = false; row.Revision++; }
foreach (var row in await db.RemoteNamespaceMappings.ToListAsync()) { row.Enabled = false; row.Revision++; }
@@ -328,8 +334,11 @@ try
foreach (var node in nodes.Where(x => x.StartsWith(cluster.ToLowerInvariant() + "-", StringComparison.Ordinal)))
db.ClusterNodes.Add(new() { NodeId = node + ":4053", ClusterId = cluster, Host = node, OpcUaPort = 4840, DashboardPort = 9000,
GrpcPort = 4056, ApplicationUri = "urn:OtOpcUa:grpc-data:" + node, CreatedBy = "grpc-data-local-gate" });
// H3 (history profile): on CONSUMER the CLI principal's HistoryRead comes ONLY from the mapping-scoped grants below,
// so a scenario can take it away per mapping (plan §6: mapped history needs HistoryRead on the mapping scope).
db.NodeAcls.Add(new() { NodeAclRowId = Guid.NewGuid(), NodeAclId = "cli-" + cluster, ClusterId = cluster,
Principal = "fixture-cli", ScopeKind = NodeAclScopeKind.Cluster, PermissionFlags = NodePermissions.Admin });
Principal = "fixture-cli", ScopeKind = NodeAclScopeKind.Cluster,
PermissionFlags = history && cluster == "CONSUMER" ? NodePermissions.Admin & ~NodePermissions.HistoryRead : NodePermissions.Admin });
}
db.DriverInstances.Add(new() { DriverInstanceRowId = Guid.NewGuid(), DriverInstanceId = "source-modbus", ClusterId = "SOURCE", Name = "modbus", DriverType = "Modbus",
DriverConfig = """{"TimeoutMs":2000,"AutoReconnect":true,"Probe":{"Enabled":true,"ProbeAddress":0}}""" });
@@ -347,7 +356,9 @@ try
TagConfig = """{"region":"HoldingRegisters","address":24,"dataType":"UInt16","isArray":true,"arrayLength":3,"writable":true}""" });
db.Tags.Add(new() { TagRowId = Guid.NewGuid(), TagId = "source-text", DeviceId = "source-device", Name = "text", DataType = "String",
AccessLevel = TagAccessLevel.ReadWrite, WriteIdempotent = false, PollGroupId = "source-fast",
TagConfig = """{"region":"HoldingRegisters","address":40,"dataType":"String","stringLength":16,"writable":true}""" });
TagConfig = history
? """{"region":"HoldingRegisters","address":40,"dataType":"String","stringLength":16,"writable":true,"isHistorized":true}"""
: """{"region":"HoldingRegisters","address":40,"dataType":"String","stringLength":16,"writable":true}""" });
db.UnsAreas.Add(new() { UnsAreaRowId = Guid.NewGuid(), UnsAreaId = "source-area", ClusterId = "SOURCE", Name = "area" });
db.UnsLines.Add(new() { UnsLineRowId = Guid.NewGuid(), UnsLineId = "source-line", UnsAreaId = "source-area", Name = "line" });
var uuid = Guid.NewGuid();
@@ -376,7 +387,10 @@ try
ClusterId = "CONSUMER", DataConnectionId = "consumer-source", Enabled = true, ConsumerNodeIds = ["consumer-1:4053", "consumer-2:4053"],
Realm = realm, RemoteRealm = realm, LocalParentKind = "Cluster", LocalParentId = "CONSUMER", BranchName = "remote-source",
RemoteRootEntityId = entity, RemoteNamespaceUri = realm == DataRealm.Raw ? V3NodeIds.RawNamespaceUri : V3NodeIds.UnsNamespaceUri,
RemoteIdentifierKind = "string", RemoteIdentifier = realm == DataRealm.Raw ? "modbus/plc" : equipment, AllowedOperations = operations, WriteThrough = true });
RemoteIdentifierKind = "string", RemoteIdentifier = realm == DataRealm.Raw ? "modbus/plc" : equipment, AllowedOperations = grantedOperations, WriteThrough = true });
if (history)
db.NodeAcls.Add(new() { NodeAclRowId = Guid.NewGuid(), NodeAclId = "cli-history-map-" + name, ClusterId = "CONSUMER", Principal = "fixture-cli",
ScopeKind = NodeAclScopeKind.RemoteNamespaceMapping, ScopeId = "map-" + name, PermissionFlags = NodePermissions.Browse | NodePermissions.HistoryRead });
}
if (history)
// The second principal's origin ACL also lacks HistoryRead: with its export's HistoryRead off the RPC is refused
@@ -403,7 +417,8 @@ try
browse_roots = new { raw = "modbus/plc", uns = unsBrowseRoot },
browse_subjects = new { raw = "modbus/plc", uns = "area/line/plc" },
origin_paths = new { raw = "modbus/plc/scalar", uns = "area/line/plc/scalar", raw_array = "modbus/plc/vector", uns_array = "area/line/plc/vector", raw_string = "modbus/plc/text", uns_string = "area/line/plc/text" }, aliases = new[] { "raw", "uns" },
history = history ? new { historized = new { raw = "modbus/plc/counter", uns = "area/line/plc/counter" }, unhistorized = new { raw = "modbus/plc/scalar", uns = "area/line/plc/scalar" } } : null });
history = history ? new { historized = new { raw = "modbus/plc/counter", uns = "area/line/plc/counter" }, unhistorized = new { raw = "modbus/plc/scalar", uns = "area/line/plc/scalar" },
historized_string = new { raw = "modbus/plc/text", uns = "area/line/plc/text" } } : null });
return 0;
}
catch (Exception error)