Skip to content

Truly independent web browser

Tests: Skip the macOS accessibility tests without PyObjC or permission

Luke Wildeaec59ce0611e
diff --git a/Tests/LibWeb/AccessibilityBridgeMac/CMakeLists.txt b/Tests/LibWeb/AccessibilityBridgeMac/CMakeLists.txt
index 5069758a0d8..495dda2f996 100644
--- a/Tests/LibWeb/AccessibilityBridgeMac/CMakeLists.txt
+++ b/Tests/LibWeb/AccessibilityBridgeMac/CMakeLists.txt
@@ -23,6 +23,8 @@ add_test(
)
set_tests_properties(LibWebAccessibilityBridgeMacLayer1 PROPERTIES
ENVIRONMENT "${LADYBIRD_A11Y_BRIDGE_MAC_ENV}"
+ # run_tests.sh exits with 77 when this machine lacks PyObjC or Accessibility permission.
+ SKIP_RETURN_CODE 77
TIMEOUT 600
TIMEOUT_SIGNAL_NAME SIGTERM
)
diff --git a/Tests/LibWeb/AccessibilityBridgeMac/README.md b/Tests/LibWeb/AccessibilityBridgeMac/README.md
index 9aacf4568fa..a465a65a7d5 100644
--- a/Tests/LibWeb/AccessibilityBridgeMac/README.md
+++ b/Tests/LibWeb/AccessibilityBridgeMac/README.md
@@ -46,9 +46,19 @@ CI runs it that way: the macOS Sanitizer build job packs its `Ladybird.app` with
- macOS (Darwin).
- A Release build of Ladybird (default at `Build/release/bin/Ladybird.app/...`; override with `LADYBIRD_BINARY`).
-- PyObjC frameworks (`pyobjc-framework-ApplicationServices`, `pyobjc-framework-Cocoa`). macOS’s system Python at `/usr/bin/python3` ships with PyObjC preinstalled; **Homebrew’s `python3` typically does not**. The runner auto-detects a Python that has the modules, probing in this order: the `PYTHON` env var, then `python3` on PATH, then `/usr/bin/python3`, then `/Library/Developer/CommandLineTools/usr/bin/python3`. If your `python3` on PATH is Homebrew and lacks PyObjC, either set `PYTHON=/usr/bin/python3` or install PyObjC into your active Python: `python3 -m pip install --user pyobjc-framework-ApplicationServices pyobjc-framework-Cocoa`.
+- PyObjC frameworks (`pyobjc-framework-ApplicationServices`, `pyobjc-framework-Cocoa`). Neither macOS’s system Python at `/usr/bin/python3` nor Homebrew’s `python3` ships with PyObjC. The runner auto-detects a Python that has the modules, probing in this order: the `PYTHON` env var, then `python3` on PATH, then `/usr/bin/python3`, then `/Library/Developer/CommandLineTools/usr/bin/python3`. To install them, create a virtual environment and point `PYTHON` at it:
+
+ ```
+ python3 -m venv ~/.venvs/ladybird-ax
+ ~/.venvs/ladybird-ax/bin/pip install pyobjc-framework-ApplicationServices pyobjc-framework-Cocoa
+ export PYTHON=~/.venvs/ladybird-ax/bin/python3
+ ```
+
+ Create it with a recent Python, such as Homebrew’s: `/usr/bin/python3` is Python 3.9, for which current PyObjC releases ship no prebuilt wheels.
- **Accessibility permission** for the calling shell/IDE. Grant via System Settings → Privacy & Security → Accessibility. Without it, every AXUIElement read returns `kAXErrorAPIDisabled` — and the harness fails fast with a clear message.
+Without PyObjC or the Accessibility permission, `run_tests.sh` exits with status 77, which ctest reports as a skipped test rather than a failure.
+
## Flakiness budget
Tests wait up to 60 seconds for Ladybird to start and for its AXWebArea to populate (children present). Anything slower is flakiness and should be investigated — not patched around with longer timeouts.
diff --git a/Tests/LibWeb/AccessibilityBridgeMac/run_tests.sh b/Tests/LibWeb/AccessibilityBridgeMac/run_tests.sh
index 929b9505057..207f6e3969a 100755
--- a/Tests/LibWeb/AccessibilityBridgeMac/run_tests.sh
+++ b/Tests/LibWeb/AccessibilityBridgeMac/run_tests.sh
@@ -2,9 +2,9 @@
#
# Runs the macOS accessibility-bridge regression tests against NSAccessibility/AXUIElement.
#
-# Requires: PyObjC frameworks (pyobjc-framework-ApplicationServices, pyobjc-framework-Cocoa) — usually pre-installed in
-# macOS's system Python. The shell/IDE running this script needs Accessibility permission granted in System Settings →
-# Privacy & Security → Accessibility.
+# Requires: PyObjC frameworks (pyobjc-framework-ApplicationServices, pyobjc-framework-Cocoa). The shell/IDE running this
+# script needs Accessibility permission granted in System Settings → Privacy & Security → Accessibility. Without either,
+# the script exits with status 77, which ctest reports as a skip.
set -euo pipefail
@@ -24,9 +24,9 @@ if [[ ! -x "${LADYBIRD_BINARY}" ]]; then
exit 1
fi
-# The harness uses PyObjC's ApplicationServices module. The system /usr/bin/python3 (Apple-supplied) ships with PyObjC
-# preinstalled; Homebrew's python3 typically does not. Pick whichever python3 on the system has it. Honor a user-
-# supplied PYTHON env var first, then probe a short list of candidates in order.
+# The harness uses PyObjC's ApplicationServices module, which neither Apple's /usr/bin/python3 nor Homebrew's python3
+# ships with. Pick whichever python3 on the system has had it installed. Honor a user-supplied PYTHON env var first,
+# then probe a short list of candidates in order.
candidates=()
if [[ -n "${PYTHON:-}" ]]; then
candidates+=("${PYTHON}")
@@ -44,15 +44,18 @@ for cand in "${candidates[@]}"; do
done
if [[ -z "${PYTHON_BIN}" ]]; then
- echo "error: no python3 on PATH has the PyObjC ApplicationServices module." >&2
- echo " The harness uses PyObjC to drive the macOS NSAccessibility / AXUIElement APIs." >&2
- echo >&2
- echo " Options:" >&2
- echo " (1) macOS's system Python ships with PyObjC preinstalled. If you have" >&2
- echo " /usr/bin/python3, set PYTHON=/usr/bin/python3 and re-run." >&2
- echo " (2) Or pip-install PyObjC into whichever python3 is on PATH:" >&2
- echo " python3 -m pip install --user pyobjc-framework-ApplicationServices pyobjc-framework-Cocoa" >&2
- exit 1
+ echo "skipping: none of ${candidates[*]} has the PyObjC ApplicationServices module." >&2
+ echo " The harness uses PyObjC to drive the macOS NSAccessibility / AXUIElement APIs. To run these tests," >&2
+ echo " pip-install pyobjc-framework-ApplicationServices and pyobjc-framework-Cocoa into a virtual" >&2
+ echo " environment, and set PYTHON to its python3. See README.md in this directory." >&2
+ exit 77
+fi
+
+if [[ "$("${PYTHON_BIN}" -c "from ApplicationServices import AXIsProcessTrusted; print(AXIsProcessTrusted())")" != "True" ]]; then
+ echo "skipping: ${PYTHON_BIN} is not trusted for Accessibility." >&2
+ echo " Grant the shell/IDE running this script Accessibility permission in System Settings →" >&2
+ echo " Privacy & Security → Accessibility, then re-run." >&2
+ exit 77
fi
cd "${SCRIPT_DIR}"