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.

test(packaging): request optional browser setup before frozen checks

rubenluetke10-beep00b7f8cc3fa2
diff --git a/scripts/ci/check_frozen_browser.py b/scripts/ci/check_frozen_browser.py
index 32f062974d..bf4d70e821 100644
--- a/scripts/ci/check_frozen_browser.py
+++ b/scripts/ci/check_frozen_browser.py
@@ -1,10 +1,13 @@
-"""Exercise automatic provisioning and real frames in the shipped frozen app.
+"""Exercise requested browser provisioning and real frames in the frozen app.
Run after packaging, with --executable pointing at the built launcher. Two
headless boots share a fresh scratch profile; no source imports, account keys,
desktop input, or existing user state are passed to the child application. On
macOS each boot also asks the running app for its permission status, which is
the only way to see whether its pyobjc frameworks loaded (BUG-222).
+
+Headless startup deliberately leaves the optional browser idle. The probe
+requests installation through the same authenticated API as the product UI.
"""
from __future__ import annotations
@@ -109,10 +112,10 @@ class ProbeHTTPError(RuntimeError):
super().__init__(f"Frozen probe request failed: HTTP {code}")
-def request_json(port: int, path: str, key: str) -> dict:
+def request_json(port: int, path: str, key: str, *, method: str = "GET") -> dict:
connection = http.client.HTTPConnection("127.0.0.1", port, timeout=5)
try:
- connection.request("GET", path, headers={"Authorization": f"Bearer {key}"})
+ connection.request(method, path, headers={"Authorization": f"Bearer {key}"})
response = connection.getresponse()
if response.status != 200:
raise ProbeHTTPError(response.status)
@@ -196,7 +199,7 @@ def boot(executable: Path, profile: Path, output: Path, key: str, timeout: float
port = sock.getsockname()[1]
env = isolated_env(profile, port, key)
started = time.monotonic()
- report: dict = {}
+ report: dict = {"browser_install_requested": False}
with output.with_suffix(".log").open("w", encoding="utf-8") as log:
process = subprocess.Popen(
[str(executable), "serve"],
@@ -232,13 +235,26 @@ def boot(executable: Path, profile: Path, output: Path, key: str, timeout: float
except (OSError, http.client.HTTPException):
time.sleep(1)
continue
+ if (
+ "healthy_seconds" in report
+ and not report["browser_install_requested"]
+ and not status.get("installed")
+ and not status.get("running")
+ and status.get("phase") == "idle"
+ ):
+ status = request_json(
+ port, "/api/society/browser/install", key, method="POST"
+ )
+ if not any(status.get(field) for field in ("started", "running", "installed")):
+ raise RuntimeError("Frozen app declined the requested browser setup")
+ report["browser_install_requested"] = True
phase = status.get("phase")
if phase != last_phase:
print(f"{output.name}: browser phase={phase}", flush=True)
last_phase = phase
if status.get("error"):
raise RuntimeError(
- "Frozen app automatic browser provisioning failed; inspect its log"
+ "Frozen app browser provisioning failed; inspect its log"
)
if status.get("installed") and "healthy_seconds" in report:
report["browser_ready_seconds"] = round(time.monotonic() - started, 3)
@@ -246,7 +262,7 @@ def boot(executable: Path, profile: Path, output: Path, key: str, timeout: float
return report
time.sleep(1)
raise TimeoutError(
- "Frozen app did not automatically prepare its browser before the deadline"
+ "Frozen app did not prepare the requested browser before the deadline"
)
finally:
stop_owned_tree(process)
diff --git a/tests/fakes/fake_frozen_browser.py b/tests/fakes/fake_frozen_browser.py
new file mode 100644
index 0000000000..a9dbd9267f
--- /dev/null
+++ b/tests/fakes/fake_frozen_browser.py
@@ -0,0 +1,42 @@
+"""An API-only frozen app with explicitly requested browser provisioning."""
+
+
+class FrozenBrowserApp:
+ def __init__(self, *, installed=False, running=False, refuse=False):
+ self.installed = installed
+ self.running = running
+ self.refuse = refuse
+ self.polls = 0
+ self.requests = []
+ self.frames = []
+ self.stopped = []
+
+ def poll(self):
+ return None
+
+ def request(self, port, path, key, *, method="GET"):
+ self.requests.append((method, path, key))
+ if path == "/api/health":
+ return {"ok": True, "instance": "dev"}
+ if path == "/api/society/browser/install" and method == "POST":
+ if self.refuse:
+ return {"started": False, "phase": "idle"}
+ self.running = True
+ return {"started": True, "running": True, "phase": "checking"}
+ if path == "/api/society/browser/status" and method == "GET":
+ if self.running:
+ self.polls += 1
+ if self.polls >= 2:
+ self.installed = True
+ self.running = False
+ return {
+ "installed": self.installed,
+ "running": self.running,
+ "phase": "done" if self.installed else "checking" if self.running else "idle",
+ }
+ raise AssertionError(f"Unexpected probe request: {method} {path}")
+
+ def capture(self, port, key, output):
+ assert self.installed, "The probe must await installation before checking frames"
+ self.frames.append(output)
+ return {"width": 640, "height": 480}
diff --git a/tests/unit/packaging/test_frozen_browser_smoke.py b/tests/unit/packaging/test_frozen_browser_smoke.py
index eb68548e8c..94b5f4d30c 100644
--- a/tests/unit/packaging/test_frozen_browser_smoke.py
+++ b/tests/unit/packaging/test_frozen_browser_smoke.py
@@ -9,6 +9,7 @@ import pytest
from jarvis.core.instance import DEV_PORT_OFFSET
from scripts.ci import check_frozen_browser as probe
+from tests.fakes.fake_frozen_browser import FrozenBrowserApp
def test_probe_does_not_inherit_account_or_runtime_credentials(tmp_path, monkeypatch):
@@ -23,13 +24,16 @@ def test_probe_does_not_inherit_account_or_runtime_credentials(tmp_path, monkeyp
assert env["PYTHON_KEYRING_BACKEND"] == "keyring.backends.null.Keyring"
-def test_probe_refuses_http_redirect_instead_of_forwarding_its_key():
[email protected]("method", ["GET", "POST"])
+def test_probe_refuses_http_redirect_instead_of_forwarding_its_key(method):
class Redirect(BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(302)
self.send_header("Location", "http://127.0.0.1:1/unrelated")
self.end_headers()
+ do_POST = do_GET
+
def log_message(self, *_args):
pass # Test traffic is intentionally quiet.
@@ -38,7 +42,7 @@ def test_probe_refuses_http_redirect_instead_of_forwarding_its_key():
thread.start()
try:
with pytest.raises(probe.ProbeHTTPError) as error:
- probe.request_json(server.server_port, "/api/health", "test-key")
+ probe.request_json(server.server_port, "/api/health", "test-key", method=method)
assert error.value.code == 302
finally:
server.shutdown()
@@ -46,6 +50,42 @@ def test_probe_refuses_http_redirect_instead_of_forwarding_its_key():
server.server_close()
+def _boot_simulated_app(tmp_path, monkeypatch, app):
+ profile = tmp_path / "profile"
+ profile.mkdir()
+ monkeypatch.setattr(probe.subprocess, "Popen", lambda *_args, **_kwargs: app)
+ monkeypatch.setattr(probe, "request_json", app.request)
+ monkeypatch.setattr(probe, "check_macos_permissions", lambda *_args: {})
+ monkeypatch.setattr(probe, "capture_frame", app.capture)
+ monkeypatch.setattr(probe, "stop_owned_tree", app.stopped.append)
+ monkeypatch.setattr(probe.time, "sleep", lambda _seconds: None)
+ return probe.boot(tmp_path / "launcher", profile, tmp_path / "boot", "test-key", timeout=5)
+
+
[email protected]("installed,running", [(False, False), (True, False), (False, True)])
+def test_probe_requests_optional_setup_once_and_still_requires_a_frame(
+ tmp_path, monkeypatch, installed, running,
+):
+ app = FrozenBrowserApp(installed=installed, running=running)
+ report = _boot_simulated_app(tmp_path, monkeypatch, app)
+ posts = [request for request in app.requests if request[0] == "POST"]
+ assert posts == (
+ [] if installed or running else [("POST", "/api/society/browser/install", "test-key")]
+ )
+ assert report["browser_install_requested"] is (not installed and not running)
+ assert len(app.frames) == 1
+ assert app.stopped == [app]
+ assert report["width"] == 640
+
+
+def test_probe_refuses_to_accept_an_ignored_install_request(tmp_path, monkeypatch):
+ app = FrozenBrowserApp(refuse=True)
+ with pytest.raises(RuntimeError, match="declined the requested browser setup"):
+ _boot_simulated_app(tmp_path, monkeypatch, app)
+ assert app.frames == []
+ assert app.stopped == [app]
+
+
def test_failed_stream_cannot_count_as_first_frame(tmp_path, monkeypatch):
class FailedViewer:
def __enter__(self):