Expand pipeline panes and select the verified Docker client endpoint
This commit is contained in:
+53
-2
@@ -6,6 +6,8 @@ import ipaddress
|
||||
import re
|
||||
import shutil
|
||||
import json
|
||||
import os
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import sys
|
||||
@@ -215,11 +217,60 @@ printf 'header = "Authorization: Bearer %s"\\n' "$(cat "$PIPELINES_NTFY_TOKEN_FI
|
||||
print("Phone reception is not verified by this setup check.")
|
||||
address = self.compose("port", "pipelines", "8080", capture=True).stdout.strip()
|
||||
port = address.rsplit(":", 1)[-1]
|
||||
if not port.isdigit():
|
||||
if not port.isdigit() or not 1 <= int(port) <= 65535:
|
||||
raise ValueError("Could not identify the published Pipelines port")
|
||||
print(f"Host CLI/TUI connection: pipelines --url ws://127.0.0.1:{port}/connect tui")
|
||||
endpoint = f"ws://127.0.0.1:{port}/connect"
|
||||
self.verify_host_endpoint(endpoint)
|
||||
self.configure_client(endpoint)
|
||||
print(f"Host CLI/TUI connection: pipelines --url {endpoint} tui")
|
||||
print("Install host client binaries with ./install.sh --native if needed.")
|
||||
|
||||
def verify_host_endpoint(self, endpoint):
|
||||
if shutil.which("go"):
|
||||
command = ["go", "run", "./cmd/pipelines", "--url", endpoint, "status", "--json"]
|
||||
elif shutil.which("pipelines"):
|
||||
command = [shutil.which("pipelines"), "--url", endpoint, "status", "--json"]
|
||||
else:
|
||||
print("Host-side server connection not tested: no host Go or pipelines CLI available.")
|
||||
return
|
||||
result = self.runner(command, cwd=self.directory, capture_output=True, text=True, timeout=60)
|
||||
try:
|
||||
status = json.loads(result.stdout)
|
||||
except ValueError:
|
||||
raise ValueError("Host client could not inspect the published Docker server; setup is NOT complete")
|
||||
if (result.returncode or not isinstance(status, dict)
|
||||
or not isinstance(status.get("ntfy"), dict)
|
||||
or status["ntfy"].get("health") != "healthy"):
|
||||
raise ValueError("Host client did not reach the verified ntfy-enabled Docker server; check the published port before using the TUI")
|
||||
print("Verified: host client reaches the ntfy-enabled Docker server at " + endpoint)
|
||||
|
||||
def configure_client(self, endpoint):
|
||||
root = Path(os.environ.get("XDG_CONFIG_HOME") or Path.home()/".config")
|
||||
directory = root/"pipelines"
|
||||
path = directory/"client.json"
|
||||
if path.is_symlink():
|
||||
raise ValueError("Refusing to modify symlinked client.json; use the printed --url explicitly")
|
||||
existing = json.loads(path.read_text()) if path.exists() else {}
|
||||
if not isinstance(existing, dict):
|
||||
raise ValueError("client.json must contain an object; existing configuration was not replaced")
|
||||
existing["server_url"] = endpoint
|
||||
directory.mkdir(mode=0o700, parents=True, exist_ok=True)
|
||||
temporary = None
|
||||
try:
|
||||
with tempfile.NamedTemporaryFile(mode="w", dir=directory, delete=False) as file:
|
||||
temporary = Path(file.name)
|
||||
os.chmod(temporary, 0o600)
|
||||
json.dump(existing, file, indent=2)
|
||||
file.write("\n")
|
||||
os.replace(temporary, path)
|
||||
finally:
|
||||
if temporary is not None:
|
||||
temporary.unlink(missing_ok=True)
|
||||
print(f"Saved Docker client default: {endpoint} ({path}). Restart the TUI.")
|
||||
override = os.environ.get("PIPELINES_URL", "")
|
||||
if override and override != endpoint:
|
||||
print("WARNING: PIPELINES_URL overrides the saved Docker address. Use the printed --url or update that variable; otherwise the TUI may still reach a different server.")
|
||||
|
||||
def run(self, args):
|
||||
self.compose("version", capture=True)
|
||||
self.settings(args)
|
||||
|
||||
@@ -16,6 +16,41 @@ spec.loader.exec_module(setup)
|
||||
|
||||
|
||||
class DockerSetupTests(unittest.TestCase):
|
||||
def setUp(self):
|
||||
directory = tempfile.TemporaryDirectory()
|
||||
self.addCleanup(directory.cleanup)
|
||||
environment = patch.dict(os.environ, {"XDG_CONFIG_HOME": directory.name})
|
||||
environment.start()
|
||||
self.addCleanup(environment.stop)
|
||||
|
||||
def test_verified_client_default_preserves_unrelated_settings_and_warns_on_override(self):
|
||||
path = Path(os.environ["XDG_CONFIG_HOME"])/"pipelines/client.json"
|
||||
path.parent.mkdir()
|
||||
path.write_text('{"server_url":"ws://old/connect","custom":"keep"}')
|
||||
with tempfile.TemporaryDirectory() as directory, patch.dict(os.environ, {"PIPELINES_URL":"ws://old/connect"}):
|
||||
setup.Setup(directory).configure_client("ws://127.0.0.1:8081/connect")
|
||||
self.assertEqual(setup.json.loads(path.read_text()), {"server_url":"ws://127.0.0.1:8081/connect","custom":"keep"})
|
||||
self.assertEqual(path.stat().st_mode & 0o777, 0o600)
|
||||
|
||||
def test_client_config_symlink_and_malformed_content_are_not_overwritten(self):
|
||||
path = Path(os.environ["XDG_CONFIG_HOME"])/"pipelines/client.json"
|
||||
path.parent.mkdir()
|
||||
target = path.parent/"custom.json"
|
||||
target.write_text("private custom settings")
|
||||
path.symlink_to(target)
|
||||
with self.assertRaises(ValueError): setup.Setup(".").configure_client("ws://127.0.0.1:8081/connect")
|
||||
self.assertEqual(target.read_text(),"private custom settings")
|
||||
path.unlink()
|
||||
path.write_text("not JSON")
|
||||
with self.assertRaises(ValueError): setup.Setup(".").configure_client("ws://127.0.0.1:8081/connect")
|
||||
self.assertEqual(path.read_text(), "not JSON")
|
||||
|
||||
def test_host_verification_rejects_wrong_unconfigured_server(self):
|
||||
def runner(command, **kwargs):
|
||||
return subprocess.CompletedProcess(command, 0, stdout='{"ntfy":{"health":"not configured"}}', stderr="")
|
||||
with patch.object(setup.shutil,"which",return_value="/fixture/go"), self.assertRaises(ValueError):
|
||||
setup.Setup(".",runner=runner).verify_host_endpoint("ws://127.0.0.1:8081/connect")
|
||||
|
||||
def test_validation_primes_its_own_service_and_passes_model_as_argument(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
root=Path(directory);(root/".env").write_text("CUSTOM=keep\n")
|
||||
@@ -231,6 +266,8 @@ fi
|
||||
out = "127.0.0.1:8081\n"
|
||||
if fail and (fail in args or (fail=="login" and "exec opencode auth login" in args[-1]) or (fail=="provider-check" and any("provider-check" in arg for arg in args))):
|
||||
code, out = 9, "private provider data/token"
|
||||
if fail == "host" and command[0] != "docker" and args[-2:] == ["status", "--json"]:
|
||||
code, out = 9, '{"ntfy":{"health":"not configured"}}'
|
||||
return subprocess.CompletedProcess(command, code, stdout=out, stderr="")
|
||||
|
||||
args = setup.arguments([] if existing else ["--ntfy-url", "http://192.168.1.20:8090",
|
||||
@@ -250,6 +287,8 @@ fi
|
||||
self.assertLess(next(i for i,c in enumerate(calls) if "token" in c), next(i for i,c in enumerate(calls) if "build" in c))
|
||||
self.assertLess(next(i for i,c in enumerate(calls) if "exec opencode auth login" in c[-1]), next(i for i,c in enumerate(calls) if "--force-recreate" in c))
|
||||
self.assertTrue(any("curl --config -" in " ".join(c) for c in calls))
|
||||
config = Path(os.environ["XDG_CONFIG_HOME"])/"pipelines/client.json"
|
||||
self.assertEqual(setup.json.loads(config.read_text())["server_url"],"ws://127.0.0.1:8081/connect")
|
||||
|
||||
def test_reinstall_preserves_configuration_tokens_and_provider_setup(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
@@ -273,7 +312,7 @@ fi
|
||||
self.assertTrue(Path(directory, "secrets/ntfy-token.txt").stat().st_size)
|
||||
|
||||
def test_status_and_publication_failures_are_not_success(self):
|
||||
for failure in ["status", "sh", "provider-check"]:
|
||||
for failure in ["status", "sh", "provider-check", "host"]:
|
||||
with tempfile.TemporaryDirectory() as directory, self.assertRaises(ValueError):
|
||||
self.exercise(directory, fail=failure)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user