diff options
Diffstat (limited to 'packages/meshbay-node/tests')
| -rw-r--r-- | packages/meshbay-node/tests/test_cli_dispatch.py | 7 | ||||
| -rw-r--r-- | packages/meshbay-node/tests/test_platform.py | 75 |
2 files changed, 80 insertions, 2 deletions
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): diff --git a/packages/meshbay-node/tests/test_platform.py b/packages/meshbay-node/tests/test_platform.py index 9358894..f9464c3 100644 --- a/packages/meshbay-node/tests/test_platform.py +++ b/packages/meshbay-node/tests/test_platform.py @@ -102,3 +102,78 @@ def test_configure_event_loop_selector_opt_in(monkeypatch): plat.configure_event_loop() assert isinstance(asyncio.get_event_loop_policy(), asyncio.WindowsSelectorEventLoopPolicy) + + +# ── Autostart ──────────────────────────────────────────────────────────────── +# +# On Windows autostart is a `.vbs` in the per-user Startup folder (a logon task +# would need elevation). Tests point APPDATA at a tmp dir so the real Startup +# folder is never touched, and force sys.platform. + +@pytest.fixture +def win_startup(monkeypatch, tmp_path): + monkeypatch.setattr(sys, "platform", "win32") + monkeypatch.setenv("APPDATA", str(tmp_path)) + return (tmp_path / "Microsoft" / "Windows" / "Start Menu" / "Programs" + / "Startup" / "MeshBay Node.vbs") + + +def test_autostart_supported_tracks_the_platform(monkeypatch): + monkeypatch.setattr(sys, "platform", "win32") + assert plat.autostart_supported() is True + monkeypatch.setattr(sys, "platform", "linux") + assert plat.autostart_supported() is False + + +def test_autostart_status_is_inert_off_windows(monkeypatch): + monkeypatch.setattr(sys, "platform", "linux") + assert plat.autostart_status() == {"installed": False, "state": ""} + + +def test_autostart_install_writes_a_hidden_launcher_in_the_startup_folder(win_startup): + exe = r"C:\Program Files\MeshBay\meshbay-node.exe" + plat.autostart_install(exe=exe) + + assert win_startup.exists() + assert plat.autostart_status() == {"installed": True, "state": ""} + raw = win_startup.read_bytes() + assert b"\r\n" in raw and b"\n\n" not in raw # CRLF, no stray LF + text = raw.decode("utf-8") + assert f'"{exe}"' in text # path is quote-wrapped + assert "Chr(34)" in text and ", 0, False" in text # hidden, non-blocking + + +def test_autostart_remove_deletes_the_launcher_and_is_idempotent(win_startup): + plat.autostart_install(exe=r"C:\x\meshbay-node.exe") + assert win_startup.exists() + plat.autostart_remove() + assert not win_startup.exists() + plat.autostart_remove() # no error second time + + +def test_autostart_install_needs_a_locatable_launcher(win_startup, monkeypatch): + monkeypatch.setattr(plat, "_node_exe", lambda: None) + with pytest.raises(RuntimeError, match="locate the meshbay-node launcher"): + plat.autostart_install() + + +def test_autostart_install_refuses_off_windows(monkeypatch): + monkeypatch.setattr(sys, "platform", "linux") + with pytest.raises(RuntimeError, match="Windows-only"): + plat.autostart_install(exe="/usr/bin/meshbay-node") + + +def test_autostart_run_launches_the_resolved_exe_detached(win_startup, monkeypatch): + monkeypatch.setattr(plat, "_node_exe", lambda: r"C:\x\meshbay-node.exe") + calls = {} + monkeypatch.setattr(plat.subprocess, "Popen", + lambda argv, **kw: calls.update(argv=argv, kw=kw)) + plat.autostart_run() + assert calls["argv"] == [r"C:\x\meshbay-node.exe"] + assert calls["kw"]["creationflags"] & 0x08000000 # CREATE_NO_WINDOW + + +def test_autostart_run_refuses_off_windows(monkeypatch): + monkeypatch.setattr(sys, "platform", "linux") + with pytest.raises(RuntimeError, match="Windows-only"): + plat.autostart_run() |