Install and start the server only together with the web app
./install builds the web app and the server before replacing either, and fails without Docker or on a failed build, leaving the old pair in place. The supervisor and start refuse to run the server when the web app is not installed.
This commit is contained in:
@@ -139,12 +139,14 @@ class ManageNativeTests(unittest.TestCase):
|
||||
patch.object(manage, "wait_health"), patch.object(manage.signal, "signal"), \
|
||||
patch.object(manage.subprocess, "Popen", return_value=server) as popen:
|
||||
manage.supervise(config)
|
||||
command = popen.call_args.args[0]
|
||||
command = popen.call_args_list[0].args[0]
|
||||
self.assertEqual(command[:5], [str(root / "bin/pipelines-server"), "-addr", "127.0.0.1:8080",
|
||||
"-db", str(root / "data/pipelines.db")])
|
||||
self.assertEqual("-allow-authoring" in command, role is True)
|
||||
|
||||
def config(self, root, mode="native"):
|
||||
(root / "lib/app-web").mkdir(parents=True, exist_ok=True)
|
||||
(root / "lib/app-web/index.html").write_text("app")
|
||||
return {
|
||||
"format": 1, "prefix": str(root), "python": "python3", "server_port": 8080,
|
||||
"ntfy_port": 8090, "opencode": "opencode", "opencode_env": {}, "path": "",
|
||||
@@ -153,8 +155,26 @@ class ManageNativeTests(unittest.TestCase):
|
||||
"label": "net.a-wan.pipelines", "docker": "docker", "project": "pipelines", "timezone": "UTC",
|
||||
"ntfy": {"mode": mode, "bin": str(root / "bin/ntfy"),
|
||||
"config": str(root / "data/ntfy/server.yml"), "base_url": "http://192.168.1.20:8090"},
|
||||
"web": {"node": "/bin/node", "script": str(root / "lib/web/serve.mjs"), "host": "127.0.0.1",
|
||||
"port": 8082, "auth_file": str(root / "auth.json"), "root": str(root / "lib/app-web")},
|
||||
}
|
||||
|
||||
def test_server_never_starts_without_the_web_app(self):
|
||||
for missing in ("unconfigured", "not built"):
|
||||
with self.subTest(missing=missing), tempfile.TemporaryDirectory() as directory:
|
||||
config = self.config(Path(directory))
|
||||
if missing == "unconfigured":
|
||||
config.pop("web")
|
||||
else:
|
||||
(Path(directory) / "lib/app-web/index.html").unlink()
|
||||
with patch.object(manage, "run") as run, patch.object(manage.subprocess, "Popen") as popen:
|
||||
with self.assertRaisesRegex(RuntimeError, "refusing to start the server"):
|
||||
manage.start(config)
|
||||
with self.assertRaisesRegex(RuntimeError, "refusing to start the server"):
|
||||
manage.supervise(config)
|
||||
run.assert_not_called()
|
||||
popen.assert_not_called()
|
||||
|
||||
def test_mode_selection_defaults_to_docker(self):
|
||||
self.assertEqual(manage.ntfy_mode({}), "docker")
|
||||
self.assertEqual(manage.ntfy_mode({"ntfy": {}}), "docker")
|
||||
@@ -166,8 +186,11 @@ class ManageNativeTests(unittest.TestCase):
|
||||
with self.subTest(system=system), tempfile.TemporaryDirectory() as directory:
|
||||
config = self.config(Path(directory))
|
||||
config["registration"] = str(Path(directory) / "service")
|
||||
response = MagicMock()
|
||||
response.__enter__.return_value.status = 200
|
||||
with patch.object(manage.platform, "system", return_value=system), \
|
||||
patch.object(manage, "run") as run, patch.object(manage, "wait_health"):
|
||||
patch.object(manage, "run") as run, patch.object(manage, "wait_health"), \
|
||||
patch.object(manage.urllib.request, "urlopen", return_value=response):
|
||||
manage.start(config)
|
||||
calls = [call.args[0] for call in run.call_args_list]
|
||||
if system == "Linux":
|
||||
@@ -249,7 +272,7 @@ class ManageNativeTests(unittest.TestCase):
|
||||
config = self.config(root)
|
||||
config["web"] = {"node": "/bin/node", "script": "/prefix/lib/web/serve.mjs",
|
||||
"host": "0.0.0.0", "port": 8082, "auth_file": "/private/auth.json",
|
||||
"root": "/prefix/lib/app-web", "updates": "/prefix/lib/app-updates"}
|
||||
"root": str(root / "lib/app-web"), "updates": "/prefix/lib/app-updates"}
|
||||
ntfy, server, web = MagicMock(), MagicMock(), MagicMock()
|
||||
ntfy.poll.return_value = None
|
||||
server.poll.return_value = None
|
||||
@@ -263,7 +286,7 @@ class ManageNativeTests(unittest.TestCase):
|
||||
call = popen.call_args_list[1]
|
||||
self.assertEqual(call.args[0], ["/bin/node", "/prefix/lib/web/serve.mjs", "--port", "8082",
|
||||
"--host", "0.0.0.0", "--pipelines", "127.0.0.1:8080",
|
||||
"--root", "/prefix/lib/app-web",
|
||||
"--root", str(root / "lib/app-web"),
|
||||
"--updates", "/prefix/lib/app-updates"])
|
||||
self.assertNotIn("PIPELINES_WEB_AUTH", call.kwargs["env"])
|
||||
self.assertEqual(call.kwargs["env"]["PIPELINES_WEB_AUTH_FILE"], "/private/auth.json")
|
||||
@@ -275,7 +298,7 @@ class ManageNativeTests(unittest.TestCase):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
config = self.config(Path(directory))
|
||||
config["registration"] = "/scratch/service"
|
||||
config["web"] = {"host": "0.0.0.0", "port": 8123}
|
||||
config["web"] = {"host": "0.0.0.0", "port": 8123, "root": config["web"]["root"]}
|
||||
response = MagicMock()
|
||||
response.__enter__.return_value.status = 200
|
||||
with patch.object(manage.platform, "system", return_value="Linux"), \
|
||||
|
||||
Reference in New Issue
Block a user