feat: add immutable partitioned data publication hub

This commit is contained in:
Joseph Doherty
2026-11-16 01:13:10 -05:00
parent b2249ce2cb
commit 8f28a0eabf
47 changed files with 6184 additions and 173 deletions
+43 -9
View File
@@ -76,7 +76,7 @@ def command(project, expression, directory, discovery=False):
return argv + (["--list-tests"] if discovery else ["--logger", "trx;LogFileName=results.trx"])
def validate_trx(directory, started_ns, expected_classes=()):
def validate_trx(directory, started_ns, expected_classes=(), excluded_methods=()):
files = list(directory.rglob("*.trx"))
if not files:
raise GateError("missing TRX result")
@@ -108,9 +108,11 @@ def validate_trx(directory, started_ns, expected_classes=()):
for unit in root.findall(".//{*}TestDefinitions/{*}UnitTest"):
method = unit.find("{*}TestMethod")
if method is not None:
definitions[unit.get("id")] = method.get("className", "").split(",", 1)[0]
definitions[unit.get("id")] = (method.get("className", "").split(",", 1)[0], method.get("name", ""))
for result in results:
class_name = definitions.get(result.get("testId"), "")
class_name, method_name = definitions.get(result.get("testId"), ("", ""))
if class_name + "." + method_name in excluded_methods:
raise ValueError("excluded method present in results: " + class_name + "." + method_name)
for expected in expected_classes:
if class_name == expected or class_name.endswith("." + expected):
executed_classes.add(expected)
@@ -148,16 +150,38 @@ def selected_records(manifest, phase, root, case):
return records
def run_phase(manifest, phase, root, case=None, dry_run=False, invoke=subprocess.run, environ=None):
def platform_exclusions(item, platform, case):
declared = item.get("platform_exclusions", {})
if not isinstance(declared, dict) or set(declared) - {"windows", "non_windows"}:
raise GateError("invalid platform exclusions")
for values in declared.values():
if not isinstance(values, list) or any(
not isinstance(name, str) or not re.fullmatch(r"[A-Za-z_][\w]*(?:\.[A-Za-z_][\w]*)+", name)
for name in values
) or len(values) != len(set(values)):
raise GateError("invalid platform exclusions")
names = declared.get("windows" if platform == "win32" else "non_windows", [])
return [name for name in names if not case or class_matches(name, case)]
def execution_filter(expression, excluded):
if not excluded:
return expression
return "(" + expression + ")" + "".join("&(FullyQualifiedName!=" + name + ")" for name in excluded)
def run_phase(manifest, phase, root, case=None, dry_run=False, invoke=subprocess.run, environ=None, platform=None):
root = Path(root).resolve()
records = selected_records(manifest, phase, root, case)
platform = sys.platform if platform is None else platform
exclusions = [platform_exclusions(item, platform, case) for item in records]
run_id = datetime.now(timezone.utc).strftime("%Y%m%dT%H%M%S.%fZ") + "-" + uuid.uuid4().hex[:12]
directory = root / "artifacts" / "grpc-data" / run_id / "unit" / phase
if dry_run:
for index, item in enumerate(records):
target = directory / f'{index:02d}-{Path(item["project"]).stem}'
print(shlex.join(command(item["project"], item["filter"], target, True)))
print(shlex.join(command(item["project"], item["filter"], target)))
print(shlex.join(command(item["project"], execution_filter(item["filter"], exclusions[index]), target)))
return directory
directory.mkdir(parents=True, exist_ok=False)
env = unit_environment(environ)
@@ -190,7 +214,9 @@ def run_phase(manifest, phase, root, case=None, dry_run=False, invoke=subprocess
for index, item in enumerate(records):
target = directory / f'{index:02d}-{Path(item["project"]).stem}'
target.mkdir()
excluded = exclusions[index]
entry = {"project": item["project"], "filter": item["filter"],
"platform": platform, "platform_exclusions": excluded,
"new_classes": item.get("new_classes", []), "existing_classes": item.get("existing_classes", [])}
report["projects"].append(entry)
tick = time.monotonic()
@@ -201,24 +227,32 @@ def run_phase(manifest, phase, root, case=None, dry_run=False, invoke=subprocess
if case:
names = [name for name in names if class_matches(name, case)]
required_classes = item.get("new_classes", []) + item.get("existing_classes", [])
mapping = {name: [test for test in names if class_matches(test, name)] for name in required_classes}
available = {name.split("(", 1)[0] for name in names}
applicable = [name for name in names if name.split("(", 1)[0] not in excluded]
mapping = {name: [test for test in applicable if class_matches(test, name)] for name in required_classes}
write_json(target / "discovery.json", {
"filter": item["filter"], "tests": names,
"filter": item["filter"], "tests": names, "platform": platform,
"platform_exclusions": excluded,
"new_classes": {name: mapping[name] for name in item.get("new_classes", [])},
"existing_classes": {name: mapping[name] for name in item.get("existing_classes", [])},
})
if not names:
raise GateError(f"zero discovered tests for {item['project']}")
missing_exclusions = sorted(set(excluded) - available)
if missing_exclusions:
raise GateError("missing platform exclusions in discovery: " + ", ".join(missing_exclusions))
if not applicable:
raise GateError(f"zero applicable discovered tests for {item['project']}")
absent = [name for name, tests in mapping.items() if not tests]
if absent:
raise GateError(f"missing required classes: {', '.join(absent)}")
expression = item["filter"]
expression = execution_filter(item["filter"], excluded)
execution = command(item["project"], expression, target)
entry["execution_filter"] = expression
entry["execution_argv"] = execution
before = time.time_ns()
_, entry["execution_seconds"] = child(execution, target, "execution")
entry["trx"] = validate_trx(target, before, required_classes)
entry["trx"] = validate_trx(target, before, required_classes, excluded)
entry["duration_seconds"] = time.monotonic() - tick
report["status"] = "passed"
return directory
@@ -206,6 +206,59 @@ class UnitPhaseRunnerTests(unittest.TestCase):
self.assertEqual(self.calls, [])
self.assertFalse((self.root / "artifacts").exists())
def test_platform_exclusions_are_verified_and_recorded_before_execution(self):
self.manifest["P00"][0]["platform_exclusions"] = {
"non_windows": ["Example.OldTests.WindowsOnly"],
"windows": ["Example.OldTests.UnixOnly"],
}
self.listing += " Example.OldTests.WindowsOnly\n Example.OldTests.UnixOnly\n"
for platform, excluded in (("darwin", "Example.OldTests.WindowsOnly"),
("win32", "Example.OldTests.UnixOnly")):
with self.subTest(platform=platform):
directory = self.run_gate(platform=platform)
report = json.loads((directory / "run.json").read_text())["projects"][0]
discovery = json.loads(next(directory.rglob("discovery.json")).read_text())
self.assertEqual(report["platform"], platform)
self.assertEqual(report["platform_exclusions"], [excluded])
self.assertEqual(discovery["platform_exclusions"], [excluded])
self.assertIn("FullyQualifiedName!=" + excluded, report["execution_filter"])
self.assertNotIn("FullyQualifiedName!=", report["filter"])
def test_missing_platform_exclusion_fails_before_execution(self):
self.manifest["P00"][0]["platform_exclusions"] = {"non_windows": ["Example.OldTests.Missing"]}
with self.assertRaisesRegex(runner.GateError, "missing.*exclu"):
self.run_gate(platform="darwin")
self.assertFalse(any(a[0] == "dotnet" and "--list-tests" not in a for a, _ in self.calls))
def test_exclusions_cannot_mask_a_required_class(self):
self.manifest["P00"][0]["platform_exclusions"] = {"non_windows": ["Example.OldTests.Works"]}
with self.assertRaisesRegex(runner.GateError, "OldTests"):
self.run_gate(platform="darwin")
def test_case_excludes_only_methods_in_selected_class(self):
self.manifest["P00"][0]["platform_exclusions"] = {"non_windows": ["Example.OldTests.WindowsOnly"]}
self.listing = "The following Tests are available:\n Example.NewTests.Works\n"
self.run_gate(case="NewTests", platform="darwin")
def test_excluded_method_in_results_is_rejected(self):
self.manifest["P00"][0]["platform_exclusions"] = {"non_windows": ["Example.OldTests.WindowsOnly"]}
self.listing += " Example.OldTests.WindowsOnly\n"
original = self.fake
def unexpected(argv, **kwargs):
result = original(argv, **kwargs)
if argv[0] == "dotnet" and "--list-tests" not in argv:
path = Path(argv[argv.index("--results-directory") + 1]) / "results.trx"
path.write_text(path.read_text().replace('className="Example.OldTests" name="Works"',
'className="Example.OldTests" name="WindowsOnly"'))
return result
with self.assertRaisesRegex(runner.GateError, "excluded.*result"):
runner.run_phase(self.manifest, "P00", self.root, invoke=unexpected, platform="darwin")
def test_invalid_exclusion_is_rejected(self):
self.manifest["P00"][0]["platform_exclusions"] = {"non_windows": ["Example.OldTests.Works|FullyQualifiedName~Other"]}
with self.assertRaisesRegex(runner.GateError, "invalid.*exclu"):
self.run_gate(platform="darwin")
def test_allowlist_removes_inherited_secrets_and_overrides_shared_sql(self):
env = runner.unit_environment({"PATH": "/bin", "HOME": "/home/test",
"OTOPCUA_CONFIG_TEST_SERVER": "shared-db", "OTOPCUA_CONFIG_CONNECTION": "secret",
+73 -3
View File
@@ -127,7 +127,7 @@
"P04": [
{
"project": "tests/Server/ZB.MOM.WW.OtOpcUa.Runtime.Tests/ZB.MOM.WW.OtOpcUa.Runtime.Tests.csproj",
"filter": "(Feature=GrpcData&Phase=P04)|FullyQualifiedName~.DriverInstanceActorBatchForwardTests.|FullyQualifiedName~.DriverHostActorBatchFanOutTests.|FullyQualifiedName~.DriverHostActorSourceRemovedTests.|FullyQualifiedName~.DriverHostActorCommsLossTests.|FullyQualifiedName~.OpcUaPublishActorBatchTests.|FullyQualifiedName~.OpcUaPublishActorStatusBatchTests.",
"filter": "(Feature=GrpcData&Phase=P04)|FullyQualifiedName~.DriverInstanceActorBatchForwardTests.|FullyQualifiedName~.DriverHostActorBatchFanOutTests.|FullyQualifiedName~.DriverHostActorSourceRemovedTests.|FullyQualifiedName~.DriverHostActorCommsLossTests.|FullyQualifiedName~.OpcUaPublishActorBatchTests.|FullyQualifiedName~.OpcUaPublishActorStatusBatchTests.|FullyQualifiedName~.VirtualTagActorTests.|FullyQualifiedName~.VirtualTagHostActorTests.|FullyQualifiedName~.DependencyMuxTagUpstreamSourceTests.|FullyQualifiedName~.DriverHostActorRestartTests.|FullyQualifiedName~.DriverHostActorReprovisionStampTests.",
"new_classes": [
"GrpcDataSampleOwnershipTests",
"GrpcDataSourceFeedParityTests",
@@ -136,7 +136,8 @@
"GrpcDataIngressOverflowTests",
"GrpcDataLocalConnectionTests",
"GrpcDataCachedReadTests",
"GrpcDataLocalExportCatalogTests"
"GrpcDataLocalExportCatalogTests",
"GrpcDataCatalogStagingTests"
],
"existing_classes": [
"DriverInstanceActorBatchForwardTests",
@@ -144,7 +145,76 @@
"DriverHostActorSourceRemovedTests",
"DriverHostActorCommsLossTests",
"OpcUaPublishActorBatchTests",
"OpcUaPublishActorStatusBatchTests"
"OpcUaPublishActorStatusBatchTests",
"VirtualTagActorTests",
"VirtualTagHostActorTests",
"DependencyMuxTagUpstreamSourceTests",
"DriverHostActorRestartTests",
"DriverHostActorReprovisionStampTests"
]
},
{
"project": "tests/Core/ZB.MOM.WW.OtOpcUa.Core.Abstractions.Tests/ZB.MOM.WW.OtOpcUa.Core.Abstractions.Tests.csproj",
"filter": "FullyQualifiedName~.GrpcDataContractsTests.|FullyQualifiedName~.DataChangeBatchContractTests.",
"new_classes": [],
"existing_classes": [
"GrpcDataContractsTests",
"DataChangeBatchContractTests"
]
},
{
"project": "tests/Core/ZB.MOM.WW.OtOpcUa.Commons.Tests/ZB.MOM.WW.OtOpcUa.Commons.Tests.csproj",
"filter": "FullyQualifiedName~.GrpcDataCodecTests.",
"new_classes": [],
"existing_classes": [
"GrpcDataCodecTests"
]
},
{
"project": "tests/Server/ZB.MOM.WW.OtOpcUa.OpcUaServer.Tests/ZB.MOM.WW.OtOpcUa.OpcUaServer.Tests.csproj",
"filter": "FullyQualifiedName~.NodeManagerHistoryReadPagingTests.|FullyQualifiedName~.NodeManagerHistoryReadModifiedTests.|FullyQualifiedName~.DataPlaneAuthorizerTests.",
"new_classes": [],
"existing_classes": [
"NodeManagerHistoryReadPagingTests",
"NodeManagerHistoryReadModifiedTests",
"DataPlaneAuthorizerTests"
]
},
{
"project": "tests/Server/ZB.MOM.WW.OtOpcUa.ScriptWorker.Tests/ZB.MOM.WW.OtOpcUa.ScriptWorker.Tests.csproj",
"filter": "FullyQualifiedName~.ProtocolTests.|FullyQualifiedName~.WorkerIsolationTests.|FullyQualifiedName~.WorkerSoftClockTests.",
"platform_exclusions": {
"non_windows": [
"ZB.MOM.WW.OtOpcUa.ScriptWorker.Tests.WorkerIsolationTests.The_pipe_acl_is_protected_and_admits_exactly_the_host_and_the_worker_identity",
"ZB.MOM.WW.OtOpcUa.ScriptWorker.Tests.WorkerIsolationTests.A_live_pipe_carries_the_acl_and_a_host_only_pipe_admits_the_host_alone",
"ZB.MOM.WW.OtOpcUa.ScriptWorker.Tests.WorkerIsolationTests.The_worker_token_is_restricted_privilege_free_and_reaches_only_what_its_identity_may",
"ZB.MOM.WW.OtOpcUa.ScriptWorker.Tests.WorkerIsolationTests.A_worker_under_the_identity_runs_scripts_with_a_restricted_token_and_a_plain_one_does_not"
],
"windows": [
"ZB.MOM.WW.OtOpcUa.ScriptWorker.Tests.WorkerIsolationTests.A_runner_configured_with_an_identity_off_windows_refuses_to_start_rather_than_fall_back"
]
},
"new_classes": [],
"existing_classes": [
"ProtocolTests",
"WorkerIsolationTests",
"WorkerSoftClockTests"
]
},
{
"project": "tests/Drivers/ZB.MOM.WW.OtOpcUa.Driver.MTConnect.Tests/ZB.MOM.WW.OtOpcUa.Driver.MTConnect.Tests.csproj",
"filter": "FullyQualifiedName~.MTConnectObservationIndexTests.",
"new_classes": [],
"existing_classes": [
"MTConnectObservationIndexTests"
]
},
{
"project": "tests/Drivers/ZB.MOM.WW.OtOpcUa.Driver.OpcUaClient.Tests/ZB.MOM.WW.OtOpcUa.Driver.OpcUaClient.Tests.csproj",
"filter": "FullyQualifiedName~.OpcUaClientSdkValueBoundaryTests.",
"new_classes": [],
"existing_classes": [
"OpcUaClientSdkValueBoundaryTests"
]
}
],