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.

fix(cua-driver): repair non-native Linux tool registry (#4715)

injaneity6f7ed59138c3
diff --git a/.github/workflows/ci-platform-linux-portability.yml b/.github/workflows/ci-platform-linux-portability.yml
index 1af1406fd3..86c984a411 100644
--- a/.github/workflows/ci-platform-linux-portability.yml
+++ b/.github/workflows/ci-platform-linux-portability.yml
@@ -1,7 +1,7 @@
name: "CI: platform-linux off Linux"
# `cargo test --workspace` must keep compiling on developer Macs, so the Linux
-# adapter and its tests are checked on macOS. Trigger on the adapter and the
+# adapter and its tests are run on macOS. Trigger on the adapter and the
# workspace crates it depends on, not on unrelated platform code.
on:
pull_request:
@@ -53,6 +53,6 @@ jobs:
workspaces: "libs/cua-driver/rust -> target"
key: platform-linux-off-linux
save-if: ${{ github.ref == 'refs/heads/main' }}
- - name: Check platform-linux and its tests off Linux
+ - name: Test platform-linux off Linux
working-directory: libs/cua-driver/rust
- run: cargo check --locked -p platform-linux --all-targets
+ run: cargo test --locked -p platform-linux --all-targets
diff --git a/libs/cua-driver/rust/crates/platform-linux/src/tools/stubs.rs b/libs/cua-driver/rust/crates/platform-linux/src/tools/stubs.rs
index 9a0dcc9aa8..aed3bbc5e2 100644
--- a/libs/cua-driver/rust/crates/platform-linux/src/tools/stubs.rs
+++ b/libs/cua-driver/rust/crates/platform-linux/src/tools/stubs.rs
@@ -183,10 +183,6 @@ stub_tool!(scroll_m, ScrollTool, "scroll",
"Scroll the target pid's focused region. direction required; by defaults to line, amount defaults to 3.",
serde_json::json!({"type":"object","required":["direction"],"properties":{"session": cua_driver_core::tool_schema::session_schema(),"cursor_id":{"type":"string"},"pid":{"type":"integer"},"direction":{"type":"string","enum":["up","down","left","right"]},"by":{"type":"string","enum":["line","page"]},"amount":{"type":"integer","minimum":1,"maximum":50},"window_id":{"type":"integer"},"element_token": cua_driver_core::tool_schema::element_token_schema()},"additionalProperties":false}));
-stub_tool!(screenshot_m, ScreenshotTool, "screenshot",
- "Capture a screenshot. Without window_id captures the full display. Supports png and jpeg formats.",
- serde_json::json!({"type":"object","properties":{"window_id":{"type":"integer"},"format":{"type":"string","enum":["png","jpeg"]},"quality":{"type":"integer","minimum":1,"maximum":95}},"additionalProperties":false}));
-
stub_tool!(
get_screen_size_m,
GetScreenSizeTool,
@@ -223,7 +219,33 @@ contract_stub_tool!(
SetAgentCursorThemeTool,
"set_agent_cursor_theme"
);
-contract_stub_tool!(invoke_menu_m, InvokeMenuTool, "invoke_menu");
+pub struct InvokeMenuTool;
+
+#[async_trait]
+impl Tool for InvokeMenuTool {
+ fn def(&self) -> &ToolDef {
+ static DEF: std::sync::OnceLock<ToolDef> = std::sync::OnceLock::new();
+ DEF.get_or_init(|| {
+ // Menu schemas are portable subsets, not canonical runtime schemas.
+ // Match the native menu definition without using the cursor bridge.
+ let contract =
+ cua_driver_contract::tool_contract("invoke_menu").expect("invoke_menu contract");
+ ToolDef {
+ name: contract.name,
+ description: contract.description,
+ input_schema: contract.input_schema,
+ read_only: contract.annotations.read_only,
+ destructive: contract.annotations.destructive,
+ idempotent: contract.annotations.idempotent,
+ open_world: contract.annotations.open_world,
+ }
+ })
+ }
+
+ async fn invoke(&self, _args: Value) -> ToolResult {
+ not_impl("invoke_menu")
+ }
+}
stub_tool!(
check_perms_m,
@@ -328,7 +350,6 @@ pub fn build_registry() -> cua_driver_core::tool::ToolRegistry {
r.register(Box::new(SetValueTool));
r.register(Box::new(InvokeMenuTool));
r.register(Box::new(ScrollTool));
- r.register(Box::new(ScreenshotTool));
r.register(Box::new(GetScreenSizeTool));
r.register(Box::new(GetCursorPositionTool));
r.register(Box::new(MoveCursorTool));
diff --git a/libs/cua-driver/rust/crates/platform-linux/tests/removed_screenshot_registry.rs b/libs/cua-driver/rust/crates/platform-linux/tests/removed_screenshot_registry.rs
new file mode 100644
index 0000000000..ac2366714c
--- /dev/null
+++ b/libs/cua-driver/rust/crates/platform-linux/tests/removed_screenshot_registry.rs
@@ -0,0 +1,27 @@
+//! Narrow current-main characterization for backlog #2317.
+//! No desktop, input, clipboard, or user state is accessed.
+#![cfg(not(target_os = "linux"))]
+
+fn assert_screenshot_removed(compat: bool) {
+ let registry = platform_linux::tools::build_registry(compat);
+ assert!(
+ registry.get_def("screenshot").is_none(),
+ "removed screenshot remains resolvable (compat={compat})"
+ );
+ let list = registry.tools_list();
+ let tools = list["tools"].as_array().expect("tools/list array");
+ assert!(
+ tools.iter().all(|tool| tool["name"] != "screenshot"),
+ "removed screenshot remains advertised (compat={compat})"
+ );
+}
+
+#[test]
+fn standard_registry_does_not_expose_removed_screenshot() {
+ assert_screenshot_removed(false);
+}
+
+#[test]
+fn compat_registry_does_not_expose_removed_screenshot() {
+ assert_screenshot_removed(true);
+}
diff --git a/libs/cua-driver/rust/crates/platform-linux/tests/stub_menu_registry.rs b/libs/cua-driver/rust/crates/platform-linux/tests/stub_menu_registry.rs
new file mode 100644
index 0000000000..4a8b71fe07
--- /dev/null
+++ b/libs/cua-driver/rust/crates/platform-linux/tests/stub_menu_registry.rs
@@ -0,0 +1,39 @@
+#![cfg(not(target_os = "linux"))]
+
+fn assert_menu_definition(compat: bool) {
+ let registry = platform_linux::tools::build_registry(compat);
+ let definition = registry.get_def("invoke_menu").expect("menu stub exists");
+ let contract = cua_driver_contract::tool_contract("invoke_menu").unwrap();
+ assert_eq!(
+ contract.schema_mode,
+ cua_driver_contract::SchemaMode::PortableSubset
+ );
+ assert_eq!(definition.name, contract.name);
+ assert_eq!(definition.description, contract.description);
+ assert_eq!(definition.input_schema, contract.input_schema);
+ assert_eq!(definition.read_only, contract.annotations.read_only);
+ assert_eq!(definition.destructive, contract.annotations.destructive);
+ assert_eq!(definition.idempotent, contract.annotations.idempotent);
+ assert_eq!(definition.open_world, contract.annotations.open_world);
+ assert!(definition.destructive && definition.open_world);
+ let list = registry.tools_list();
+ assert_eq!(
+ list["tools"]
+ .as_array()
+ .unwrap()
+ .iter()
+ .filter(|tool| tool["name"] == "invoke_menu")
+ .count(),
+ 1
+ );
+}
+
+#[test]
+fn standard_registry_constructs_portable_menu_stub() {
+ assert_menu_definition(false);
+}
+
+#[test]
+fn compat_registry_constructs_portable_menu_stub() {
+ assert_menu_definition(true);
+}