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: make Computer-Use and window-state tests/code deterministic on real macOS hosts

Joana Lütke45079350c71f
diff --git a/jarvis/platform/window_state.py b/jarvis/platform/window_state.py
index 3c07a7a67d..f7582bc9db 100644
--- a/jarvis/platform/window_state.py
+++ b/jarvis/platform/window_state.py
@@ -28,6 +28,7 @@ from __future__ import annotations
import logging
import os
+import re
import shutil
import subprocess
import time
@@ -712,7 +713,10 @@ def _app_token(app_name: str) -> str:
if not name:
return ""
if ("\\" in name) or ("/" in name) or name.lower().endswith(".exe"):
- base = os.path.basename(name)
+ # Split on BOTH separators: a Windows-style path must resolve to its
+ # basename on macOS/Linux too (os.path.basename only splits the
+ # host's own separator, leaving the full path as a dead token).
+ base = re.split(r"[\\/]", name)[-1]
stem = base.rsplit(".", 1)[0] if "." in base else base
name = stem or name
return name.strip()
diff --git a/jarvis/plugins/tool/type_text.py b/jarvis/plugins/tool/type_text.py
index a15bd40a17..2a5cb5877f 100644
--- a/jarvis/plugins/tool/type_text.py
+++ b/jarvis/plugins/tool/type_text.py
@@ -53,27 +53,38 @@ def _build_windows_input_types() -> Any:
Lazily imported so the module still imports on non-Windows hosts.
"""
import ctypes
- from ctypes import wintypes
from types import SimpleNamespace
- ULONG_PTR = wintypes.WPARAM
+ # Fixed-width types matching the Win32 ABI on every host. ctypes.wintypes
+ # aliases (LONG=c_long, DWORD=c_ulong) inflate to 8 bytes on LP64
+ # macOS/Linux, silently changing the struct layout the cross-platform
+ # cbSize parity test guards. On Windows these are byte-identical to the
+ # wintypes definitions (AD-7).
+ WORD = ctypes.c_uint16
+ DWORD = ctypes.c_uint32
+ LONG = ctypes.c_int32
+ ULONG_PTR = (
+ ctypes.c_uint64
+ if ctypes.sizeof(ctypes.c_void_p) == 8
+ else ctypes.c_uint32
+ )
class KEYBDINPUT(ctypes.Structure):
_fields_ = (
- ("wVk", wintypes.WORD),
- ("wScan", wintypes.WORD),
- ("dwFlags", wintypes.DWORD),
- ("time", wintypes.DWORD),
+ ("wVk", WORD),
+ ("wScan", WORD),
+ ("dwFlags", DWORD),
+ ("time", DWORD),
("dwExtraInfo", ULONG_PTR),
)
class MOUSEINPUT(ctypes.Structure):
_fields_ = (
- ("dx", wintypes.LONG),
- ("dy", wintypes.LONG),
- ("mouseData", wintypes.DWORD),
- ("dwFlags", wintypes.DWORD),
- ("time", wintypes.DWORD),
+ ("dx", LONG),
+ ("dy", LONG),
+ ("mouseData", DWORD),
+ ("dwFlags", DWORD),
+ ("time", DWORD),
("dwExtraInfo", ULONG_PTR),
)
@@ -84,7 +95,7 @@ def _build_windows_input_types() -> Any:
_fields_ = (("mi", MOUSEINPUT), ("ki", KEYBDINPUT))
class INPUT(ctypes.Structure):
- _fields_ = (("type", wintypes.DWORD), ("union", INPUT_UNION))
+ _fields_ = (("type", DWORD), ("union", INPUT_UNION))
return SimpleNamespace(
KEYBDINPUT=KEYBDINPUT,
diff --git a/pyproject.toml b/pyproject.toml
index 29cea889fa..67936214c1 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -616,4 +616,5 @@ markers = [
"eval: Phase-8.6 Eval-Harness — Golden-Query-Suite (manuell via `pytest -m eval`).",
"slow: Lang laufende Tests (Eval, E2E) — vom Standard-Run via `pytest -m 'not slow'` ausgeschlossen.",
"integration: Integration tests that spawn real subprocesses or hit live external services (e.g. Codex CLI ChatGPT OAuth). Self-skip when prerequisites are missing; run explicitly via `pytest -m integration`.",
+ "real_tcc_gate: opts a Computer-Use test back into the real macOS Screen-Recording gate that tests/unit/cu/conftest.py neutralizes by default.",
]
diff --git a/tests/unit/cu/conftest.py b/tests/unit/cu/conftest.py
new file mode 100644
index 0000000000..581b65fea6
--- /dev/null
+++ b/tests/unit/cu/conftest.py
@@ -0,0 +1,34 @@
+"""Computer-Use unit-test fixtures.
+
+The capture path probes the LIVE macOS Screen-Recording TCC state before
+every grab (``_require_macos_screen_recording_permission``). These unit tests
+drive capture/engine logic through injected fake grabbers — the real TCC
+state of the host must not decide their outcome (CI runners and dev shells
+have no grant, so every capture-touching test would fail on real darwin
+hosts while passing everywhere else). The gate's own behavior is covered by
+``tests/unit/cu/test_capture_permission_gate``-style tests that patch the
+permission port explicitly.
+"""
+
+from __future__ import annotations
+
+import pytest
+
+
[email protected](autouse=True)
+def _screen_recording_gate_open(
+ request: pytest.FixtureRequest, monkeypatch: pytest.MonkeyPatch
+) -> None:
+ """Neutralize the live TCC probe; a no-op off darwin by design.
+
+ Tests that exercise the gate itself opt back in with
+ ``@pytest.mark.real_tcc_gate`` (they fake the permission port and the
+ platform explicitly, so they stay deterministic on every host).
+ """
+ if request.node.get_closest_marker("real_tcc_gate"):
+ return
+ import jarvis.cu.capture as capture
+
+ monkeypatch.setattr(
+ capture, "_require_macos_screen_recording_permission", lambda: None
+ )
diff --git a/tests/unit/cu/test_capture.py b/tests/unit/cu/test_capture.py
index a0def63bf1..9bd4b5b189 100644
--- a/tests/unit/cu/test_capture.py
+++ b/tests/unit/cu/test_capture.py
@@ -81,6 +81,7 @@ def test_stable_screen_returns_after_one_regrab():
assert frame.jpeg[:2] == b"\xff\xd8" # JPEG magic
def test_macos_screen_recording_denial_stops_before_grab(monkeypatch):
from jarvis.platform.permissions import PermissionState
@@ -110,6 +111,7 @@ def test_macos_screen_recording_denial_stops_before_grab(monkeypatch):
assert calls == {"grab": 0, "probe": 1}
def test_macos_screen_recording_is_rechecked_before_each_grab(monkeypatch):
from jarvis.platform.permissions import PermissionState
diff --git a/tests/unit/platform/test_window_state.py b/tests/unit/platform/test_window_state.py
index 133f6bbc57..bc2fa214df 100644
--- a/tests/unit/platform/test_window_state.py
+++ b/tests/unit/platform/test_window_state.py
@@ -299,6 +299,10 @@ def test_get_foreground_title_never_raises(monkeypatch):
def test_get_foreground_title_macos_empty_without_tool(monkeypatch):
monkeypatch.setattr(ws, "detect_platform", lambda: "darwin")
monkeypatch.setattr("shutil.which", lambda n: None)
+ # Block the native backends so the degrade path is exercised even on a
+ # real macOS host where pyobjc is installed.
+ monkeypatch.setitem(sys.modules, "AppKit", None)
+ monkeypatch.setitem(sys.modules, "Quartz", None)
assert ws.get_foreground_title() == ""
diff --git a/tests/unit/platform/test_window_state_rects.py b/tests/unit/platform/test_window_state_rects.py
index 73f7d1c255..f4920b680f 100644
--- a/tests/unit/platform/test_window_state_rects.py
+++ b/tests/unit/platform/test_window_state_rects.py
@@ -62,6 +62,9 @@ def test_macos_frame_rect_resolves_by_window_number(monkeypatch):
def test_macos_foreground_window_is_first_normal_layer_window(monkeypatch):
monkeypatch.setattr(ws, "detect_platform", lambda: "darwin")
+ # Block real AppKit so the frontmost-pid probe stays neutral and the fake
+ # Quartz list decides the result on macOS hosts too.
+ monkeypatch.setitem(sys.modules, "AppKit", None)
monkeypatch.setitem(
sys.modules, "Quartz", _fake_quartz([_OVERLAY, _MAIL_WINDOW]),
)