From e1488243e11556beadc405fd885fb863a47a0106 Mon Sep 17 00:00:00 2001 From: Florian Schmidt Date: Sun, 15 Nov 2026 11:15:06 +0100 Subject: [PATCH] tools: install Codex into the worker executable path Use a global npm install within the service user's prefix so the configured .local/bin launcher exists. Exercise npm with an offline synthetic package and check the installed launcher without contacting a provider. Refs #19 --- docs/proxmox.md | 5 ++++ tools/proxmox/guest.py | 2 +- tools/proxmox/test_installer.py | 52 +++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 1 deletion(-) diff --git a/docs/proxmox.md b/docs/proxmox.md index 37a903d..df96746 100644 --- a/docs/proxmox.md +++ b/docs/proxmox.md @@ -232,6 +232,11 @@ of configuration/keys, partial setup, stopped services and activation rollback. a real Proxmox create/update, Linux build, certificate issuance or provider login. No Proxmox host/container was changed while developing this script. +One installer regression uses real Node.js/npm with an offline synthetic package to check the +configured Codex launcher and repeat installation. It skips explicitly when Node.js/npm are +unavailable. On Windows its fixture adapts npm's global-prefix layout to the guest's Linux `bin` +path; that checks npm install mode and actual files without claiming Linux execution. + Updater tests use real local Git repositories and Bash with a synthetic installer. They verify two-version fast-forward deployment, no-change retry, dirty/diverged/ahead/detached refusal, fetch failure, dry-run, exit status, ignored-state retention and ignored-file collisions. Advisory lock command results diff --git a/tools/proxmox/guest.py b/tools/proxmox/guest.py index c57e8fe..16481d8 100644 --- a/tools/proxmox/guest.py +++ b/tools/proxmox/guest.py @@ -121,7 +121,7 @@ def official_clis(providers): script.chmod(0o644) as_user("finaltoken", WORKER_HOME, ["bash", str(script), "stable"]) if "codex" in providers and not (WORKER_HOME / ".local/bin/codex").exists(): - as_user("finaltoken", WORKER_HOME, ["npm", "install", "--prefix", str(WORKER_HOME / ".local"), "@openai/codex@latest"]) + as_user("finaltoken", WORKER_HOME, ["npm", "install", "--global", "--prefix", str(WORKER_HOME / ".local"), "@openai/codex@latest"]) for provider in providers: as_user("finaltoken", WORKER_HOME, [str(WORKER_HOME / ".local/bin" / provider), "--version"]) diff --git a/tools/proxmox/test_installer.py b/tools/proxmox/test_installer.py index 25d0491..522d628 100644 --- a/tools/proxmox/test_installer.py +++ b/tools/proxmox/test_installer.py @@ -6,6 +6,7 @@ import io import json import os from pathlib import Path, PurePosixPath +import shutil import subprocess import sys import tarfile @@ -208,6 +209,57 @@ class HostTests(unittest.TestCase): class GuestTests(unittest.TestCase): + def test_codex_npm_install_creates_the_configured_launcher(self): + node, npm = shutil.which("node"), shutil.which("npm") + if not node or not npm: + self.skipTest("Offline npm launcher integration requires Node.js and npm") + npm_path = Path(npm).resolve() + npm_cli = npm_path if npm_path.suffix == ".js" else npm_path.parent / "node_modules/npm/bin/npm-cli.js" + self.assertTrue(npm_cli.is_file(), "Cannot locate the installed npm CLI") + with tempfile.TemporaryDirectory(prefix="finaltoken-npm-fixture-") as tmp: + root = Path(tmp) + package = root / "codex-fixture.tgz" + with tarfile.open(package, "w:gz") as archive: + files = {"package/package.json": json.dumps({"name": "@finaltoken/offline-codex-fixture", "version": "1.0.0", + "bin": {"codex": "cli.js"}}), "package/cli.js": "#!/usr/bin/env node\nconsole.log('synthetic codex fixture');\n"} + for name, value in files.items(): + content = value.encode("utf-8") + item = tarfile.TarInfo(name) + item.size, item.mode = len(content), 0o755 + archive.addfile(item, io.BytesIO(content)) + user_config, global_config = root / "user.npmrc", root / "global.npmrc" + user_config.write_text(""); global_config.write_text("") + env = {name: os.environ[name] for name in ("PATH", "SystemRoot", "TEMP", "TMP", "ComSpec", "PATHEXT") if name in os.environ} + env.update(NPM_CONFIG_USERCONFIG=str(user_config), NPM_CONFIG_GLOBALCONFIG=str(global_config)) + home = root / "worker" + home.mkdir() + versions = [] + def local_user(name, directory, command, **kwargs): + self.assertEqual("finaltoken", name) + self.assertEqual(home, directory) + if command[0] == "npm": + arguments = list(command[1:-1]) + prefix_index = arguments.index("--prefix") + 1 + prefix = Path(arguments[prefix_index]) + # npm puts global launchers directly in the prefix on Windows; + # adapt that platform boundary to exercise the guest's Linux bin path. + if os.name == "nt": + arguments[prefix_index] = str(prefix / "bin") + return subprocess.run([node, str(npm_cli), *arguments, str(package), "--offline", "--ignore-scripts", + "--no-audit", "--no-fund", "--cache", str(root / "cache")], env=env, cwd=root, + text=True, capture_output=True, check=True, timeout=30) + launcher = home / ".local/bin/codex" + self.assertEqual([str(launcher), "--version"], command) + self.assertTrue(launcher.is_file(), "npm did not install the configured Codex launcher") + installed = home / (".local/bin/node_modules" if os.name == "nt" else ".local/lib/node_modules") + result = subprocess.run([node, str(installed / "@finaltoken/offline-codex-fixture/cli.js"), "--version"], + env=env, cwd=root, text=True, capture_output=True, check=True, timeout=10) + versions.append(result.stdout.strip()) + with patch.object(guest, "WORKER_HOME", home), patch.object(guest, "as_user", side_effect=local_user): + guest.official_clis(["codex"]) + guest.official_clis(["codex"]) # Existing launcher is used on subsequent runs. + self.assertEqual(["synthetic codex fixture"] * 2, versions) + def test_server_update_uses_persisted_identity_and_preserves_config_and_history(self): with tempfile.TemporaryDirectory() as tmp: root = Path(tmp)