Files
pipelines/scripts/test_configure_compose.py
T
alan fc7dbb0ac0 Remove ntfy: notifications go only through the app notification stream
Server: drop ntfy publishing (stage hooks, run outbox, chat attention, chat
tool notify, auto-switch and schedule notices), the chat push outbox (its
table is dropped at startup), ntfy status/endpoints and PIPELINES_NTFY_*.
The app_notifications stream, subscribe/clear and kinds are unchanged.
Notification settings keep run_finished/chat_needs_you/chat_reply_finished;
ntfy_enabled is accepted and ignored and its stored row is never read.

Stage type=ntfy is rejected: "ntfy stages were removed; notifications go to
the Pipelines apps — use the stage notify hook". The notify hook remains.

Installer: no ntfy build, accounts, config or supervisor child; manifest
gets top-level "mode" (legacy ntfy.mode still read). Reinstall retires an
old ntfy (safe PID-file stop, deletes binary, config, data dir, token, log,
with a note in logs/install.log); uninstall cleans leftovers.

App: ntfy settings section replaced by "Notification events"; texts updated.
Docs: docs/ntfy.md folded into docs/notifications.md; install, docker, cli,
author skill references updated; security review M1 marked resolved.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 23:24:24 +00:00

81 lines
3.9 KiB
Python

import importlib.util
import json
import os
from pathlib import Path
import tempfile
import unittest
from unittest.mock import patch
spec = importlib.util.spec_from_file_location("configure", Path(__file__).with_name("configure-compose.py"))
configure = importlib.util.module_from_spec(spec)
spec.loader.exec_module(configure)
class ConfigureTests(unittest.TestCase):
def setUp(self):
# Container runs may have HOME=/home/pipelines, which the mount guard
# rejects; inject a disposable HOME/USERPROFILE for the fixtures.
home = tempfile.TemporaryDirectory()
self.addCleanup(home.cleanup)
environment = patch.dict(os.environ, {"HOME": home.name, "USERPROFILE": home.name})
environment.start()
self.addCleanup(environment.stop)
def test_detect_timezone_and_preserve_existing_files(self):
try:
configure.host_timezone()
except ValueError:
self.skipTest("host timezone is unavailable in this environment")
with tempfile.TemporaryDirectory() as directory:
zone = configure.configure(directory)
self.assertTrue(zone)
settings = Path(directory, ".env")
original = settings.read_bytes()
self.assertIn(f"TZ={zone}", settings.read_text())
self.assertNotIn("NTFY", settings.read_text())
self.assertFalse(Path(directory, "secrets").exists())
with self.assertRaises(ValueError):
configure.configure(directory, "Europe/London")
self.assertEqual(settings.read_bytes(), original)
def test_reject_injected_values(self):
for timezone in ("Europe/London\nEVIL=yes", "Nowhere/Invalid"):
with tempfile.TemporaryDirectory() as directory, self.assertRaises(Exception):
configure.configure(directory, timezone)
self.assertFalse(Path(directory, ".env").exists())
with tempfile.TemporaryDirectory() as directory, self.assertRaises(ValueError):
configure.configure(directory, "Europe/London", port=70000)
def test_client_default_is_saved_privately_and_preserves_other_keys(self):
with tempfile.TemporaryDirectory() as directory:
environ = {"XDG_CONFIG_HOME": directory}
path = configure.configure_client("ws://127.0.0.1:8080/connect", environ)
self.assertEqual(path, Path(directory) / "pipelines/client.json")
self.assertEqual(path.stat().st_mode & 0o777, 0o600)
self.assertEqual(json.loads(path.read_text())["server_url"], "ws://127.0.0.1:8080/connect")
# Unrelated keys survive a later reinstall with a different address.
path.write_text(json.dumps({"server_url": "ws://old/connect", "theme": "dark"}))
configure.configure_client("ws://127.0.0.1:9090/connect", environ)
saved = json.loads(path.read_text())
self.assertEqual(saved["server_url"], "ws://127.0.0.1:9090/connect")
self.assertEqual(saved["theme"], "dark")
def test_client_default_refuses_symlink_and_non_object(self):
with tempfile.TemporaryDirectory() as directory:
environ = {"XDG_CONFIG_HOME": directory}
target = Path(directory) / "real.json"
target.write_text("{}")
directory_path = Path(directory) / "pipelines"
directory_path.mkdir()
(directory_path / "client.json").symlink_to(target)
with self.assertRaisesRegex(ValueError, "symlinked client.json"):
configure.configure_client("ws://127.0.0.1:8080/connect", environ)
(directory_path / "client.json").unlink()
(directory_path / "client.json").write_text("[]")
with self.assertRaisesRegex(ValueError, "must contain an object"):
configure.configure_client("ws://127.0.0.1:8080/connect", environ)
if __name__ == "__main__":
unittest.main()