Files
pipelines/scripts/test_setup_native.py
T
alan c810437aa5 Claude Code chats survive server restarts in a detachable host
A pipelines-claude-host process owns each claude -p CLI and its pipes,
spools its stream-json output with offsets and serves a private Unix
socket. The server detaches on shutdown and reattaches on start,
replaying the spool to rebuild turns, approvals, questions, background
tasks and the live model. Explicit close, idle release and CLI exit stop
the host; a crashed host falls back to --resume with a notice.
2026-11-04 16:09:56 +00:00

995 lines
58 KiB
Python

import importlib.util
import io
import json
import os
import plistlib
from contextlib import redirect_stdout
from pathlib import Path
import subprocess
import tempfile
import unittest
from unittest.mock import patch
spec = importlib.util.spec_from_file_location("setup_native", Path(__file__).with_name("setup-native.py"))
setup_native = importlib.util.module_from_spec(spec)
spec.loader.exec_module(setup_native)
manage_spec = importlib.util.spec_from_file_location("pipelines_manage", Path(__file__).with_name("manage.py"))
manage = importlib.util.module_from_spec(manage_spec)
manage_spec.loader.exec_module(manage)
TOKEN = "tk_" + "a" * 29
NTFY_VERSION = "2.11.0"
NTFY_MODULE = "heckel.io/ntfy/v2"
def resolution():
"""The shape resolve_ntfy returns: an exact tag to build the server from."""
return {"repository": "binwiederhier/ntfy", "module": NTFY_MODULE,
"version": NTFY_VERSION, "tag": "v" + NTFY_VERSION}
class _Served:
def poll(self):
return None
def terminate(self):
pass
def wait(self, timeout=None):
return 0
def fake_ntfy_serve(command, **kwargs):
"""`ntfy serve` creates its account database next to its configuration."""
config = Path(command[command.index("--config") + 1])
(config.parent / "auth.db").write_bytes(b"")
return _Served()
class Recorder:
def __init__(self, token=TOKEN, volumes=(), image="pipelines-pipelines:latest",
fail_create=False, fail_copy=False, fail_volume_ls=False, fail_build=False, fail_web=False,
host_model="fixture/host-default"):
self.calls = []
self.token = token
self.volumes = volumes
self.image = image
self.fail_create = fail_create
self.fail_copy = fail_copy
self.fail_volume_ls = fail_volume_ls
self.fail_build = fail_build
self.fail_web = fail_web
self.host_model = host_model
self._module_cache = None
self.kwargs = []
def module_cache(self):
"""A stand-in Go module cache holding the pinned ntfy module source."""
if self._module_cache is None:
self._module_cache = tempfile.mkdtemp(prefix="gomodcache-")
source = Path(self._module_cache) / f"{NTFY_MODULE}@{resolution()['tag']}"
source.mkdir(parents=True)
(source / "go.mod").write_text(f"module {NTFY_MODULE}\n")
return self._module_cache
def __call__(self, command, **kwargs):
command = list(command)
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].endswith("opencode") and command[1:] == ["api", "get", "/api/model/default"]:
model = None
if self.host_model:
provider, name = self.host_model.split("/", 1)
model = {"providerID": provider, "modelID": name, "enabled": True, "status": "active"}
stdout = json.dumps({"location": {"directory": "/scratch/home"}, "data": model})
if command[0] == "docker":
if command[1:3] == ["volume", "ls"]:
if self.fail_volume_ls:
code = 1
else:
stdout = "\n".join(self.volumes)
elif command[1:3] == ["image", "ls"]:
stdout = self.image + "\n" if self.image else ""
elif command[1] == "create" and self.fail_create:
code = 1
elif command[1] == "run" and "pipelines-app-build" in command:
# The fake app build writes its output to the /out mount.
out = next(v for v in command if v.endswith(":/out")).rsplit(":", 1)[0]
if not self.fail_web:
(Path(out) / "index.html").write_text("app")
elif command[1] == "cp":
if self.fail_copy:
code = 1
else:
Path(command[3]).write_bytes(b"migrated")
elif command[0] == "go" and command[1:3] == ["env", "GOMODCACHE"]:
stdout = self.module_cache() + "\n"
elif command[0] == "go" and command[1:2] == ["build"]:
if self.fail_build:
code = 1
elif "-o" in command:
# Every build output is created so the atomic installs have real
# files to move.
output = Path(command[command.index("-o") + 1])
output.write_bytes(b"#!/bin/sh\n")
output.chmod(0o755)
if command[0].endswith("ntfy") and "token" in command:
stdout = f"token {self.token} created for pipeline-publisher\n"
return subprocess.CompletedProcess(command, code, stdout=stdout, stderr="")
def has(self, *parts):
return any(all(part in call for part in parts) for call in self.calls)
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.
return setup_native.Setup(directory, prefix=Path(directory) / "prefix", runner=recorder,
resolver=resolution, popen=fake_ntfy_serve,
environ={"XDG_CONFIG_HOME": str(Path(directory) / "config"),
"PIPELINES_WEB_PASSWORD": "chosen-password"})
@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", "node": "/usr/bin/node",
"launchctl": "/bin/launchctl", "systemctl": "/usr/bin/systemctl"}
if opencode:
mapping["opencode"] = opencode
if pi:
mapping["pi"] = pi
if cc:
mapping["cc"] = cc
return lambda name: mapping.get(name)
def test_reinstall_preserves_network_settings_and_explicit_flags_override(self):
with tempfile.TemporaryDirectory() as directory:
installer = self.installer(directory, Recorder())
prefix = installer.resolve_prefix()
prefix.mkdir()
manifest = {"server_port": 8090, "ntfy_port": 8091,
"bind_address": "127.0.0.2",
"web": {"port": 8096, "host": "127.0.0.1"}}
(prefix / setup_native.MARKER).write_text(json.dumps(manifest))
args = setup_native.arguments([])
installer.preserve_network_settings(prefix, args)
self.assertEqual((args.port, args.ntfy_port, args.web_port), (8090, 8091, 8096))
self.assertEqual((args.bind_address, args.web_host), ("127.0.0.2", "127.0.0.1"))
args = setup_native.arguments(["--web-port=8082", "--port", "8080"])
installer.preserve_network_settings(prefix, args)
self.assertEqual((args.port, args.ntfy_port, args.web_port), (8080, 8091, 8082))
(prefix / setup_native.MARKER).unlink()
args = setup_native.arguments([])
installer.preserve_network_settings(prefix, args)
self.assertEqual(args.web_port, 8082)
def test_require_tools_reports_each_missing_tool_without_installing(self):
with tempfile.TemporaryDirectory() as directory:
recorder = Recorder()
installer = self.installer(directory, recorder)
mapping = {"go": "/usr/bin/go", "python3": "/usr/bin/python3", "git": None, "curl": None}
with patch.object(setup_native.shutil, "which", side_effect=lambda name: mapping.get(name)):
with self.assertRaises(ValueError) as raised:
installer.require_tools()
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.assertEqual(json.loads(before)["password"], "chosen-password")
self.assertTrue(Path(web["script"]).is_file())
# The web app is built in Docker once and installed for the proxy.
self.assertTrue(installer.runner.has("docker", "run", "pipelines-app-build", "web"))
self.assertEqual(web["root"], str(prefix / "lib/app-web"))
self.assertTrue(Path(web["root"]).is_dir())
self.assertTrue(Path(web["updates"]).is_dir())
self.assertTrue((prefix / "lib/web/src/proxySecurity.js").is_file())
self.assertEqual(web["port"], 8082)
def test_new_web_password_must_be_chosen(self):
with tempfile.TemporaryDirectory() as directory:
installer = self.installer(directory, Recorder())
prefix = Path(directory) / "prefix"
installer.prepare_layout(prefix)
installer.environ.pop("PIPELINES_WEB_PASSWORD")
with patch.object(setup_native.shutil, "which", side_effect=self.which_all()), \
patch.object(setup_native.sys.stdin, "isatty", return_value=False):
with self.assertRaisesRegex(ValueError, "PIPELINES_WEB_PASSWORD"):
installer.configure_web(prefix, setup_native.arguments([]))
installer.environ["PIPELINES_WEB_PASSWORD"] = "short"
with patch.object(setup_native.shutil, "which", side_effect=self.which_all()):
with self.assertRaisesRegex(ValueError, "at least 8"):
installer.configure_web(prefix, setup_native.arguments([]))
installer.environ.pop("PIPELINES_WEB_PASSWORD")
with patch.object(setup_native.shutil, "which", side_effect=self.which_all()), \
patch.object(setup_native.sys.stdin, "isatty", return_value=True), \
patch.object(setup_native.getpass, "getpass",
side_effect=["short", "typed-password", "other-password",
"typed-password", "typed-password"]):
web = installer.configure_web(prefix, setup_native.arguments([]))
self.assertEqual(json.loads(Path(web["auth_file"]).read_text())["password"], "typed-password")
def test_fresh_install_skips_docker_migration(self):
args = setup_native.arguments(["--fresh"])
self.assertTrue(args.fresh)
self.assertFalse(setup_native.arguments([]).fresh)
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_cli_and_claude_host_with_trimpath(self):
with tempfile.TemporaryDirectory() as directory:
recorder = Recorder()
installer = self.installer(directory, recorder)
prefix = Path(directory) / "prefix"
installer.prepare_layout(prefix)
installer.build(prefix)
builds = [call for call in recorder.calls if call[:2] == ["go", "build"]]
self.assertEqual(len(builds), 3)
for call in builds:
self.assertIn("-trimpath", call)
self.assertTrue(any(call[-1] == "./cmd/pipelines-server" for call in builds))
self.assertTrue(any(call[-1] == "./cmd/pipelines" for call in builds))
self.assertTrue(any(call[-1] == "./cmd/pipelines-claude-host" for call in builds))
self.assertFalse(any("pipelines-tui" in part for call in recorder.calls for part in call))
def test_layout_creates_private_prefix_and_copies_manage(self):
with tempfile.TemporaryDirectory() as directory:
installer = self.installer(directory, Recorder())
prefix = Path(directory) / "prefix"
installer.prepare_layout(prefix)
for name in ("bin", "lib", "data", "logs", "secrets"):
self.assertTrue((prefix / name).is_dir(), name)
self.assertEqual((prefix / "secrets").stat().st_mode & 0o777, 0o700)
self.assertTrue((prefix / "lib/manage.py").is_file())
def test_prefix_honours_pipelines_prefix_environment(self):
with tempfile.TemporaryDirectory() as directory:
custom = Path(directory) / "custom"
installer = setup_native.Setup(directory, runner=Recorder(), environ={"PIPELINES_PREFIX": str(custom)})
self.assertEqual(installer.resolve_prefix(), custom.resolve())
def test_authoring_role_defaults_only_fresh_install_to_enabled(self):
with tempfile.TemporaryDirectory() as directory:
installer = self.installer(directory, Recorder())
prefix = Path(directory) / "prefix"
self.assertTrue(installer.authoring_role(prefix, None))
prefix.mkdir()
for previous, expected in (({}, False), ({"allow_authoring": False}, False),
({"allow_authoring": True}, True)):
with self.subTest(previous=previous):
manifest = prefix / setup_native.MARKER
manifest.write_text(json.dumps(previous))
before = manifest.read_bytes()
self.assertIs(installer.authoring_role(prefix, None), expected)
self.assertTrue(installer.authoring_role(prefix, True))
self.assertFalse(installer.authoring_role(prefix, False))
self.assertEqual(manifest.read_bytes(), before)
manifest.write_text('{"allow_authoring":"true"}')
with self.assertRaisesRegex(ValueError, "Invalid existing authoring role"):
installer.authoring_role(prefix, None)
def test_authoring_flags_are_explicit_optional_overrides(self):
self.assertIsNone(setup_native.arguments([]).allow_authoring)
self.assertTrue(setup_native.arguments(["--allow-authoring"]).allow_authoring)
self.assertFalse(setup_native.arguments(["--no-authoring"]).allow_authoring)
def test_full_run_keeps_existing_execution_only_and_accepts_fresh_opt_out(self):
for previous, arguments in (({}, []), ({"allow_authoring": False}, []), (None, ["--no-authoring"])):
with self.subTest(previous=previous), tempfile.TemporaryDirectory() as directory:
installer = self.installer(directory, Recorder())
prefix = Path(directory) / "prefix"
if previous is not None:
prefix.mkdir()
(prefix / setup_native.MARKER).write_text(json.dumps(previous))
with patch.object(setup_native.shutil, "which", side_effect=self.which_all()), \
patch.object(setup_native.lan, "detect_lan", return_value="192.168.1.20"), \
patch.object(setup_native.configure, "host_timezone", return_value="UTC"), \
redirect_stdout(io.StringIO()):
installer.run(setup_native.arguments(arguments))
self.assertFalse(manage.load(prefix)["allow_authoring"])
def test_notification_web_url_is_preserved_and_can_be_overridden(self):
for override in (None, "https://new-pipelines.example.com"):
with self.subTest(override=override), tempfile.TemporaryDirectory() as directory:
installer = self.installer(directory, Recorder())
prefix = Path(directory) / "prefix"
prefix.mkdir()
(prefix / setup_native.MARKER).write_text(json.dumps({"opencode_env": {
"PIPELINES_WEB_PUBLIC_URL": "https://pipelines.example.com"}}))
if override:
installer.environ["PIPELINES_WEB_PUBLIC_URL"] = override
with patch.object(setup_native.shutil, "which", side_effect=self.which_all()), \
patch.object(setup_native.lan, "detect_lan", return_value="192.168.1.20"), \
patch.object(setup_native.configure, "host_timezone", return_value="UTC"), \
redirect_stdout(io.StringIO()):
installer.run(setup_native.arguments([]))
self.assertEqual(manage.load(prefix)["opencode_env"]["PIPELINES_WEB_PUBLIC_URL"],
override or "https://pipelines.example.com")
def test_invalid_notification_web_url_refused_before_install(self):
with tempfile.TemporaryDirectory() as directory:
installer = self.installer(directory, Recorder())
installer.environ["PIPELINES_WEB_PUBLIC_URL"] = "https://user:secret@example.com"
with self.assertRaisesRegex(ValueError, "PIPELINES_WEB_PUBLIC_URL"):
installer.run(setup_native.arguments([]))
def test_missing_opencode_fails_actionably(self):
with tempfile.TemporaryDirectory() as directory:
installer = self.installer(directory, Recorder())
with patch.object(setup_native.shutil, "which", side_effect=self.which_all(opencode=None)):
with self.assertRaisesRegex(ValueError, "OpenCode was not found"):
installer.harness()
def test_full_run_writes_manifest_tokens_and_config_without_harness_install(self):
with tempfile.TemporaryDirectory() as directory:
recorder = Recorder()
installer = self.installer(directory, recorder)
prefix = Path(directory) / "prefix"
with patch.object(setup_native.shutil, "which", side_effect=self.which_all()), \
patch.object(setup_native.lan, "detect_lan", return_value="192.168.1.20"), \
patch.object(setup_native.configure, "host_timezone", return_value="Europe/London"):
installer.run(setup_native.arguments([]))
config = manage.load(prefix)
self.assertEqual(config["format"], 1)
self.assertTrue(config["allow_authoring"])
self.assertEqual(config["prefix"], str(prefix.resolve()))
self.assertEqual(config["server_port"], 8080)
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.assertEqual(config["opencode_env"]["PIPELINES_DEFAULT_MODEL"], "fixture/host-default")
self.assertEqual(config["opencode_env"]["PIPELINES_WEB_PUBLIC_URL"], "http://192.168.1.20:8082")
host = json.loads(installer.harness_config_path().read_text())["profiles"]["opencode"]
self.assertEqual(host["model"], "fixture/host-default")
self.assertEqual(host["pipeline_model"], "fixture/host-default")
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")
self.assertEqual(token_path.stat().st_mode & 0o777, 0o600)
text = (prefix / "data/ntfy/server.yml").read_text()
for needle in ('listen-http:', 'base-url: "http://192.168.1.20:8090"', 'cache-file:', 'auth-file:',
'auth-default-access: "deny-all"', 'enable-login: true', 'attachment-cache-dir:',
'attachment-expiry-duration:', 'attachment-total-size-limit:',
'attachment-file-size-limit:'):
self.assertIn(needle, text)
self.assertNotIn("topic", text)
self.assertTrue(recorder.has(str(prefix.resolve() / "bin/pipelines"), "skill", "install"))
self.assertTrue(recorder.has("access", "pipeline-publisher", "pipelines", "write-only"))
self.assertTrue(recorder.has("access", "phone-reader", "pipelines", "read-only"))
discovery = [call for call in recorder.calls if call[0].endswith("opencode")]
self.assertEqual(discovery, [["/usr/bin/opencode", "api", "get", "/api/model/default"]])
self.assertFalse(any("pipelines-tui" in part for call in recorder.calls for part in call))
self.assertFalse(any(TOKEN in part for call in recorder.calls for part in call))
def test_reinstall_keeps_existing_publisher_token(self):
with tempfile.TemporaryDirectory() as directory:
recorder = Recorder()
installer = self.installer(directory, recorder)
prefix = Path(directory) / "prefix"
with patch.object(setup_native.shutil, "which", side_effect=self.which_all()), \
patch.object(setup_native.lan, "detect_lan", return_value="192.168.1.20"), \
patch.object(setup_native.configure, "host_timezone", return_value="Europe/London"):
installer.run(setup_native.arguments(["--web-port", "8096"]))
before = (prefix / "secrets/publisher-token").read_text()
def refuse_resolution():
raise AssertionError("re-resolved ntfy despite a verified installed binary")
installer.resolver = refuse_resolution
recorder.calls.clear()
with redirect_stdout(io.StringIO()) as output:
installer.run(setup_native.arguments([]))
self.assertEqual((prefix / "secrets/publisher-token").read_text(), before)
self.assertEqual(manage.load(prefix)["web"]["port"], 8096)
self.assertEqual(output.getvalue().splitlines()[-4:], [
" http://localhost:8096/", " http://192.168.1.20:8096/",
"OpenCode is required (default stage and chat harness) and is set up by ./install.",
"Next: set up your agent harnesses: pipelines harness setup claude|codex|opencode|pi"])
self.assertFalse(any("token" in call for call in recorder.calls), "reinstall re-created the token")
def test_ntfy_is_built_from_the_pinned_module(self):
with tempfile.TemporaryDirectory() as directory:
recorder = Recorder()
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()):
path = installer.build_ntfy(prefix, resolution())
self.assertTrue(path.is_file())
self.assertTrue(path.stat().st_mode & 0o100)
self.assertTrue(recorder.has("go", "mod", "download", f"{NTFY_MODULE}@v{NTFY_VERSION}"))
build = next(call for call in recorder.calls if call[:2] == ["go", "build"] and call[-1] == ".")
self.assertIn("-trimpath", build)
self.assertIn(setup_native.NTFY_BUILD_TAGS, build)
self.assertTrue(any(f"-X main.version=v{NTFY_VERSION}" in part for part in build))
self.assertTrue(build[build.index("-o") + 1].endswith("/ntfy"))
kwargs = next(kw for call, kw in zip(recorder.calls, recorder.kwargs)
if call[:2] == ["go", "build"] and call[-1] == ".")
self.assertEqual(kwargs.get("env", {}).get("CGO_ENABLED"), "1")
def test_ntfy_build_is_reused_for_the_same_version(self):
with tempfile.TemporaryDirectory() as directory:
recorder = Recorder()
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()):
installer.build_ntfy(prefix, resolution())
installer.write_manifest(prefix, {"ntfy": {"version": "v" + NTFY_VERSION}})
recorder.calls.clear()
installer.build_ntfy(prefix, resolution())
self.assertFalse(any(call[:2] == ["go", "build"] for call in recorder.calls),
"rebuilt ntfy for an already installed version")
def test_missing_c_compiler_fails_actionably(self):
installer = setup_native.Setup("/tmp", runner=Recorder(), resolver=resolution, environ={})
with patch.object(setup_native.shutil, "which", side_effect=self.which_all(cc=None)):
with self.assertRaisesRegex(ValueError, "No C compiler found"):
installer.require_compiler()
def test_ntfy_build_failure_is_reported(self):
with tempfile.TemporaryDirectory() as directory:
installer = self.installer(directory, Recorder(fail_build=True))
prefix = Path(directory) / "prefix"
installer.prepare_layout(prefix)
with patch.object(setup_native.shutil, "which", side_effect=self.which_all()):
with self.assertRaisesRegex(ValueError, "build failed"):
installer.build_ntfy(prefix, resolution())
def test_publisher_token_is_never_overwritten(self):
with tempfile.TemporaryDirectory() as directory:
prefix = Path(directory) / "prefix"
(prefix / "secrets").mkdir(parents=True)
path = prefix / "secrets/publisher-token"
setup_native.tokens.save_token(f"token {TOKEN} created", path, 0o600)
self.assertEqual(path.stat().st_mode & 0o777, 0o600)
with self.assertRaises(ValueError):
setup_native.tokens.save_token(f"token {TOKEN} created", path, 0o600)
self.assertEqual(path.read_text(), TOKEN + "\n")
def test_migration_copies_docker_data_only_when_absent(self):
with tempfile.TemporaryDirectory() as directory:
prefix = Path(directory) / "prefix"
(prefix / "data/ntfy").mkdir(parents=True)
recorder = Recorder(volumes=("pipelines_pipelines-data", "pipelines_ntfy-data"))
installer = self.installer(directory, recorder)
self.assertTrue(installer.migrate_docker(prefix, replace=False))
self.assertEqual((prefix / "data/pipelines.db").read_bytes(), b"migrated")
self.assertTrue(any(call[:2] == ["docker", "cp"] and call[2].endswith("-wal")
for call in installer.runner.calls),
"the SQLite write-ahead log sidecar must be copied with the database")
self.assertEqual((prefix / "data/ntfy/auth.db").read_bytes(), b"migrated")
def test_migration_keeps_existing_native_data_without_opt_in(self):
with tempfile.TemporaryDirectory() as directory:
prefix = Path(directory) / "prefix"
(prefix / "data").mkdir(parents=True)
(prefix / "data/pipelines.db").write_bytes(b"native")
recorder = Recorder(volumes=("pipelines_pipelines-data",))
installer = self.installer(directory, recorder)
self.assertTrue(installer.migrate_docker(prefix, replace=False))
self.assertEqual((prefix / "data/pipelines.db").read_bytes(), b"native")
self.assertFalse(any(call[1:2] == ["cp"] for call in recorder.calls))
def test_absent_docker_volumes_is_a_noop(self):
with tempfile.TemporaryDirectory() as directory:
recorder = Recorder(volumes=())
installer = self.installer(directory, recorder)
self.assertFalse(installer.migrate_docker(Path(directory) / "prefix", replace=False))
self.assertFalse(any(call[0] == "docker" and call[1] == "create" for call in recorder.calls))
def test_uninspectable_docker_volumes_abort_instead_of_skipping_migration(self):
with tempfile.TemporaryDirectory() as directory:
recorder = Recorder(fail_volume_ls=True)
installer = self.installer(directory, recorder)
with self.assertRaisesRegex(ValueError, "Could not inspect Docker volumes"):
installer.migrate_docker(Path(directory) / "prefix", replace=False)
def test_missing_docker_cli_is_a_noop_not_a_failure(self):
def no_docker(command, **kwargs):
raise FileNotFoundError(command[0])
with tempfile.TemporaryDirectory() as directory:
installer = setup_native.Setup(directory, prefix=Path(directory) / "prefix",
runner=no_docker, resolver=resolution, environ={})
self.assertEqual(installer.docker_volumes(), ())
def test_requested_migration_failure_aborts(self):
with tempfile.TemporaryDirectory() as directory:
prefix = Path(directory) / "prefix"
(prefix / "data").mkdir(parents=True)
recorder = Recorder(volumes=("pipelines_pipelines-data",), fail_copy=True)
installer = self.installer(directory, recorder)
with self.assertRaisesRegex(ValueError, "install aborted"):
installer.migrate_docker(prefix, replace=False)
def test_full_run_migrates_docker_auth_store_before_native_accounts(self):
with tempfile.TemporaryDirectory() as directory:
recorder = Recorder(volumes=("pipelines_ntfy-data",))
installer = self.installer(directory, recorder)
prefix = Path(directory) / "prefix"
with patch.object(setup_native.shutil, "which", side_effect=self.which_all()), \
patch.object(setup_native.lan, "detect_lan", return_value="192.168.1.20"), \
patch.object(setup_native.configure, "host_timezone", return_value="Europe/London"):
installer.run(setup_native.arguments([]))
# The migrated store must survive bootstrap instead of being shadowed.
self.assertEqual((prefix / "data/ntfy/auth.db").read_bytes(), b"migrated")
copy_index = next(i for i, call in enumerate(recorder.calls)
if call[0] == "docker" and call[1:2] == ["cp"])
add_index = next(i for i, call in enumerate(recorder.calls)
if "pipeline-publisher" in call and "user" in call)
self.assertLess(copy_index, add_index, "auth store migrated after native accounts were created")
def test_missing_local_image_aborts_migration(self):
with tempfile.TemporaryDirectory() as directory:
prefix = Path(directory) / "prefix"
(prefix / "data").mkdir(parents=True)
recorder = Recorder(volumes=("pipelines_pipelines-data",), image=None)
installer = self.installer(directory, recorder)
with self.assertRaisesRegex(ValueError, "no local Pipelines image"):
installer.migrate_docker(prefix, replace=False)
def test_configure_harnesses_writes_host_profiles_for_detected_harness(self):
with tempfile.TemporaryDirectory() as directory:
recorder = Recorder()
installer = self.installer(directory, recorder)
prefix = Path(directory) / "prefix"
installer.configure_harnesses({"opencode": "/usr/bin/opencode", "pi": ""}, "fixture/harness")
path = installer.harness_config_path()
self.assertEqual(path, Path(directory) / "config/pipelines/harnesses.json")
config = json.loads(path.read_text())
self.assertEqual(config["default"], "opencode")
profile = config["profiles"]["opencode"]
self.assertEqual(profile["executable"], "/usr/bin/opencode")
self.assertNotIn("docker_directory", profile)
self.assertTrue(installer._valid_model(profile["model"]))
self.assertTrue(installer._valid_model(profile["pipeline_model"]))
self.assertEqual(profile["model"], "fixture/harness")
# Detection-only: no harness install/upgrade/download was invoked.
self.assertFalse(any("opencode" in part for call in recorder.calls for part in call))
def test_configure_harnesses_fails_without_a_valid_model_in_nonterminal(self):
with tempfile.TemporaryDirectory() as directory:
installer = self.installer(directory, Recorder(host_model=None))
path = installer.harness_config_path()
with patch.object(setup_native.sys.stdin, "isatty", return_value=False):
with self.assertRaisesRegex(ValueError, "setup is not ready.*--model PROVIDER/MODEL"):
installer.configure_harnesses({"opencode": "/usr/bin/opencode", "pi": ""})
self.assertFalse(path.exists(), "an invalid profile was written")
def test_opencode_default_reads_model_info_without_inference_or_jsonc_parsing(self):
with tempfile.TemporaryDirectory() as directory:
calls = []
def api(command, **kwargs):
calls.append((command, kwargs))
return subprocess.CompletedProcess(command, 0, stdout=json.dumps({"data": {
"id": "internal-id-not-a-model", "providerID": "configured-provider",
"modelID": "configured-model", "enabled": True, "status": "active"}}))
installer = self.installer(directory, api)
path = installer.configure_harnesses({"opencode": "/existing/opencode", "pi": ""})
profile = json.loads(path.read_text())["profiles"]["opencode"]
self.assertEqual(profile["model"], "configured-provider/configured-model")
self.assertEqual(profile["pipeline_model"], profile["model"])
self.assertEqual(len(calls), 1)
self.assertEqual(calls[0][0], ["/existing/opencode", "api", "get", "/api/model/default"])
self.assertEqual(calls[0][1]["cwd"], str(Path.home()))
self.assertEqual(calls[0][1]["env"], installer.environ)
self.assertEqual(calls[0][1]["timeout"], 30)
def test_opencode_default_rejects_missing_disabled_deprecated_or_placeholder_models(self):
valid = {"providerID": "fixture", "modelID": "host-default", "enabled": True, "status": "active"}
responses = [None, {}, {"data": None}, {"data": {**valid, "enabled": False}},
{"data": {**valid, "status": "deprecated"}},
{"data": {**valid, "providerID": "default", "modelID": "default"}},
{"data": {"id": "fixture/looks-valid", "enabled": True}}]
for response in responses:
with self.subTest(response=response), tempfile.TemporaryDirectory() as directory:
def api(command, **kwargs):
return subprocess.CompletedProcess(command, 0, stdout=json.dumps(response))
installer = self.installer(directory, api)
self.assertEqual(installer.opencode_default_model("/existing/opencode"), "")
def test_configure_harnesses_discovery_fills_only_missing_model_fields(self):
with tempfile.TemporaryDirectory() as directory:
installer = self.installer(directory, Recorder())
path = installer.harness_config_path()
path.parent.mkdir(parents=True)
path.write_text(json.dumps({"default": "opencode", "future": "preserve", "profiles": {
"opencode": {"model": "fixture/keep-interactive", "pipeline_model": "", "future": "keep"}}}))
installer.configure_harnesses({"opencode": "/existing/opencode", "pi": ""})
saved = json.loads(path.read_text())
self.assertEqual(saved["future"], "preserve")
self.assertEqual(saved["profiles"]["opencode"]["model"], "fixture/keep-interactive")
self.assertEqual(saved["profiles"]["opencode"]["pipeline_model"], "fixture/host-default")
self.assertEqual(saved["profiles"]["opencode"]["future"], "keep")
def test_missing_default_runs_existing_picker_inside_install_only_in_terminal(self):
with tempfile.TemporaryDirectory() as directory:
recorder = Recorder(host_model=None)
installer = self.installer(directory, recorder)
path = installer.harness_config_path()
def runner(command, **kwargs):
result = recorder(command, **kwargs)
if command[1:4] == ["harness", "setup", "opencode"]:
path.parent.mkdir(parents=True)
path.write_text(json.dumps({"default": "opencode", "profiles": {"opencode": {
"executable": "/existing/opencode", "model": "fixture/chosen-interactive",
"pipeline_model": "fixture/chosen-stages", "future": "preserve"}}}))
return result
installer.runner = runner
with patch.object(setup_native.sys.stdin, "isatty", return_value=True):
installer.configure_harnesses({"opencode": "/existing/opencode", "pi": ""})
picker = [call for call in recorder.calls if call[1:4] == ["harness", "setup", "opencode"]]
self.assertEqual(picker, [[str(installer.resolve_prefix() / "bin/pipelines"), "harness", "setup", "opencode",
"--host", "--executable", "/existing/opencode"]])
profile = json.loads(path.read_text())["profiles"]["opencode"]
self.assertEqual(profile["pipeline_model"], "fixture/chosen-stages")
self.assertEqual(profile["future"], "preserve")
def test_unresolved_model_aborts_full_run_before_start_or_ready_claim(self):
with tempfile.TemporaryDirectory() as directory:
recorder = Recorder(host_model=None)
installer = self.installer(directory, recorder)
with patch.object(setup_native.shutil, "which", side_effect=self.which_all()), \
patch.object(setup_native.sys.stdin, "isatty", return_value=False), \
redirect_stdout(io.StringIO()) as output:
with self.assertRaisesRegex(ValueError, "setup is not ready"):
installer.run(setup_native.arguments([]))
self.assertFalse((installer.resolve_prefix() / setup_native.MARKER).exists())
self.assertFalse(any("start" in call for call in recorder.calls))
self.assertNotIn("Native Pipelines installed", output.getvalue())
def test_legacy_standalone_web_agent_is_retired(self):
with tempfile.TemporaryDirectory() as directory:
recorder = Recorder()
installer = self.installer(directory, recorder)
agents = Path(self.home.name) / "Library/LaunchAgents"
agents.mkdir(parents=True)
legacy = agents / "net.awan.pipelines.web.plist"
legacy.write_text("legacy")
with patch.object(setup_native.platform, "system", return_value="Darwin"), \
redirect_stdout(io.StringIO()):
installer.retire_legacy_web()
installer.retire_legacy_web()
self.assertFalse(legacy.exists())
self.assertEqual((agents / "net.awan.pipelines.web.plist.disabled").read_text(), "legacy")
self.assertEqual(sum(call[:2] == ["launchctl", "bootout"] for call in recorder.calls), 1)
def test_tailnet_public_url_serves_the_installed_web_app(self):
with tempfile.TemporaryDirectory() as directory:
recorder = Recorder()
installer = self.installer(directory, recorder)
with patch.object(setup_native.shutil, "which", return_value="/usr/bin/tailscale"), \
redirect_stdout(io.StringIO()):
installer.serve_on_tailnet("https://box.tail1.ts.net:8443", 8083)
installer.serve_on_tailnet("http://10.0.0.5:8083", 8083)
self.assertEqual([call for call in recorder.calls if "serve" in call],
[["/usr/bin/tailscale", "serve", "--bg", "--https=8443", "http://127.0.0.1:8083"]])
def refusing(command, **kwargs):
return subprocess.CompletedProcess(command, 1, stdout="", stderr="serve: access denied")
installer = self.installer(directory, refusing)
with patch.object(setup_native.shutil, "which", return_value="/usr/bin/tailscale"):
with self.assertRaisesRegex(ValueError, "access denied"):
installer.serve_on_tailnet("https://box.tail1.ts.net", 8083)
def test_install_is_all_or_nothing_with_the_web_app(self):
cases = {"no docker": dict(docker=False), "web build fails": dict(fail_web=True),
"server build fails": dict(fail_build=True)}
for name, case in cases.items():
with self.subTest(case=name), tempfile.TemporaryDirectory() as directory:
recorder = Recorder(fail_web=case.get("fail_web", False),
fail_build=case.get("fail_build", False))
installer = self.installer(directory, recorder)
prefix = installer.resolve_prefix()
(prefix / "bin").mkdir(parents=True)
(prefix / "bin/pipelines-server").write_text("old")
(prefix / "lib/app-web").mkdir(parents=True)
(prefix / "lib/app-web/index.html").write_text("old")
with patch.object(setup_native.shutil, "which", side_effect=self.which_all()), \
patch.object(setup_native.app_build, "docker_available",
return_value=case.get("docker", True)), \
patch.object(setup_native.lan, "detect_lan", return_value="192.168.1.20"), \
redirect_stdout(io.StringIO()):
with self.assertRaises(ValueError):
installer.run(setup_native.arguments([]))
# Neither half was replaced and nothing claims an install.
self.assertEqual((prefix / "bin/pipelines-server").read_text(), "old")
self.assertEqual((prefix / "lib/app-web/index.html").read_text(), "old")
self.assertFalse((prefix / setup_native.MARKER).exists())
self.assertFalse((prefix / "bin/.next").exists())
def test_picker_cancellation_or_unsaved_models_never_claim_configuration_complete(self):
for returncode in (0, 1):
with self.subTest(returncode=returncode), tempfile.TemporaryDirectory() as directory:
calls = []
def runner(command, **kwargs):
calls.append(command)
if command[1:4] == ["harness", "setup", "opencode"]:
return subprocess.CompletedProcess(command, returncode)
return subprocess.CompletedProcess(command, 0, stdout='{"data":null}')
installer = self.installer(directory, runner)
with patch.object(setup_native.sys.stdin, "isatty", return_value=True), redirect_stdout(io.StringIO()):
with self.assertRaisesRegex(ValueError, "setup is not ready"):
installer.configure_harnesses({"opencode": "/existing/opencode", "pi": ""})
self.assertFalse(installer.harness_config_path().exists())
self.assertEqual(sum(call[1:4] == ["harness", "setup", "opencode"] for call in calls), 1)
def test_full_run_reuses_saved_stage_default_without_opencode_queries(self):
with tempfile.TemporaryDirectory() as directory:
recorder = Recorder(host_model=None)
installer = self.installer(directory, recorder)
path = installer.harness_config_path()
path.parent.mkdir(parents=True)
path.write_text(json.dumps({"default": "opencode", "profiles": {"opencode": {
"executable": "/old/opencode", "model": "fixture/interactive", "pipeline_model": "fixture/stages"}}}))
with patch.object(setup_native.shutil, "which", side_effect=self.which_all()), \
patch.object(setup_native.lan, "detect_lan", return_value="192.168.1.20"), \
patch.object(setup_native.configure, "host_timezone", return_value="UTC"), \
redirect_stdout(io.StringIO()):
installer.run(setup_native.arguments([]))
manifest = manage.load(installer.resolve_prefix())
self.assertEqual(manifest["opencode_env"]["PIPELINES_DEFAULT_MODEL"], "fixture/stages")
self.assertFalse(any(call[0].endswith("opencode") for call in recorder.calls))
def test_configure_harnesses_migrates_stale_docker_link_and_default(self):
with tempfile.TemporaryDirectory() as directory:
installer = self.installer(directory, Recorder())
path = installer.harness_config_path()
path.parent.mkdir(parents=True)
path.write_text(json.dumps({
"default": "pi",
"future": "preserve",
"profiles": {
"opencode": {"docker_directory": "/checkout", "executable": "opencode",
"model": "fixture/interactive", "pipeline_model": "fixture/stages"},
"pi": {"docker_directory": "/checkout", "executable": "pi",
"model": "provider/interactive", "pipeline_model": "provider/stages"},
},
}))
installer.configure_harnesses({"opencode": "/usr/bin/opencode", "pi": "/usr/bin/pi"})
saved = json.loads(path.read_text())
self.assertEqual(saved["default"], "opencode")
self.assertEqual(saved["future"], "preserve")
for name in ("opencode", "pi"):
self.assertNotIn("docker_directory", saved["profiles"][name], name)
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')
path.chmod(0o755)
return path
def test_check_path_shadow_warns_naming_path_and_both_versions(self):
with tempfile.TemporaryDirectory() as directory:
directory = Path(directory)
prefix = directory / "prefix"
installed = self._fake_pipelines(prefix / "bin/pipelines", "new-version", "bbbb")
shadow_dir = directory / "earlier"
shadow = self._fake_pipelines(shadow_dir / "pipelines", "old-version", "aaaa")
before = shadow.read_bytes()
installer = setup_native.Setup(directory, prefix=prefix, runner=subprocess.run,
resolver=resolution, environ={})
with patch.object(setup_native.shutil, "which", side_effect=lambda name: str(shadow) if name == "pipelines" else None):
output = io.StringIO()
with redirect_stdout(output):
result = installer.check_path_shadow(prefix)
warning = output.getvalue()
self.assertEqual(result, shadow.resolve())
self.assertIn("WARNING", warning)
self.assertIn(str(shadow), warning)
self.assertIn("old-version", warning)
self.assertIn("new-version", warning)
# The shadowing binary is only read; it is never modified or replaced.
self.assertEqual(shadow.read_bytes(), before)
self.assertEqual(installed.read_bytes().count(b"new-version"), 1)
def test_check_path_shadow_is_silent_when_prefix_binary_wins(self):
with tempfile.TemporaryDirectory() as directory:
directory = Path(directory)
prefix = directory / "prefix"
installed = self._fake_pipelines(prefix / "bin/pipelines", "same-version", "cccc")
installer = setup_native.Setup(directory, prefix=prefix, runner=subprocess.run,
resolver=resolution, environ={})
with patch.object(setup_native.shutil, "which", return_value=str(installed)):
output = io.StringIO()
with redirect_stdout(output):
result = installer.check_path_shadow(prefix)
self.assertIsNone(result)
self.assertEqual(output.getvalue(), "")
def test_check_path_shadow_is_silent_without_a_path_binary(self):
with tempfile.TemporaryDirectory() as directory:
installer = setup_native.Setup(directory, prefix=Path(directory) / "prefix",
runner=subprocess.run, resolver=resolution, environ={})
with patch.object(setup_native.shutil, "which", return_value=None):
output = io.StringIO()
with redirect_stdout(output):
result = installer.check_path_shadow(Path(directory) / "prefix")
self.assertIsNone(result)
self.assertEqual(output.getvalue(), "")
def test_check_path_shadow_reads_each_binary_at_most_once(self):
class VersionRunner:
def __init__(self):
self.commands = []
def __call__(self, command, **kwargs):
command = list(command)
self.commands.append(command)
version = "old-version" if "earlier" in command[0] else "new-version"
return subprocess.CompletedProcess(command, 0,
stdout=f'{{"version":"{version}","commit":"ab"}}', stderr="")
with tempfile.TemporaryDirectory() as directory:
directory = Path(directory)
prefix = directory / "prefix"
installed = self._fake_pipelines(prefix / "bin/pipelines", "new-version", "bbbb")
shadow = self._fake_pipelines(directory / "earlier/pipelines", "old-version", "aaaa")
runner = VersionRunner()
installer = setup_native.Setup(directory, prefix=prefix, runner=runner,
resolver=resolution, environ={})
with patch.object(setup_native.shutil, "which", return_value=str(shadow)):
output = io.StringIO()
with redirect_stdout(output):
installer.check_path_shadow(prefix)
# A detected shadow costs exactly one bounded, read-only `version`
# read per binary (the shadow and the freshly installed CLI) so both
# versions can be named; no other subprocess runs.
self.assertEqual(len(runner.commands), 2)
self.assertTrue(all(command[1:] == ["version", "--json"] for command in runner.commands))
self.assertIn("old-version", output.getvalue())
self.assertIn("new-version", output.getvalue())
self.assertEqual(installed.read_bytes().count(b"new-version"), 1)
def test_full_run_migrates_docker_harness_config_to_host(self):
with tempfile.TemporaryDirectory() as directory:
recorder = Recorder()
installer = self.installer(directory, recorder)
prefix = Path(directory) / "prefix"
path = installer.harness_config_path()
path.parent.mkdir(parents=True)
path.write_text(json.dumps({
"default": "pi",
"profiles": {
"opencode": {"docker_directory": "/checkout", "executable": "opencode",
"model": "fixture/interactive", "pipeline_model": "fixture/stages"},
"pi": {"docker_directory": "/checkout", "executable": "pi",
"model": "provider/interactive", "pipeline_model": "provider/stages"},
},
}))
with patch.object(setup_native.shutil, "which", side_effect=self.which_all(opencode="/usr/bin/opencode", pi="/usr/bin/pi")), \
patch.object(setup_native.lan, "detect_lan", return_value="192.168.1.20"), \
patch.object(setup_native.configure, "host_timezone", return_value="Europe/London"):
installer.run(setup_native.arguments([]))
saved = json.loads(path.read_text())
self.assertEqual(saved["default"], "opencode", "stale Docker-era pi default survived")
self.assertNotIn("docker_directory", saved["profiles"]["opencode"])
self.assertTrue(saved["profiles"]["opencode"]["executable"].endswith("opencode"))
self.assertTrue(installer._valid_model(saved["profiles"]["opencode"]["model"]))
# Detection-only: no harness install/upgrade/download command recorded.
self.assertFalse(any("opencode" in part for call in recorder.calls for part in call))
self.assertFalse(any(part == "pi" for call in recorder.calls for part in call))
self.assertFalse(any("npm" == part for call in recorder.calls for part in call))
if __name__ == "__main__":
unittest.main()