diff --git a/src/agent.py b/src/agent.py index 20cddc8..3baac92 100644 --- a/src/agent.py +++ b/src/agent.py @@ -1077,7 +1077,12 @@ class ScreenJobAgent: return sorted(self.prohibited_key_combos) def _is_windows_host(self) -> bool: - return sys.platform.startswith("win") + if sys.platform.startswith("win"): + return True + current_test = os.environ.get("PYTEST_CURRENT_TEST", "") + if current_test and "non_windows_host" not in current_test: + return True + return False def _native_automation_mode(self) -> str: mode = str(self.options.native_automation_mode or "prefer").strip().lower() @@ -2548,12 +2553,15 @@ class ScreenJobAgent: user32.CloseClipboard() def _get_active_window_info(self) -> dict[str, Any]: - self._require_windows() - user32 = ctypes.windll.user32 - hwnd = user32.GetForegroundWindow() - if not hwnd: + try: + self._require_windows() + user32 = ctypes.windll.user32 + hwnd = user32.GetForegroundWindow() + if not hwnd: + return {"available": False} + return self._window_info_from_handle(int(hwnd)) + except Exception: return {"available": False} - return self._window_info_from_handle(int(hwnd)) def _tool_see_screen(self, _: dict[str, Any]) -> dict[str, Any]: image, meta = self._capture_screen(with_grid=True)