Skip to content

armgit / cua

Public Imported from GitHub
0

Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.

test(cua-driver): repair the macOS Lume acceptance lane (#4601)

Francesco Bonacci7ff69de1790b
diff --git a/libs/cua-driver/rust/crates/cua-driver-e2e/tests/perception_capture_loop_test.rs b/libs/cua-driver/rust/crates/cua-driver-e2e/tests/perception_capture_loop_test.rs
index 776f2ef94b..efcffdecf1 100644
--- a/libs/cua-driver/rust/crates/cua-driver-e2e/tests/perception_capture_loop_test.rs
+++ b/libs/cua-driver/rust/crates/cua-driver-e2e/tests/perception_capture_loop_test.rs
@@ -378,7 +378,10 @@ fn installed_macos_binary() -> PathBuf {
.expect("CUA_E2E_INSTALLED_DRIVER_BIN must identify the installed, TCC-authorized app"),
);
assert!(binary.is_file(), "installed Driver is missing: {binary:?}");
- binary
+ // The Lume runner exports the ~/.local/bin symlink; the daemon is launched
+ // from the app bundle it points to.
+ std::fs::canonicalize(&binary)
+ .unwrap_or_else(|error| panic!("resolve installed Driver {binary:?}: {error}"))
}
/// A second instance of the installed app, sharing its TCC grants but not its
diff --git a/libs/cua-driver/rust/crates/cua-driver-e2e/tests/tk_pointer_click_macos_test.rs b/libs/cua-driver/rust/crates/cua-driver-e2e/tests/tk_pointer_click_macos_test.rs
index d496152ff0..7afa3d6d64 100644
--- a/libs/cua-driver/rust/crates/cua-driver-e2e/tests/tk_pointer_click_macos_test.rs
+++ b/libs/cua-driver/rust/crates/cua-driver-e2e/tests/tk_pointer_click_macos_test.rs
@@ -189,6 +189,7 @@ fn tk_window_pixel_click_foreground_moves_pointer_and_reaches_target() {
let click = fixture.driver.call(
"click",
json!({
+ "session": fixture.session,
"pid": fixture.pid,
"window_id": fixture.window_id,
"x": x,
@@ -247,6 +248,7 @@ fn tk_window_pixel_click_background_is_refused_without_delivery() {
let click = fixture.driver.call(
"click",
json!({
+ "session": fixture.session,
"pid": fixture.pid,
"window_id": fixture.window_id,
"x": x,
diff --git a/libs/cua-driver/scripts/tests/test_macos_lume_runner.py b/libs/cua-driver/scripts/tests/test_macos_lume_runner.py
index 4a8fbb7f87..e2b6f88c31 100644
--- a/libs/cua-driver/scripts/tests/test_macos_lume_runner.py
+++ b/libs/cua-driver/scripts/tests/test_macos_lume_runner.py
@@ -219,6 +219,53 @@ def test_golden_image_preflight_requires_python3(tmp_path: Path) -> None:
assert completed.stderr == "Missing golden-image dependency: python3\n"
+def _fake_keychain_list(tmp_path: Path, *keychains: str) -> Path:
+ fake_bin = tmp_path / "bin"
+ listed = "".join(f' \\"{keychain}\\"\\n' for keychain in keychains)
+ _write_executable(
+ fake_bin / "security",
+ f'[ "$1 $2 $3" = "list-keychains -d user" ] || exit 9\nprintf "{listed}"\n',
+ )
+ return fake_bin
+
+
+def test_login_keychain_must_stay_in_the_user_search_list(tmp_path: Path) -> None:
+ login = "/Users/lume/Library/Keychains/login.keychain-db"
+ signing = "/Users/lume/Library/Keychains/cua-driver-signing.keychain-db"
+ fake_bin = _fake_keychain_list(tmp_path, signing)
+
+ completed = _run(
+ RUN_ALL,
+ 'PATH="$TEST_FAKE_BIN:$PATH"\nrequire_login_keychain_searchable "$TEST_LOGIN"\n',
+ env={"TEST_FAKE_BIN": str(fake_bin), "TEST_LOGIN": login},
+ )
+
+ assert completed.returncode == 2
+ assert "missing from the user Keychain search list" in completed.stderr
+ assert f'"{login}"' in completed.stderr
+
+
+def test_searchable_login_keychain_passes_the_history_preflight(tmp_path: Path) -> None:
+ login = "/Users/lume/Library/Keychains/login.keychain-db"
+ signing = "/Users/lume/Library/Keychains/cua-driver-signing.keychain-db"
+ fake_bin = _fake_keychain_list(tmp_path, signing, login)
+
+ completed = _run(
+ RUN_ALL,
+ 'PATH="$TEST_FAKE_BIN:$PATH"\nrequire_login_keychain_searchable "$TEST_LOGIN"\n',
+ env={"TEST_FAKE_BIN": str(fake_bin), "TEST_LOGIN": login},
+ )
+
+ assert completed.returncode == 0, completed.stderr
+ assert completed.stderr == ""
+
+
+def test_seed_guide_keeps_the_login_keychain_searchable() -> None:
+ text = RUNNER_GUIDE.read_text(encoding="utf-8")
+ assert 'security list-keychains -d user -s "$SIGNING_KEYCHAIN"\n' not in text
+ assert '"$HOME/Library/Keychains/login.keychain-db"' in text
+
+
@pytest.mark.parametrize("script", [RUN_ALL, RUN_RUST_E2E], ids=lambda path: path.name)
def test_no_permission_mode_check_pipes_into_grep(script: Path) -> None:
text = script.read_text(encoding="utf-8")
@@ -1015,6 +1062,9 @@ def test_required_keychains_unlock_login_without_retaining_password(
_write_executable(
fake_security,
"""printf '%s\\n' "$*" >> "$CUA_TEST_SECURITY_LOG"
+if [ "$1" = list-keychains ]; then
+ printf ' "%s"\\n' "$CUA_E2E_SIGNING_KEYCHAIN" "$CUA_E2E_LOGIN_KEYCHAIN"
+fi
""",
)
completed = _run(
@@ -1034,6 +1084,7 @@ def test_required_keychains_unlock_login_without_retaining_password(
assert log.read_text(encoding="utf-8").splitlines() == [
f"unlock-keychain -p fixture-password {signing_keychain}",
f"unlock-keychain -p fixture-password {login_keychain}",
+ "list-keychains -d user",
]
@@ -1051,6 +1102,9 @@ def test_required_keychains_accept_already_unlocked_noninteractive_keychains(
_write_executable(
fake_security,
"""printf '%s\n' "$*" >> "$CUA_TEST_SECURITY_LOG"
+if [ "$1" = list-keychains ]; then
+ printf ' "%s"\n' "$CUA_E2E_SIGNING_KEYCHAIN" "$CUA_E2E_LOGIN_KEYCHAIN"
+fi
command="$1"
shift
if [ "$command" = find-generic-password ]; then
@@ -1092,7 +1146,7 @@ fi
probe_binary = codesign_calls[0].rsplit(" ", 1)[1]
assert codesign_calls[1] == f"--verify --strict {probe_binary}"
security_calls = security_log.read_text(encoding="utf-8").splitlines()
- assert len(security_calls) == 3
+ assert len(security_calls) == 4
assert security_calls[0].startswith("add-generic-password -a cua-driver-keychain-probe -s ")
service = security_calls[0].split(" -s ", 1)[1].split(" -w ", 1)[0]
assert security_calls[0].endswith(f" -w {service} {login_keychain}")
@@ -1104,6 +1158,7 @@ fi
f"delete-generic-password -a cua-driver-keychain-probe -s {service} "
f"{login_keychain}"
)
+ assert security_calls[3] == "list-keychains -d user"
def test_required_keychains_fail_when_noninteractive_keychain_is_locked(
diff --git a/libs/cua-driver/tests/runners/macos-lume/README.md b/libs/cua-driver/tests/runners/macos-lume/README.md
index 19e87b18d5..5c47c17ca9 100644
--- a/libs/cua-driver/tests/runners/macos-lume/README.md
+++ b/libs/cua-driver/tests/runners/macos-lume/README.md
@@ -165,11 +165,18 @@ the VM account so maintainers have only one local credential to enter:
SIGNING_KEYCHAIN="$HOME/Library/Keychains/cua-driver-signing.keychain-db"
security create-keychain "$SIGNING_KEYCHAIN"
security set-keychain-settings "$SIGNING_KEYCHAIN"
-security list-keychains -d user -s "$SIGNING_KEYCHAIN"
+security list-keychains -d user -s "$SIGNING_KEYCHAIN" \
+ "$HOME/Library/Keychains/login.keychain-db"
security unlock-keychain "$SIGNING_KEYCHAIN"
export CUA_DRIVER_LOCAL_SIGNING_KEYCHAIN="$SIGNING_KEYCHAIN"
```
+Keep the login Keychain in the search list. Computer History adds its key to
+the default login Keychain and reads it back through the search list, so a list
+with only the signing keychain fails the history gate with
+`history_key_unavailable`. The acceptance runner refuses such a list before it
+builds.
+
The first strict local install creates and imports the self-signed identity,
then stops without replacing the app if the new certificate is not usable yet.
Run it once, then open Keychain Access in the VM display, select the
@@ -232,7 +239,10 @@ osascript -e \
```
Choose Allow for `Terminal` -> `System Events` and on the CuaDriverLocal
-direct-capture prompt. CuaDriverLocal app enumeration must not ask for System
+direct-capture prompt. Then add Terminal under System Settings > Privacy &
+Security > Accessibility: the `bring_to_front` oracles raise fixture windows and
+read `AXFocusedWindow` through System Events UI scripting, which needs it. The
+runner checks both Terminal grants before it builds. CuaDriverLocal app enumeration must not ask for System
Events. Target-specific Automation prompts may still appear later when a user
explicitly requests an Apple Events-backed browser or app operation; do not
pre-grant those in the seed. These are normal macOS consent flows; do not edit
@@ -356,6 +366,7 @@ granted and then rerun without prompts:
- `CuaDriverLocal.app`: Accessibility and Screen Recording
- Terminal controlling System Events
+- Terminal: Accessibility, for System Events UI scripting
- CuaDriverLocal direct screen capture without the system picker. macOS labels
this combined consent as screen and system-audio access even though Cua
Driver's current ScreenCaptureKit recorder does not enable audio capture.
diff --git a/libs/cua-driver/tests/runners/macos-lume/run-all.sh b/libs/cua-driver/tests/runners/macos-lume/run-all.sh
index 7b8f13466c..a8b7645f09 100755
--- a/libs/cua-driver/tests/runners/macos-lume/run-all.sh
+++ b/libs/cua-driver/tests/runners/macos-lume/run-all.sh
@@ -333,6 +333,25 @@ prepare_keychain() {
keychain_password=""
}
+# Computer History adds its key to the default (login) Keychain and reads it back
+# through the user search list. A list that omits the login Keychain lets the add
+# succeed while every read-back misses, which the daemon reports as
+# history_key_unavailable.
+require_login_keychain_searchable() {
+ local keychain="$1"
+ local listed
+ if ! listed="$(security list-keychains -d user 2>&1)"; then
+ echo "Could not read the user Keychain search list: ${listed}" >&2
+ return 2
+ fi
+ if [[ "${listed}" != *"\"${keychain}\""* ]]; then
+ echo "The login Keychain is missing from the user Keychain search list, so Computer History cannot read back its key" >&2
+ echo "Keep it searchable next to the signing keychain:" >&2
+ echo " security list-keychains -d user -s \"${SIGNING_KEYCHAIN}\" \"${keychain}\"" >&2
+ return 2
+ fi
+}
+
unlock_required_keychains() {
local provided_password="${CUA_E2E_SIGNING_KEYCHAIN_PASSWORD:-}"
unset CUA_E2E_SIGNING_KEYCHAIN_PASSWORD
@@ -349,6 +368,7 @@ unlock_required_keychains() {
prepare_keychain "Login keychain" "${LOGIN_KEYCHAIN}" \
"${provided_password}" login
provided_password=""
+ require_login_keychain_searchable "${LOGIN_KEYCHAIN}"
}
json_string_array() {
@@ -1004,6 +1024,16 @@ if ! osascript -e \
echo "Terminal cannot control System Events; rebuild the seed and grant the Automation prompt" >&2
exit 2
fi
+echo "[AUTOMATION] Verifying Terminal can read accessibility attributes through System Events"
+# The bring_to_front oracles raise fixture windows and read AXFocusedWindow
+# through System Events UI scripting, which needs Accessibility for Terminal.
+if ! osascript -e \
+ 'tell application "System Events" to get value of attribute "AXRole" of (first application process whose frontmost is true)' \
+ > "${ARTIFACT_DIR}/terminal-accessibility.txt" 2>&1; then
+ cat "${ARTIFACT_DIR}/terminal-accessibility.txt" >&2
+ echo "Terminal cannot use System Events UI scripting; grant Terminal Accessibility in the seed" >&2
+ exit 2
+fi
echo "[INSTALL] Building and installing ${SOURCE_SHA} with the golden signing identity"
bash "${DRIVER_ROOT}/scripts/install-local.sh" \