fix(notify): open configured web run pages from ntfy
This commit is contained in:
@@ -25,6 +25,7 @@ import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
from urllib.parse import urlsplit
|
||||
|
||||
from zoneinfo import ZoneInfoNotFoundError
|
||||
|
||||
@@ -642,6 +643,16 @@ class Setup:
|
||||
raise ValueError("Invalid API/web bind address; use an IPv4 address such as 0.0.0.0 or 127.0.0.1") from None
|
||||
prefix = self.resolve_prefix()
|
||||
allow_authoring = self.authoring_role(prefix, args.allow_authoring)
|
||||
web_public_url = self.environ.get("PIPELINES_WEB_PUBLIC_URL", "")
|
||||
previous = prefix / MARKER
|
||||
if not web_public_url and previous.is_file() and not previous.is_symlink():
|
||||
web_public_url = json.loads(previous.read_text()).get("opencode_env", {}).get("PIPELINES_WEB_PUBLIC_URL", "")
|
||||
if web_public_url:
|
||||
parsed = urlsplit(web_public_url)
|
||||
if (parsed.scheme not in ("http", "https") or not parsed.hostname or parsed.username is not None
|
||||
or parsed.password is not None or parsed.query or parsed.fragment or parsed.path not in ("", "/")
|
||||
or any(ord(c) < 33 for c in web_public_url)):
|
||||
raise ValueError("PIPELINES_WEB_PUBLIC_URL must be an HTTP(S) web origin without credentials, path, query or fragment")
|
||||
harness = self.harness()
|
||||
service_path = self.service_path()
|
||||
# Reuse an already built ntfy binary and skip the release lookup, so a
|
||||
@@ -684,6 +695,7 @@ class Setup:
|
||||
if self.environ.get(key):
|
||||
opencode_env[key] = self.environ[key]
|
||||
opencode_env["PIPELINES_DEFAULT_MODEL"] = args.model or pipeline_model
|
||||
opencode_env["PIPELINES_WEB_PUBLIC_URL"] = web_public_url or f"http://{lan_ip if args.web_host == '0.0.0.0' else args.web_host}:{args.web_port}"
|
||||
path_value = str(prefix / "bin") + os.pathsep + self.environ.get("PATH", "")
|
||||
manifest = {
|
||||
"format": 1,
|
||||
|
||||
@@ -298,6 +298,31 @@ class SetupNativeTests(unittest.TestCase):
|
||||
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())
|
||||
@@ -325,6 +350,7 @@ class SetupNativeTests(unittest.TestCase):
|
||||
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")
|
||||
|
||||
Reference in New Issue
Block a user