Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

fix(setup): frozen builds never touch the installer's shell registration

rubenluetke10-beep00e21f6e5746
diff --git a/jarvis/setup/desktop_integration.py b/jarvis/setup/desktop_integration.py
index 262f2cc087..0c24498a20 100644
--- a/jarvis/setup/desktop_integration.py
+++ b/jarvis/setup/desktop_integration.py
@@ -14,6 +14,17 @@ Installer, updater, first desktop boot, and uninstaller all call this module so
an update cannot move the code while leaving its launcher behind. Registration
is restricted to installer-managed trees by default; a developer checkout must
never acquire an uninstall entry which could delete the checkout.
+
+**A frozen build registers nothing.** When Personal Jarvis arrived through a
+native installer (Windows ``Setup.exe``, macOS ``.dmg``, Linux ``.AppImage`` or
+``.deb``) that installer owns every shell artifact: it created the Start-menu
+entry, the ``Applications`` bundle, the ``.desktop`` file and the uninstall
+record, and it removes them again on uninstall. Registering a second time from
+inside the app would overwrite a working launcher with one built for the
+source-install layout (``<interpreter> -m jarvis.ui.web.launcher``), which a
+frozen executable cannot run at all — and on the removal path it would delete
+shortcuts this app never created. Every entry point here is therefore a quiet,
+logged no-op under :func:`jarvis.core.frozen.is_frozen`.
"""
from __future__ import annotations
@@ -41,9 +52,15 @@ from jarvis.core.branding import (
from jarvis.core.branding import (
WINDOWS_UNINSTALL_REGISTRY_SUBKEY as WINDOWS_UNINSTALL_SUBKEY,
)
+from jarvis.core.frozen import is_frozen
log = logging.getLogger(__name__)
+#: ``skipped_reason`` reported when a native-installer build declines to touch
+#: the shell. A constant rather than a literal so the installer, the tests and
+#: the ``--json`` contract cannot drift apart.
+FROZEN_SKIP_REASON = "native installer owns desktop registration"
+
def _windows_aumid_subkey(aumid: str) -> str:
return rf"Software\Classes\AppUserModelId\{aumid}"
@@ -302,10 +319,31 @@ def ensure_desktop_integration(
macos_applications_dir: Path | None = None,
linux_applications_dir: Path | None = None,
) -> DesktopIntegrationReport:
- """Install or repair the current platform's desktop-shell artifacts."""
+ """Install or repair the current platform's desktop-shell artifacts.
+
+ Returns an ``attempted=False`` report on a frozen build: the native
+ installer already registered the app and nothing here may touch it.
+ """
- root = (install_dir or _install_root()).resolve()
plat = _platform(platform)
+ # Before any path work: ``_install_root()`` would resolve to a directory
+ # inside the frozen bundle, and every answer derived from it would be about
+ # a tree the installer owns rather than one this module may write to.
+ if is_frozen():
+ log.info(
+ "Desktop integration skipped: %s was installed by a native "
+ "installer, which owns the shell registration.",
+ PRODUCT_NAME,
+ )
+ return DesktopIntegrationReport(
+ platform=plat,
+ managed=False,
+ attempted=False,
+ ok=True,
+ skipped_reason=FROZEN_SKIP_REASON,
+ )
+
+ root = (install_dir or _install_root()).resolve()
managed = is_managed_install(root)
if require_managed and not managed:
return DesktopIntegrationReport(
@@ -431,9 +469,30 @@ def remove_desktop_integration(
macos_applications_dir: Path | None = None,
linux_applications_dir: Path | None = None,
) -> DesktopIntegrationReport:
- """Remove the current platform's external desktop-shell artifacts."""
+ """Remove the current platform's external desktop-shell artifacts.
+
+ Returns an ``attempted=False`` report on a frozen build. This is the half
+ that would do real damage: the Start-menu entry, the ``Applications``
+ bundle and the ``.desktop`` file of a native install belong to the
+ installer's uninstaller, and deleting them from inside the app would leave
+ an installed product with no way to start it.
+ """
plat = _platform(platform)
+ if is_frozen():
+ log.info(
+ "Desktop cleanup skipped: %s was installed by a native installer, "
+ "which removes its own shell registration on uninstall.",
+ PRODUCT_NAME,
+ )
+ return DesktopIntegrationReport(
+ platform=plat,
+ managed=False,
+ attempted=False,
+ ok=True,
+ skipped_reason=FROZEN_SKIP_REASON,
+ )
+
warnings: list[str] = []
artifacts: list[str] = []
if plat == "windows":
@@ -524,6 +583,7 @@ if __name__ == "__main__": # pragma: no cover
__all__ = [
"DesktopIntegrationReport",
+ "FROZEN_SKIP_REASON",
"MANAGED_MARKER",
"WINDOWS_APP_USER_MODEL_ID",
"WINDOWS_UNINSTALL_SUBKEY",
diff --git a/jarvis/ui/icon_utils.py b/jarvis/ui/icon_utils.py
index 65b12f2aad..e8c32892fc 100644
--- a/jarvis/ui/icon_utils.py
+++ b/jarvis/ui/icon_utils.py
@@ -71,6 +71,31 @@ _LAUNCHER_MODULE = "jarvis.ui.web.launcher"
# IID_IPropertyStore — the COM interface for reading/writing a .lnk's AUMID.
_IID_IPROPERTYSTORE = "{886D8EEB-8CF2-4446-8D02-CDBA1DBDCF99}"
+
+def _installer_owns_shell_registration(artifact: str) -> bool:
+ """True when a native installer owns ``artifact`` and this app must not.
+
+ Every shell artifact written in this module relaunches Jarvis as
+ ``<interpreter> -m jarvis.ui.web.launcher`` — the source-install shape. A
+ PyInstaller executable cannot run that command line, and inside an AppImage
+ the interpreter path points into a mount that disappears when the app
+ exits, so the entry would be broken twice over. The native installers
+ (``Setup.exe``, ``.dmg``, ``.deb``/AppImage integration) create the real
+ launcher and remove it again on uninstall; this app only has to keep its
+ hands off it. See ``jarvis/setup/desktop_integration.py`` for the same rule
+ on the registration lifecycle as a whole.
+ """
+ from jarvis.core.frozen import is_frozen
+
+ if not is_frozen():
+ return False
+ logger.debug(
+ "{} not written: this is a native-installer build and the installer "
+ "owns the shell registration.",
+ artifact,
+ )
+ return True
+
# A per-install copy of ``pythonw.exe`` (next to the interpreter, or in the
# per-user ``%LOCALAPPDATA%\PersonalJarvis\bin`` when the base dir is read-only),
# carrying the Jarvis mascot as its EMBEDDED icon. On Windows the taskbar button of
@@ -703,9 +728,17 @@ def ensure_start_menu_shortcut(
exact interpreter is left alone), Windows-only, best-effort - it never
raises and never blocks boot. Returns ``True`` only when a matching shortcut
is present afterwards.
+
+ A frozen build writes nothing: the shortcut it would create points at
+ ``<interpreter> -m jarvis.ui.web.launcher``, a command a PyInstaller
+ executable cannot run, and the native installer already placed a working
+ one. The self-heal below would otherwise replace the installer's launcher
+ with a broken one on every boot.
"""
if sys.platform != "win32":
return False
+ if _installer_owns_shell_registration("Start-Menu shortcut"):
+ return False
programs = programs_dir or _default_start_menu_programs_dir()
if programs is None:
return False
@@ -859,9 +892,15 @@ def ensure_desktop_shortcut(
``create_if_missing=False`` repairs an existing shortcut but never
resurrects a deleted one — a user who threw the icon away keeps their empty
desktop. The installer passes ``True``; incidental callers should not.
+
+ A frozen build writes nothing — see :func:`ensure_start_menu_shortcut`; the
+ native installer owns the Desktop icon too, including the user's choice not
+ to have one.
"""
if sys.platform != "win32":
return False
+ if _installer_owns_shell_registration("Desktop shortcut"):
+ return False
desktop = desktop_dir or _default_desktop_dir()
if desktop is None or not desktop.is_dir():
return False
@@ -1432,7 +1471,15 @@ def ensure_linux_desktop_entry(applications_dir: Path | None = None) -> bool:
Pure ``pathlib`` text I/O, idempotent (rewritten only when the rendered
content changed), best-effort — never raises, never blocks the window.
``applications_dir`` is a test seam; without it, non-Linux is a no-op.
+
+ A frozen build writes nothing. Inside an AppImage ``sys.executable`` points
+ into a temporary mount that is gone the moment the app exits, so the entry
+ would launch nothing at all; the AppImage's own ``.desktop`` (built by
+ ``packaging/linux/build.sh``) and the Debian package are what register the
+ app there.
"""
+ if _installer_owns_shell_registration("Linux application-menu entry"):
+ return False
if applications_dir is None:
if sys.platform != "linux":
return False
diff --git a/tests/unit/setup/test_desktop_integration.py b/tests/unit/setup/test_desktop_integration.py
index 7992e25216..3903cc0a87 100644
--- a/tests/unit/setup/test_desktop_integration.py
+++ b/tests/unit/setup/test_desktop_integration.py
@@ -246,3 +246,137 @@ def test_desktop_boot_repairs_registration_after_first_paint() -> None:
source = inspect.getsource(desktop_app.DesktopApp._inject_token)
assert "_start_desktop_integration_repair" in source
+
+
+# --- Frozen (native-installer) builds ---------------------------------------
+#
+# A native installer (Windows Setup.exe, macOS .dmg, Linux .AppImage/.deb)
+# creates the Start-menu entry, the Applications bundle and the .desktop file,
+# and removes them again on uninstall. Two things must therefore never happen
+# from inside a frozen app: writing a second, source-shaped launcher over the
+# installer's working one (a frozen executable cannot run
+# "<interpreter> -m jarvis.ui.web.launcher" at all), and deleting an artifact
+# it did not create.
+
+
+def _freeze(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> None:
+ """Make ``jarvis.core.frozen.is_frozen()`` report a PyInstaller onedir bundle."""
+
+ internal = tmp_path / "bundle" / "_internal"
+ internal.mkdir(parents=True)
+ monkeypatch.setattr(sys, "frozen", True, raising=False)
+ monkeypatch.setattr(sys, "_MEIPASS", str(internal), raising=False)
+
+
[email protected]("platform", ["win32", "darwin", "linux"])
+def test_frozen_install_registers_nothing(
+ platform: str, tmp_path: Path, monkeypatch: pytest.MonkeyPatch
+) -> None:
+ _freeze(monkeypatch, tmp_path)
+ # Deliberately a MANAGED tree: the frozen probe has to win even over the
+ # marker that normally authorizes registration.
+ root = _managed_root(tmp_path)
+ apps = tmp_path / "applications"
+ programs = tmp_path / "Programs"
+
+ report = di.ensure_desktop_integration(
+ install_dir=root,
+ platform=platform,
+ windows_programs_dir=programs,
+ windows_desktop_dir=tmp_path / "Desktop",
+ windows_registry_subkey=rf"Software\PersonalJarvisTests\Frozen\{tmp_path.name}",
+ windows_aumid=f"PersonalJarvis.Test.Frozen.{tmp_path.name}",
+ macos_applications_dir=apps,
+ linux_applications_dir=apps,
+ )
+
+ assert report.attempted is False
+ assert report.ok is True
+ assert report.artifacts == ()
+ assert report.skipped_reason == di.FROZEN_SKIP_REASON
+ assert not apps.exists()
+ assert not programs.exists()
+
+
[email protected]("platform", ["win32", "darwin", "linux"])
+def test_frozen_uninstall_leaves_the_installers_artifacts_alone(
+ platform: str, tmp_path: Path, monkeypatch: pytest.MonkeyPatch
+) -> None:
+ _freeze(monkeypatch, tmp_path)
+ apps = tmp_path / "applications"
+ apps.mkdir()
+ entry = apps / "personal-jarvis.desktop"
+ entry.write_text("[Desktop Entry]\n", encoding="utf-8")
+ bundle_plist = apps / "Personal Jarvis.app" / "Contents" / "Info.plist"
+ bundle_plist.parent.mkdir(parents=True)
+ bundle_plist.write_text("<plist/>\n", encoding="utf-8")
+ programs = tmp_path / "Programs"
+ programs.mkdir()
+ shortcut = programs / "Personal Jarvis.lnk"
+ shortcut.write_bytes(b"the installer's own launcher")
+
+ report = di.remove_desktop_integration(
+ platform=platform,
+ windows_programs_dir=programs,
+ windows_desktop_dir=tmp_path / "Desktop",
+ windows_registry_subkey=rf"Software\PersonalJarvisTests\Frozen\{tmp_path.name}",
+ windows_aumid=f"PersonalJarvis.Test.Frozen.{tmp_path.name}",
+ macos_applications_dir=apps,
+ linux_applications_dir=apps,
+ )
+
+ assert report.attempted is False
+ assert report.ok is True
+ assert report.artifacts == ()
+ assert report.skipped_reason == di.FROZEN_SKIP_REASON
+ # Deleting these would leave an installed product with no way to start it.
+ assert entry.is_file()
+ assert bundle_plist.is_file()
+ assert shortcut.read_bytes() == b"the installer's own launcher"
+
+
+def test_frozen_build_writes_no_linux_application_entry(
+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch
+) -> None:
+ # Runs on every OS: the applications_dir seam is what makes the writer
+ # reachable off Linux, and inside an AppImage sys.executable points into a
+ # mount that is gone the moment the app exits - so the entry this would
+ # write launches nothing at all.
+ from jarvis.ui import icon_utils
+
+ _freeze(monkeypatch, tmp_path)
+ apps = tmp_path / "applications"
+
+ assert icon_utils.ensure_linux_desktop_entry(applications_dir=apps) is False
+ assert not apps.exists()
+
+
+def test_windows_shortcut_writers_consult_the_frozen_guard() -> None:
+ from jarvis.ui import icon_utils
+
+ for writer in (
+ icon_utils.ensure_start_menu_shortcut,
+ icon_utils.ensure_desktop_shortcut,
+ ):
+ source = inspect.getsource(writer)
+ assert "_installer_owns_shell_registration" in source, writer.__name__
+
+
[email protected](sys.platform != "win32", reason="Windows shell links only")
+def test_frozen_windows_build_does_not_touch_the_installers_shortcut(
+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch
+) -> None:
+ from jarvis.ui import icon_utils
+
+ _freeze(monkeypatch, tmp_path)
+ programs = tmp_path / "Programs"
+ programs.mkdir()
+ installer_lnk = programs / icon_utils.START_MENU_SHORTCUT_NAME
+ installer_lnk.write_bytes(b"the installer's own launcher")
+ desktop = tmp_path / "Desktop"
+ desktop.mkdir()
+
+ assert icon_utils.ensure_start_menu_shortcut(programs_dir=programs) is False
+ assert icon_utils.ensure_desktop_shortcut(desktop_dir=desktop) is False
+ assert installer_lnk.read_bytes() == b"the installer's own launcher"
+ assert not (desktop / icon_utils.START_MENU_SHORTCUT_NAME).exists()