diff options
Diffstat (limited to 'packages/meshbay-node/tests/test_platform.py')
| -rw-r--r-- | packages/meshbay-node/tests/test_platform.py | 75 |
1 files changed, 75 insertions, 0 deletions
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() |