From 298debd1b933f13671d489224656b122b524b85e Mon Sep 17 00:00:00 2001 From: DCCONSTRUCTIONS Date: Tue, 29 Sep 2026 19:28:07 +0300 Subject: [PATCH] Test release installer against real Core and Manager health handlers --- infra/ci/sources.lock.json | 2 +- .../deploy-runner/health-contract-servers.mjs | 39 +++++++++ .../test_device_release_health_contract.py | 81 +++++++++++++++++++ 3 files changed, 121 insertions(+), 1 deletion(-) create mode 100644 infra/deploy-runner/health-contract-servers.mjs create mode 100644 infra/deploy-runner/test_device_release_health_contract.py diff --git a/infra/ci/sources.lock.json b/infra/ci/sources.lock.json index 2542292..e2acd00 100644 --- a/infra/ci/sources.lock.json +++ b/infra/ci/sources.lock.json @@ -13,7 +13,7 @@ }, "platform": { "url": "https://git.dcserve.ru/SILVER/NODEDC_PLATFORM.git", - "commit": "11b73e64681f83aa2ebfd89ef266d3be2869f7e1" + "commit": "ed500278a04affa93228b14d97a6c6b6c1f82a07" } } } diff --git a/infra/deploy-runner/health-contract-servers.mjs b/infra/deploy-runner/health-contract-servers.mjs new file mode 100644 index 0000000..ad93342 --- /dev/null +++ b/infra/deploy-runner/health-contract-servers.mjs @@ -0,0 +1,39 @@ +// Real application handlers; only external dependencies are replaced in this fixture. +import { createControlCoreApp } from "../../services/device-control-core/src/app.mjs"; +import { createDeviceManagerServer } from "../../apps/device-manager/server/device-manager-server.mjs"; + +const servers = []; +const urls = {}; +for (const mode of ["healthy", "database", "discovery", "management", "transport", "auth", "coreClient"]) { + const core = createControlCoreApp({ + repository: { + health: async () => mode === "database" ? "unavailable" : "ready", + upsertQuarantineDiscovery() {}, acceptAdapterMessage() {}, executeManagementCommand() {}, + }, + gatewayToken: "fixture-only-".repeat(4), identifierPepper: "fixture-only-".repeat(4), + managementToken: "fixture-only-".repeat(4), + discoveryIngestEnabled: mode !== "discovery", managementApiEnabled: mode !== "management", + gatewayIngest: { observeDiscovery() {}, acceptMessage() {} }, + typedCommandRuntime: mode === "transport" ? null : { planServicePing() {}, status() {} }, + edgeChannelStatusProvider: () => ({ enabled: true, configured: 1, accepted: 1, degraded: 0 }), + }); + const manager = createDeviceManagerServer({ + auth: { authRequired: mode !== "auth", authorize() {} }, + coreClient: { configured: mode !== "coreClient", listProjects() {} }, + presentationStore: {}, + }); + urls[mode] = []; + for (const server of [core, manager]) { + await new Promise((resolve, reject) => { + server.once("error", reject); + server.listen(0, "127.0.0.1", resolve); + }); + servers.push(server); + urls[mode].push(`http://127.0.0.1:${server.address().port}/healthz`); + } +} +process.stdout.write(JSON.stringify(urls) + "\n"); +process.stdin.resume(); +process.stdin.on("end", async () => { + await Promise.all(servers.map(server => new Promise(resolve => server.close(resolve)))); +}); diff --git a/infra/deploy-runner/test_device_release_health_contract.py b/infra/deploy-runner/test_device_release_health_contract.py new file mode 100644 index 0000000..dff45ef --- /dev/null +++ b/infra/deploy-runner/test_device_release_health_contract.py @@ -0,0 +1,81 @@ +"""Exercise the pinned production installer against real Core/Manager HTTP handlers.""" +import importlib.machinery +import importlib.util +import json +import os +from pathlib import Path +import select +import subprocess +import unittest +import urllib.request +from unittest import mock + +HERE = Path(__file__).resolve().parent +RUNNER_PATH = Path(os.environ.get("NODEDC_DEPLOY_RUNNER", HERE.parents[2] / "platform/infra/deploy-runner/nodedc-deploy")) +loader = importlib.machinery.SourceFileLoader("release_health_runner", str(RUNNER_PATH)) +spec = importlib.util.spec_from_loader(loader.name, loader) +R = importlib.util.module_from_spec(spec) +loader.exec_module(R) + + +class ActualApplicationHealthContractTests(unittest.TestCase): + @classmethod + def setUpClass(cls): + cls.process = subprocess.Popen( + ["node", str(HERE / "health-contract-servers.mjs")], + stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, + ) + cls.addClassCleanup(cls.stop_servers) + if not select.select([cls.process.stdout], [], [], 15)[0]: + raise AssertionError("health fixture did not listen within 15 seconds") + line = cls.process.stdout.readline() + if not line: + raise AssertionError("health fixture failed: " + cls.process.stderr.read()) + cls.urls = json.loads(line) + + @classmethod + def stop_servers(cls): + cls.process.stdin.close() + try: + cls.process.wait(timeout=5) + except subprocess.TimeoutExpired: + cls.process.kill() + cls.process.wait(timeout=5) + cls.process.stdout.close() + cls.process.stderr.close() + + def check_actual_handlers(self, mode): + health = R.healthcheck_url + calls = [] + def local_check(check): + index = 0 if check["url"].endswith(":18120/healthz") else 1 + calls.append(index) + return health({**check, "url": self.urls[mode][index]}) + with mock.patch.object(R, "healthcheck_compose_service_with_grace"), \ + mock.patch.object(R, "healthcheck_url", side_effect=local_check), \ + mock.patch.object(R.time, "sleep"), \ + mock.patch.object(R, "NO_REDIRECT_OPENER", urllib.request.build_opener(urllib.request.ProxyHandler({}))): + # Real release selection and real HTTP contract comparison, not a copied expectation. + R.run_healthchecks("device-core-release", R.DEVICE_RELEASE_ENTRIES, R.DEVICE_RELEASE_SERVICES) + return calls + + def test_enabled_production_foundation_passes_actual_installer(self): + self.assertEqual(self.check_actual_handlers("healthy"), [0, 1]) + + def test_unavailable_database_fails(self): + with self.assertRaisesRegex(R.DeployError, "contract mismatch"): + self.check_actual_handlers("database") + + def test_disabled_required_core_capabilities_fail(self): + for mode in ["discovery", "management", "transport"]: + with self.subTest(mode=mode), self.assertRaisesRegex(R.DeployError, "contract mismatch"): + self.check_actual_handlers(mode) + + def test_manager_without_auth_or_core_fails(self): + for mode in ["auth", "coreClient"]: + with self.subTest(mode=mode), self.assertRaisesRegex(R.DeployError, "contract mismatch"): + self.check_actual_handlers(mode) + + +if __name__ == "__main__": + unittest.main()