From 220e6e701806213a576ce80fa655cd9cf4a51880 Mon Sep 17 00:00:00 2001 From: Christophe Besson Date: Fri, 4 Sep 2026 03:58:16 +0200 Subject: feat: Windows daemon lifecycle (W3) — Startup-folder autostart MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Linux node runs under `systemctl --user`. Windows has no per-user equivalent that works without elevation: `schtasks /create /sc ONLOGON` (even `/rl LIMITED /it`) fails with "Access is denied" for a non-admin user, because a logon trigger touches machine-wide scheduler state. So autostart is a `.vbs` in the per-user Startup folder instead: CreateObject("WScript.Shell").Run Chr(34) & "" & Chr(34), 0, False wscript runs it at every sign-in, hidden (0) and non-blocking. No admin, no console window, no new dependency. Verified end to end: the launcher brings the daemon up with no window and it answers its loopback API. node/platform.py autostart_install/remove/status — write / delete / detect the launcher autostart_run/end — start now (DETACHED|NO_WINDOW) / taskkill _node_exe — PATH, then next to sys.executable, then argv[0] node/daemon.py new `autostart install|remove|start|stop|status` verb reload (win32) -> POST /api/reload on the loopback API restart-daemon (win32) -> autostart_end + autostart_run reset (win32) -> also removes the launcher client/main.js, preload.js node:autostart handler + winAutostart* helpers (kept in step with platform.py) node:service-status (win32) probes the daemon; stop/restart/start use taskkill + a detached, windowless spawn Tests: 8 autostart cases in test_platform.py (mocked sys.platform, APPDATA pointed at tmp); `autostart status` added to the CLI dispatch sweep. Full meshbay-node suite green on Windows (784 passed / 34 skipped). Still open: no CTRL_CLOSE_EVENT handler, so a bare taskkill / window close does not run _shutdown() (SetConsoleCtrlHandler, follow-up). Service mode (pywin32/NSSM) stays Phase 2. Co-Authored-By: Claude Sonnet 5 --- packages/meshbay-node/tests/test_cli_dispatch.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'packages/meshbay-node/tests/test_cli_dispatch.py') diff --git a/packages/meshbay-node/tests/test_cli_dispatch.py b/packages/meshbay-node/tests/test_cli_dispatch.py index 76eb6d5..606e586 100644 --- a/packages/meshbay-node/tests/test_cli_dispatch.py +++ b/packages/meshbay-node/tests/test_cli_dispatch.py @@ -42,6 +42,7 @@ VERBS = [ ["stun", "list"], ["reload"], ["restart-daemon"], + ["autostart", "status"], ] @@ -141,7 +142,8 @@ def test_the_verb_list_here_matches_the_parser(): @pytest.mark.skipif(sys.platform == "win32", - reason="systemd lifecycle; Windows path (schtasks) is W3, not built") + reason="systemd lifecycle; Windows uses the loopback API / " + "Startup-folder launcher, covered by test_platform.py") @pytest.mark.parametrize("argv,verb", [ (["reload"], "reload"), (["restart-daemon"], "restart"), @@ -170,7 +172,8 @@ def test_lifecycle_commands_delegate_to_systemctl_user( @pytest.mark.skipif(sys.platform == "win32", - reason="systemd lifecycle; Windows path (schtasks) is W3, not built") + reason="systemd lifecycle; Windows uses the loopback API / " + "Startup-folder launcher, covered by test_platform.py") @pytest.mark.parametrize("argv", [["reload"], ["restart-daemon"]]) def test_lifecycle_commands_report_systemctl_failure( argv, stub_daemon, monkeypatch, capsys): -- cgit v1.2.3