Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.
Rust agentai-agentapplecomputer-usecomputer-use-agentcontainerizationcuadesktop-automationhacktoberfestlumemacosmanusoperatorswiftvirtualizationvirtualization-frameworkwindowswindows-sandbox
fix(cua-driver): print actionable PATH install hints (#5219)
injaneity2e644e9f6540
diff --git a/.github/scripts/tests/test_cua_driver_release_wiring.py b/.github/scripts/tests/test_cua_driver_release_wiring.pyindex 861a14dec4..674a321886 100644--- a/.github/scripts/tests/test_cua_driver_release_wiring.py+++ b/.github/scripts/tests/test_cua_driver_release_wiring.py@@ -3,6 +3,7 @@import jsonimport osfrom pathlib import Path+import reimport subprocessimport tempfileimport textwrap@@ -584,6 +585,68 @@ fiself.assertIn('$CursorThemeRequiredFrom = [version]"0.12.7"', powershell)self.assertIn("[version]$version -ge $CursorThemeRequiredFrom", powershell)+ def run_release_installer_path_block(+ self, user_shell: str, *, no_modify_path: str = "0"+ ) -> tuple[str, str | None, str]:+ shell = self.read("libs/cua-driver/scripts/_install-rust.sh")+ snippets = [+ re.search(r"^log\(\) .*$", shell, re.M),+ re.search(r"^print_path_hint\(\) \{$.*?^\}$", shell, re.M | re.S),+ re.search(r'^if \[\[ ":\$PATH:" .*?^fi$', shell, re.M | re.S),+ ]+ self.assertTrue(all(snippets))+ with tempfile.TemporaryDirectory() as temp:+ home = Path(temp) / "home dir"+ home.mkdir()+ bin_dir = str(home / "cua bin")+ result = subprocess.run(+ [+ "bash",+ "-c",+ f'BIN_DIR="{bin_dir}"\nBIN_LINK="$BIN_DIR/cua-driver"\n'+ + "\n".join(snippet.group(0) for snippet in snippets),+ ],+ env={+ **os.environ,+ "HOME": str(home),+ "SHELL": user_shell,+ "NO_MODIFY_PATH": no_modify_path,+ },+ capture_output=True,+ text=True,+ check=True,+ )+ bashrc = home / ".bashrc"+ bashrc_text = bashrc.read_text() if bashrc.exists() else None+ return result.stdout, bashrc_text, bin_dir++ def test_release_installer_always_prints_an_actionable_path_hint(self) -> None:+ posix_export = 'export PATH="{bin_dir}:$PATH"'+ quoted_run = '"{bin_dir}/cua-driver" --version'+ cases = {+ "/bin/bash": (posix_export, " " + quoted_run),+ "/opt/homebrew/bin/fish": ('fish_add_path "{bin_dir}"', " " + quoted_run),+ "/usr/local/bin/nu": (+ '$env.PATH = ($env.PATH | prepend "{bin_dir}")',+ " ^" + quoted_run,+ ),+ "": (posix_export, " " + quoted_run),+ }+ for user_shell, expected_lines in cases.items():+ for no_modify_path in ("0", "1"):+ with self.subTest(shell=user_shell, no_modify_path=no_modify_path):+ stdout, bashrc, bin_dir = self.run_release_installer_path_block(+ user_shell, no_modify_path=no_modify_path+ )+ for expected in expected_lines:+ self.assertIn(expected.format(bin_dir=bin_dir) + "\n", stdout)+ if user_shell == "":+ self.assertIn("POSIX-compatible shells:", stdout)+ if user_shell == "/bin/bash" and no_modify_path == "0":+ self.assertIn(f'export PATH="{bin_dir}:$PATH"', bashrc)+ else:+ self.assertIsNone(bashrc)+def test_windows_installer_elevates_autostart_binary_without_command_string(self,) -> None:diff --git a/libs/cua-driver/scripts/_install-rust.sh b/libs/cua-driver/scripts/_install-rust.shindex b28842995b..6698f898e0 100644--- a/libs/cua-driver/scripts/_install-rust.sh+++ b/libs/cua-driver/scripts/_install-rust.sh@@ -189,6 +189,27 @@ TMP_DIR=$(mktemp -d)log() { printf '==> %s\n' "$*"; }err() { printf 'error: %s\n' "$*" >&2; }+print_path_hint() {+ log "WARNING: $BIN_DIR is not on PATH."+ echo "Add it for your shell with:"+ local run_prefix=""+ case "${SHELL:-}" in+ */fish)+ printf ' fish_add_path "%s"\n' "$BIN_DIR"+ ;;+ */nu|*/nushell)+ printf ' $env.PATH = ($env.PATH | prepend "%s")\n' "$BIN_DIR"+ run_prefix="^"+ ;;+ *)+ echo "POSIX-compatible shells:"+ printf ' export PATH="%s:$PATH"\n' "$BIN_DIR"+ ;;+ esac+ echo "Or run the installed binary directly:"+ printf ' %s"%s" --version\n' "$run_prefix" "$BIN_LINK"+}+# The integer "version" of a GNOME helper metadata.json, or nothing.helper_metadata_version() {sed -n 's/.*"version"[[:space:]]*:[[:space:]]*\([0-9][0-9]*\).*/\1/p' "$1" 2>/dev/null | head -n 1 || true@@ -1543,21 +1564,20 @@ CUA_DRIVER_RELEASE_VERSION="$VERSION" \disown 2>/dev/null || true# Auto-extend PATH for users whose shell doesn't already include BIN_DIR.-if [[ "$NO_MODIFY_PATH" != "1" ]] && [[ ":$PATH:" != *":$BIN_DIR:"* ]]; then+if [[ ":$PATH:" != *":$BIN_DIR:"* ]]; thenSHELL_RC=""case "${SHELL:-}" in*/zsh) SHELL_RC="$HOME/.zshrc" ;;*/bash) SHELL_RC="$HOME/.bashrc" ;;esac- if [[ -n "$SHELL_RC" ]]; then+ if [[ "$NO_MODIFY_PATH" != "1" ]] && [[ -n "$SHELL_RC" ]]; then{printf '\n# Added by cua-driver-rs installer — see https://github.com/trycua/cua\n'printf 'export PATH="%s:$PATH"\n' "$BIN_DIR"} >> "$SHELL_RC"log "appended PATH update to $SHELL_RC — open a new shell or run \`source $SHELL_RC\`"- else- log "WARNING: $BIN_DIR is not on PATH; add it manually."fi+ print_path_hintfiecho ""