From 4e6535ee1df6c667b15abab070574cbedb3fbcd9 Mon Sep 17 00:00:00 2001 From: Joseph Doherty Date: Tue, 24 Nov 2026 17:25:31 -0500 Subject: [PATCH] =?UTF-8?q?test(grpc-data):=20A3=20live=20smoke=20?= =?UTF-8?q?=E2=80=94=20conditions=20profile=20makes=20the=20CONSUMER=20con?= =?UTF-8?q?dition-bearing;=20conditions=5Fa3=5Fsmoke.py=20acknowledges=20t?= =?UTF-8?q?he=20imported=20ScalarHigh=20through=20the=20consumer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../grpc-data/conditions_a3_smoke.py | 132 ++++++++++++++++++ scripts/validation/grpc-data/seed/Program.cs | 8 +- 2 files changed, 138 insertions(+), 2 deletions(-) create mode 100644 scripts/validation/grpc-data/conditions_a3_smoke.py diff --git a/scripts/validation/grpc-data/conditions_a3_smoke.py b/scripts/validation/grpc-data/conditions_a3_smoke.py new file mode 100644 index 000000000..da7f1393d --- /dev/null +++ b/scripts/validation/grpc-data/conditions_a3_smoke.py @@ -0,0 +1,132 @@ +"""A3 consumer-condition live smoke on a `rig.py up --conditions` run (plan §9 A3 exit; the full gate is A4). + +Raises the SOURCE scripted alarm `ScalarHigh` (scalar register 20 := 150) through the device control API, then: + +1. starts the CLI `alarms --refresh` on the SOURCE Primary (the origin's OWN subscriber) and on the CONSUMER Primary (whose + Server-object item opens condition demand, so the consumer imports ScalarHigh over its data connection); +2. waits for the IMPORTED `ScalarHigh` (Active, Unacknowledged) on the consumer, with its consumer-minted EventId and its + `mapped/conditions` ConditionNodeId; +3. refuses first: a bogus EventId must answer `BadEventIdUnknown` (nothing sent); +4. acknowledges it THROUGH THE CONSUMER with the CLI `ack` (§5.6: claimed by the node manager, dispatched to the origin's + `CallConditionMethod`, never applied locally); +5. requires the origin's own subscriber to see EXACTLY ONE `Active, Acknowledged` ScalarHigh event, and the consumer to + see the acknowledgement come back (the origin's record re-imported) — exactly one consumer `Active, Acknowledged` event; +6. clears the alarm. + +Evidence lands in the run's restricted `evidence/` folder (`A3-*.txt`, `A3-*.process.json`, `A3-conditions-consumer.json`). +""" +import argparse +import json +import os +import re +import signal +import subprocess +import sys +import time + +import scenarios + + +def watch(runner, node, name): + log = runner.folder / name + descriptor = os.open(log, os.O_WRONLY | os.O_CREAT | os.O_TRUNC, 0o600) + process = subprocess.Popen(["dotnet", str(runner.cli_dll), "alarms", "-u", runner.endpoint(node), "-U", "apikey", "-P", runner.key, + "--refresh", "-i", "250"], stdout=descriptor, stderr=subprocess.STDOUT, start_new_session=True) + os.close(descriptor) + return process, log + + +def stop(process): + process.send_signal(signal.SIGINT) + try: + process.wait(timeout=20) + except subprocess.TimeoutExpired: + process.kill() + process.wait(timeout=10) + + +def blocks(log, condition="ScalarHigh"): + found = [] + for block in log.read_text(errors="replace").split("\n\n"): + if f"Condition: {condition}" not in block: + continue + fields = {} + for line in block.splitlines(): + match = re.match(r"\s*(State|ConditionNodeId|EventId|Message):\s*(.*)$", line) + if match: + fields[match.group(1)] = match.group(2).strip() + found.append(fields) + return found + + +def wait_for(predicate, timeout, step=1.0): + deadline = time.monotonic() + timeout + while time.monotonic() < deadline: + value = predicate() + if value: + return value + time.sleep(step) + return predicate() + + +def main(argv=None): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("--run-id", required=True) + parser.add_argument("--settle-seconds", type=int, default=8) + parser.add_argument("--import-timeout", type=int, default=120) + arguments = parser.parse_args(argv) + runner = scenarios.ScenarioRunner(arguments.run_id) + runner.active, runner.deadline = "A3", time.monotonic() + 900 + runner.publish() + runner.device("set", address=20, value=150) + time.sleep(arguments.settle_seconds) + source, consumer = runner.primary("source"), runner.primary("consumer") + origin_watch, origin_log = watch(runner, source, "A3-origin-alarms.txt") + consumer_watch, consumer_log = watch(runner, consumer, "A3-consumer-alarms.txt") + report = {"source_primary": source, "consumer_primary": consumer, "checks": {}} + try: + imported = wait_for(lambda: next((b for b in blocks(consumer_log) if b.get("State") == "Active, Unacknowledged" + and b.get("EventId") and b.get("ConditionNodeId")), None), arguments.import_timeout) + report["checks"]["imported_active_unacked"] = bool(imported) + if not imported: + raise scenarios.ScenarioError("the consumer never showed the imported ScalarHigh (Active, Unacknowledged)") + report["imported"] = {"condition_node_id": imported["ConditionNodeId"], "event_id_len": len(imported["EventId"])} + endpoint = runner.endpoint(consumer) + base = ["dotnet", str(runner.cli_dll), "ack", "-u", endpoint, "-U", "apikey", "-P", runner.key, "-n", imported["ConditionNodeId"]] + + bogus = runner.process(base + ["-e", "00" * 16, "-c", "A3 bogus"], "A3-ack-bogus-eventid", timeout=60) + bogus_text = bogus.stdout + bogus.stderr + report["checks"]["bogus_eventid_refused"] = ("BadEventIdUnknown" in bogus_text or "809A0000" in bogus_text.upper()) \ + and "successful" not in bogus_text + report["bogus"] = bogus_text[-300:] + time.sleep(3) + report["checks"]["nothing_acked_after_bogus"] = all(b.get("State") != "Active, Acknowledged" for b in blocks(origin_log)) + + started = time.monotonic() + ack = runner.process(base + ["-e", imported["EventId"], "-c", "A3 consumer ack"], "A3-ack-consumer", timeout=60) + report["ack"] = {"returncode": ack.returncode, "elapsed_ms": round((time.monotonic() - started) * 1000), + "stdout": ack.stdout[-400:]} + report["checks"]["ack_good"] = ack.returncode == 0 and "Acknowledge successful" in ack.stdout + + acked_back = wait_for(lambda: any(b.get("State") == "Active, Acknowledged" for b in blocks(consumer_log)), 30) + report["checks"]["consumer_sees_ack_back"] = bool(acked_back) + time.sleep(6) # let any duplicate arrive before counting + finally: + stop(consumer_watch) + stop(origin_watch) + runner.device("set", address=20, value=0) + + origin_states = [b.get("State") for b in blocks(origin_log)] + consumer_states = [b.get("State") for b in blocks(consumer_log)] + report["origin_subscriber"] = {"states": origin_states, "active_acknowledged_events": origin_states.count("Active, Acknowledged")} + report["consumer_subscriber"] = {"states": consumer_states, "active_acknowledged_events": consumer_states.count("Active, Acknowledged")} + report["checks"]["origin_exactly_one_ack_event"] = report["origin_subscriber"]["active_acknowledged_events"] == 1 + report["checks"]["consumer_exactly_one_ack_event"] = report["consumer_subscriber"]["active_acknowledged_events"] == 1 + report["passed"] = all(report["checks"].values()) + runner.save("A3-conditions-consumer.json", report) + print(json.dumps(report, indent=2)[:20000]) + return 0 if report["passed"] else 1 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/scripts/validation/grpc-data/seed/Program.cs b/scripts/validation/grpc-data/seed/Program.cs index 5d7ed1d1c..8b30abfb5 100644 --- a/scripts/validation/grpc-data/seed/Program.cs +++ b/scripts/validation/grpc-data/seed/Program.cs @@ -388,7 +388,10 @@ try db.DataConnections.Add(new() { DataConnectionRowId = Guid.NewGuid(), DataConnectionId = "consumer-source", ClusterId = "CONSUMER", Enabled = true, ConsumerNodeIds = ["consumer-1:4053", "consumer-2:4053"], TargetMode = DataTargetMode.Cluster, ExpectedClusterId = "SOURCE", EligibleTargetNodeIds = ["source-1:4053", "source-2:4053"], Endpoints = ["https://source-1:4057", "https://source-2:4057"], - SecretReference = "secret:data/source", SecretScopeClusterId = "CONSUMER", AllowedOperations = grantedOperations, + // A3: the conditions profile makes the CONSUMER condition-bearing too (connection + mappings carry AlarmSubscribe and + // the method bits), so a consumer Server-object subscription imports ScalarHigh and can acknowledge it remotely. + SecretReference = "secret:data/source", SecretScopeClusterId = "CONSUMER", + AllowedOperations = grantedOperations | (conditions ? DataOperationSets.ConditionGrants : DataOperations.None), TimeoutMilliseconds = 30000 }); foreach (var realm in new[] { DataRealm.Raw, DataRealm.Uns }) { @@ -406,7 +409,8 @@ 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 = grantedOperations, WriteThrough = true }); + RemoteIdentifierKind = "string", RemoteIdentifier = realm == DataRealm.Raw ? "modbus/plc" : equipment, + AllowedOperations = grantedOperations | (conditions ? DataOperationSets.ConditionGrants : DataOperations.None), 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 });