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.

feat(core): shared frozen-install probe for the native installer path

rubenluetke10-beep91fd57cf18dc
diff --git a/jarvis/core/frozen.py b/jarvis/core/frozen.py
new file mode 100644
index 0000000000..d621a433cd
--- /dev/null
+++ b/jarvis/core/frozen.py
@@ -0,0 +1,53 @@
+"""Where this process was installed from — the ONE probe every layer shares.
+
+Three install kinds exist, and each one ships a different update path:
+
+* ``frozen`` — a PyInstaller bundle distributed as a native installer
+ (Windows ``Setup.exe``, macOS ``.dmg``, Linux ``.AppImage``). PyInstaller
+ sets ``sys.frozen`` and ``sys._MEIPASS`` (the bundled-resources root).
+ Updates arrive as a new installer asset from the GitHub Release, never
+ through git.
+* ``managed`` — the one-line installer's git checkout under
+ ``~/.personal-jarvis`` (marker file + official origin; the probe lives in
+ ``jarvis/ui/web/update_routes.py``). Updates are ``git fetch`` + reinstall.
+* ``dev`` — anything else: a maintainer checkout, a fork, a plain
+ ``pip install``. Never self-updates.
+
+This module is pure stdlib and imports nothing from ``jarvis`` so it can sit
+on the boot critical path (AP-26) and be tested on any OS by patching ``sys``.
+"""
+
+from __future__ import annotations
+
+import sys
+from pathlib import Path
+
+__all__ = ["bundle_root", "is_frozen", "resources_root"]
+
+
+def is_frozen() -> bool:
+ """True when running from a PyInstaller bundle (``sys.frozen`` + ``_MEIPASS``)."""
+ return bool(getattr(sys, "frozen", False)) and hasattr(sys, "_MEIPASS")
+
+
+def bundle_root() -> Path | None:
+ """Directory that holds the frozen executable (the ``onedir`` layout).
+
+ This is where an installer placed the app — the directory a Windows
+ uninstaller removes, the ``Contents/MacOS`` folder inside an ``.app``, or
+ the AppImage's mounted ``usr/bin``. ``None`` outside a frozen bundle.
+ """
+ if not is_frozen():
+ return None
+ return Path(sys.executable).resolve().parent
+
+
+def resources_root() -> Path | None:
+ """Root of the bundled data files (``sys._MEIPASS``); ``None`` when not frozen.
+
+ In the ``onedir`` layout this is ``<bundle_root>/_internal``; the
+ package-relative ``datas`` from ``jarvis.spec`` resolve beneath it.
+ """
+ if not is_frozen():
+ return None
+ return Path(getattr(sys, "_MEIPASS")).resolve() # noqa: B009 — attribute is injected at runtime
diff --git a/tests/unit/core/test_frozen.py b/tests/unit/core/test_frozen.py
new file mode 100644
index 0000000000..7c8bb93a19
--- /dev/null
+++ b/tests/unit/core/test_frozen.py
@@ -0,0 +1,40 @@
+"""``jarvis.core.frozen`` — the install-kind probe, exercised by patching ``sys``."""
+
+from __future__ import annotations
+
+import sys
+from pathlib import Path
+
+import pytest
+
+from jarvis.core import frozen
+
+
+def test_not_frozen_in_a_plain_interpreter() -> None:
+ assert frozen.is_frozen() is False
+ assert frozen.bundle_root() is None
+ assert frozen.resources_root() is None
+
+
+def test_frozen_needs_both_pyinstaller_markers(monkeypatch: pytest.MonkeyPatch) -> None:
+ # ``sys.frozen`` alone (cx_Freeze, py2exe) is not a PyInstaller bundle.
+ monkeypatch.setattr(sys, "frozen", True, raising=False)
+ assert frozen.is_frozen() is False
+
+ monkeypatch.setattr(sys, "_MEIPASS", "/somewhere/_internal", raising=False)
+ assert frozen.is_frozen() is True
+
+
+def test_roots_follow_the_onedir_layout(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> None:
+ bundle = tmp_path / "Jarvis"
+ internal = bundle / "_internal"
+ internal.mkdir(parents=True)
+ exe = bundle / ("Jarvis.exe" if sys.platform == "win32" else "Jarvis")
+ exe.write_bytes(b"")
+
+ monkeypatch.setattr(sys, "frozen", True, raising=False)
+ monkeypatch.setattr(sys, "_MEIPASS", str(internal), raising=False)
+ monkeypatch.setattr(sys, "executable", str(exe))
+
+ assert frozen.bundle_root() == bundle.resolve()
+ assert frozen.resources_root() == internal.resolve()