Install authenticated native web proxy with user autostart
Register the existing native supervisor with launchd/systemd, include the dependency-free authenticated web proxy, detect Node, and keep the API loopback by default. Preserve existing web credentials and configured host harness defaults. Clarify single-step setup, lifecycle selection, and optional ntfy limits. Checks: 44 mocked native installer/lifecycle tests; 8 entrypoint tests; 42 Docker installer tests; GOPROXY=off GOTOOLCHAIN=local go test ./internal/installation ./cmd/pipelines; sh -n install install.sh; git diff --check. No live install, deployment, restart, downloads, real autostart/login verification or native Linux verification.
This commit is contained in:
@@ -2,6 +2,7 @@ import importlib.util
|
||||
import io
|
||||
import json
|
||||
import os
|
||||
import plistlib
|
||||
from contextlib import redirect_stdout
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
@@ -56,6 +57,8 @@ class Recorder:
|
||||
self.calls.append(command)
|
||||
self.kwargs.append(kwargs)
|
||||
stdout, code = "", 0
|
||||
if command[0].endswith("node") and command[1:] == ["--version"]:
|
||||
stdout = "v22.19.0\n"
|
||||
if command[0] == "docker":
|
||||
if command[1:3] == ["volume", "ls"]:
|
||||
if self.fail_volume_ls:
|
||||
@@ -92,6 +95,14 @@ class Recorder:
|
||||
|
||||
|
||||
class SetupNativeTests(unittest.TestCase):
|
||||
def setUp(self):
|
||||
# All LaunchAgent files, including full-run tests, stay in scratch HOME.
|
||||
self.home = tempfile.TemporaryDirectory()
|
||||
self.addCleanup(self.home.cleanup)
|
||||
home = patch.object(setup_native.Path, "home", return_value=Path(self.home.name))
|
||||
home.start()
|
||||
self.addCleanup(home.stop)
|
||||
|
||||
def installer(self, directory, recorder):
|
||||
# A disposable XDG config home keeps the client default out of the real
|
||||
# user configuration during tests.
|
||||
@@ -102,7 +113,8 @@ class SetupNativeTests(unittest.TestCase):
|
||||
@staticmethod
|
||||
def which_all(opencode="/usr/bin/opencode", pi=None, cc="/usr/bin/cc"):
|
||||
mapping = {"go": "/usr/bin/go", "python3": "/usr/bin/python3",
|
||||
"git": "/usr/bin/git", "curl": "/usr/bin/curl"}
|
||||
"git": "/usr/bin/git", "curl": "/usr/bin/curl", "node": "/usr/bin/node",
|
||||
"launchctl": "/bin/launchctl", "systemctl": "/usr/bin/systemctl"}
|
||||
if opencode:
|
||||
mapping["opencode"] = opencode
|
||||
if pi:
|
||||
@@ -122,9 +134,91 @@ class SetupNativeTests(unittest.TestCase):
|
||||
message = str(raised.exception)
|
||||
self.assertIn("git", message)
|
||||
self.assertIn("curl", message)
|
||||
self.assertIn("node", message)
|
||||
self.assertIn("never installs tools", message)
|
||||
self.assertEqual(recorder.calls, [])
|
||||
|
||||
def test_registration_uses_native_supervisor_on_both_platforms(self):
|
||||
for system in ("Darwin", "Linux"):
|
||||
with self.subTest(system=system), tempfile.TemporaryDirectory() as directory:
|
||||
installer = self.installer(directory, Recorder())
|
||||
prefix = Path(directory) / "prefix with spaces"
|
||||
manifest = {"prefix": str(prefix), "python": "/usr/bin/python3", "path": "/bin"}
|
||||
with patch.object(setup_native.platform, "system", return_value=system), \
|
||||
patch.object(setup_native.shutil, "which", side_effect=self.which_all()):
|
||||
path = installer.service_path()
|
||||
installer.register_service(path, manifest)
|
||||
self.assertEqual(manifest["registration"], str(path))
|
||||
self.assertEqual(path.stat().st_mode & 0o777, 0o600)
|
||||
if system == "Darwin":
|
||||
data = plistlib.loads(path.read_bytes())
|
||||
self.assertEqual(data["ProgramArguments"], ["/usr/bin/python3", str(prefix / "lib/manage.py"),
|
||||
"supervise", "--prefix", str(prefix)])
|
||||
self.assertTrue(data["RunAtLoad"])
|
||||
else:
|
||||
text = path.read_text()
|
||||
self.assertIn('"supervise" "--prefix"', text)
|
||||
self.assertIn('"' + str(prefix) + '"', text)
|
||||
self.assertIn("WantedBy=default.target", text)
|
||||
|
||||
def test_unmanaged_service_is_never_replaced(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
installer = self.installer(directory, Recorder())
|
||||
with patch.object(setup_native.platform, "system", return_value="Linux"), \
|
||||
patch.object(setup_native.shutil, "which", side_effect=self.which_all()):
|
||||
path = installer.service_path()
|
||||
path.parent.mkdir(parents=True)
|
||||
path.write_text("operator service")
|
||||
with self.assertRaisesRegex(ValueError, "unmanaged"):
|
||||
installer.service_path()
|
||||
self.assertEqual(path.read_text(), "operator service")
|
||||
|
||||
def test_missing_service_manager_fails_before_build_or_config(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
installer = self.installer(directory, Recorder())
|
||||
with patch.object(setup_native.platform, "system", return_value="Linux"), \
|
||||
patch.object(setup_native.shutil, "which", return_value=None):
|
||||
with self.assertRaisesRegex(ValueError, "systemctl is required"):
|
||||
installer.service_path()
|
||||
self.assertFalse((Path(directory) / "prefix").exists())
|
||||
|
||||
def test_web_install_copies_assets_and_preserves_credentials(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
installer = self.installer(directory, Recorder())
|
||||
prefix = Path(directory) / "prefix"
|
||||
installer.prepare_layout(prefix)
|
||||
with patch.object(setup_native.shutil, "which", side_effect=self.which_all()):
|
||||
web = installer.configure_web(prefix, setup_native.arguments([]))
|
||||
auth = Path(web["auth_file"])
|
||||
before = auth.read_bytes()
|
||||
installer.configure_web(prefix, setup_native.arguments([]))
|
||||
self.assertEqual(auth.read_bytes(), before)
|
||||
self.assertEqual(auth.stat().st_mode & 0o777, 0o600)
|
||||
self.assertGreaterEqual(len(json.loads(before)["password"]), 8)
|
||||
self.assertTrue(Path(web["script"]).is_file())
|
||||
self.assertTrue((prefix / "lib/web/src/proxySecurity.js").is_file())
|
||||
self.assertEqual(web["port"], 8082)
|
||||
|
||||
def test_invalid_web_auth_is_retained(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
installer = self.installer(directory, Recorder())
|
||||
auth = Path(directory) / "auth.json"
|
||||
auth.write_text('{"password":"short"}')
|
||||
installer.environ["PIPELINES_WEB_AUTH_FILE"] = str(auth)
|
||||
with patch.object(setup_native.shutil, "which", side_effect=self.which_all()):
|
||||
with self.assertRaisesRegex(ValueError, "Invalid existing web auth"):
|
||||
installer.configure_web(Path(directory) / "prefix", setup_native.arguments([]))
|
||||
self.assertEqual(auth.read_text(), '{"password":"short"}')
|
||||
|
||||
def test_old_node_is_rejected(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
def old_node(command, **kwargs):
|
||||
return subprocess.CompletedProcess(command, 0, stdout="v16.0.0\n")
|
||||
installer = self.installer(directory, old_node)
|
||||
with patch.object(setup_native.shutil, "which", side_effect=self.which_all()):
|
||||
with self.assertRaisesRegex(ValueError, "Node.js 18"):
|
||||
installer.configure_web(Path(directory) / "prefix", setup_native.arguments([]))
|
||||
|
||||
def test_build_installs_only_server_and_cli_with_trimpath(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
recorder = Recorder()
|
||||
@@ -176,11 +270,13 @@ class SetupNativeTests(unittest.TestCase):
|
||||
self.assertEqual(config["format"], 1)
|
||||
self.assertEqual(config["prefix"], str(prefix.resolve()))
|
||||
self.assertEqual(config["server_port"], 8080)
|
||||
self.assertEqual(config["bind_address"], "0.0.0.0")
|
||||
self.assertEqual(config["bind_address"], "127.0.0.1")
|
||||
self.assertEqual(config["ntfy"]["mode"], "native")
|
||||
self.assertEqual(config["topic"], "pipelines")
|
||||
self.assertEqual(config["opencode"], "/usr/bin/opencode")
|
||||
self.assertEqual(config["pi"], "")
|
||||
self.assertTrue(Path(config["registration"]).is_file())
|
||||
self.assertTrue(recorder.has("start", "--prefix", str(prefix.resolve())))
|
||||
self.assertEqual((prefix / setup_native.MARKER).stat().st_mode & 0o777, 0o600)
|
||||
token_path = prefix / "secrets/publisher-token"
|
||||
self.assertEqual(token_path.read_text(), TOKEN + "\n")
|
||||
@@ -412,6 +508,21 @@ class SetupNativeTests(unittest.TestCase):
|
||||
self.assertTrue(installer._valid_model(saved["profiles"][name]["model"]))
|
||||
self.assertEqual(saved["profiles"]["opencode"]["executable"], "/usr/bin/opencode")
|
||||
|
||||
def test_configure_harnesses_preserves_configured_host_default(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
installer = self.installer(directory, Recorder())
|
||||
path = installer.harness_config_path()
|
||||
path.parent.mkdir(parents=True)
|
||||
profiles = {name: {"model": "fixture/interactive", "pipeline_model": "fixture/stages"}
|
||||
for name in ("opencode", "pi")}
|
||||
profiles["pi"]["future"] = "preserve"
|
||||
path.write_text(json.dumps({"default": "pi", "profiles": profiles}))
|
||||
installer.configure_harnesses({"opencode": "/usr/bin/opencode", "pi": "/usr/bin/pi"})
|
||||
saved = json.loads(path.read_text())
|
||||
self.assertEqual(saved["default"], "pi")
|
||||
self.assertEqual(saved["profiles"]["pi"]["model"], "fixture/interactive")
|
||||
self.assertEqual(saved["profiles"]["pi"]["future"], "preserve")
|
||||
|
||||
def _fake_pipelines(self, path, version, commit):
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
path.write_text(f'#!/bin/sh\necho \'{{"version":"{version}","commit":"{commit}"}}\'\n')
|
||||
|
||||
Reference in New Issue
Block a user