diff --git a/infra/ci/qualify.py b/infra/ci/qualify.py index bf3ba9d..c658ab7 100644 --- a/infra/ci/qualify.py +++ b/infra/ci/qualify.py @@ -7,8 +7,10 @@ import json import os from pathlib import Path import re +import shutil import subprocess import sys +import tempfile import time @@ -30,9 +32,11 @@ def run(args, cwd, capture=False, capture_errors=False): ).stdout -def install_dependencies(cwd): +def install_dependencies(cwd, *, production=False): """Retry only explicit transport failures in a disposable npm ci checkout.""" command = ["npm", "ci", "--ignore-scripts", "--no-audit", "--no-fund"] + if production: + command.append("--omit=dev") transient = {"ECONNRESET", "ETIMEDOUT", "EAI_AGAIN"} for attempt in range(1, 4): try: @@ -51,6 +55,17 @@ def install_dependencies(cwd): return +def qualify_core_runtime(root): + """Exercise the standalone lock used by Docker, outside npm workspaces.""" + with tempfile.TemporaryDirectory(prefix="device-core-runtime-") as temporary: + target = Path(temporary) + for name in ("package.json", "package-lock.json"): + shutil.copyfile(root / "services/device-control-core" / name, target / name) + install_dependencies(target, production=True) + run(["node", "--input-type=module", "-e", + "await import('oauth4webapi'); await import('pg');"], target) + + def read_lock(root): lock = json.loads((root / "infra/ci/sources.lock.json").read_text()) if lock.get("schema") != "nodedc.device-core.ci-sources.v1": @@ -151,6 +166,9 @@ def qualify(root, commit, lock, report): print("ci_step=" + name, flush=True) if name in ("design-install", "device-install"): install_dependencies(cwd) + if name == "device-install": + print("ci_dependency_check=core-standalone-runtime", flush=True) + qualify_core_runtime(root) else: run(command, cwd) completed.append(name) diff --git a/infra/ci/test_qualify.py b/infra/ci/test_qualify.py index 1cc6f36..0d858e6 100644 --- a/infra/ci/test_qualify.py +++ b/infra/ci/test_qualify.py @@ -119,6 +119,38 @@ class QualificationTests(unittest.TestCase): self.assertEqual(execute.call_args.args[0], ["npm", "ci", "--ignore-scripts", "--no-audit", "--no-fund"]) pause.assert_called_once_with(5) + def test_core_runtime_uses_its_own_lock_outside_the_workspace(self): + source = self.root / "services/device-control-core" + source.mkdir(parents=True) + for name, value in (("package.json", '{"name":"core"}'), + ("package-lock.json", '{"name":"standalone-lock"}')): + (source / name).write_text(value) + (self.root / "package-lock.json").write_text('{"name":"workspace-lock"}') + temporary_paths = [] + def inspect_install(path, *, production): + self.assertTrue(production) + self.assertFalse(path.is_relative_to(self.root)) + self.assertEqual((path / "package-lock.json").read_text(), '{"name":"standalone-lock"}') + self.assertEqual(sorted(p.name for p in path.iterdir()), ["package-lock.json", "package.json"]) + temporary_paths.append(path) + with mock.patch.object(CI, "install_dependencies", side_effect=inspect_install), \ + mock.patch.object(CI, "run") as execute: + CI.qualify_core_runtime(self.root) + self.assertIn("await import('oauth4webapi')", execute.call_args.args[0][-1]) + self.assertFalse(temporary_paths[0].exists()) + + def test_core_runtime_lock_failure_stops_before_imports(self): + source = self.root / "services/device-control-core" + source.mkdir(parents=True) + for name in ("package.json", "package-lock.json"): + (source / name).write_text('{}') + failure = subprocess.CalledProcessError(1, "npm", output="npm error code EUSAGE\n") + with mock.patch.object(CI, "install_dependencies", side_effect=failure), \ + mock.patch.object(CI, "run") as execute: + with self.assertRaises(subprocess.CalledProcessError): + CI.qualify_core_runtime(self.root) + execute.assert_not_called() + def test_permanent_mixed_and_unclassified_install_failures_never_retry(self): for output in ("npm error code EINTEGRITY\n", "npm error code E401\n", "npm error code EUSAGE\n", "download ECONNRESET in explanatory text\n", diff --git a/services/device-control-core/package-lock.json b/services/device-control-core/package-lock.json index 565b6a7..a1c9fb5 100644 --- a/services/device-control-core/package-lock.json +++ b/services/device-control-core/package-lock.json @@ -8,12 +8,22 @@ "name": "@nodedc/device-control-core", "version": "0.1.0", "dependencies": { + "oauth4webapi": "3.8.8", "pg": "8.22.0" }, "engines": { "node": ">=20" } }, + "node_modules/oauth4webapi": { + "version": "3.8.8", + "resolved": "https://registry.npmjs.org/oauth4webapi/-/oauth4webapi-3.8.8.tgz", + "integrity": "sha512-8N28E+a/oxfXWBgOMt+ZP/JUf/XR+IFbvkAEPP3gznXOMv9BpAAwiIj0TFNz3tGTPc0ZQ8zmWBNgN1nAys0gng==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/panva" + } + }, "node_modules/pg": { "version": "8.22.0", "resolved": "https://registry.npmjs.org/pg/-/pg-8.22.0.tgz",