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): prune redundant protocol and CLI tests (#4113)

Francesco Bonacci79573be555fa
diff --git a/libs/cua-driver/docs/test-harnesses-guide.md b/libs/cua-driver/docs/test-harnesses-guide.md
index acdf424cbb..9ad2761d6f 100644
--- a/libs/cua-driver/docs/test-harnesses-guide.md
+++ b/libs/cua-driver/docs/test-harnesses-guide.md
@@ -214,7 +214,7 @@ These run without a repo-local GUI application and normally run without
| `rust/crates/*/src/**` | Core driver, platform-independent logic, schemas, and helpers |
| `protocol_*_test.rs` | MCP handshake, tool calls, sessions, media, and errors |
| `schema_*_test.rs` | Shared schema and backend consistency |
-| `transport_config_persistence_test.rs` | CLI/MCP configuration persistence |
+| `transport_config_persistence_test.rs` | CLI configuration persistence across processes |
| `protocol_element_token_test.rs` | Element-token protocol behavior |
These tests should be fast, deterministic, and safe to run on ordinary CI
diff --git a/libs/cua-driver/docs/test-matrix.md b/libs/cua-driver/docs/test-matrix.md
index 8ef3f70753..210309f211 100644
--- a/libs/cua-driver/docs/test-matrix.md
+++ b/libs/cua-driver/docs/test-matrix.md
@@ -47,7 +47,7 @@ These run without the repo-local GUI applications:
| MCP and CLI boundary | `rust/crates/cua-driver/tests/protocol_*` | Handshake, tool registration, tool calls, media, sessions, and errors |
| Lifecycle sessions and target migration | Core `session`, `session_tools`, `action_target`, and compatibility `capture_scope` tests plus `session_capture_scope_test.rs` | One implicit session per transport, five-minute idle policy, in-flight and exact-once cleanup, owner-scoped inspection and revival, per-call target validation, and legacy capture-scope compatibility |
| Tool-contract gate | `schema_consistency_test.rs` | Shared tool schema parity and reviewed risk metadata across OS backends |
-| Configuration transport | `transport_config_persistence_test.rs` | CLI and MCP configuration persistence |
+| Configuration transport | `transport_config_persistence_test.rs` | CLI configuration persistence across daemon-backed processes |
| Token and protocol surfaces | `protocol_element_token_test.rs`, related tests | JSON-RPC-visible contract behavior |
| Permission modes and policy startup | `permission_policy_startup_test.rs`, `daemon_required_test.rs`, core `authorization`, `policy`, and `session_manifest` tests | Fail-before-bind policy loading, managed/user intersection, immutable standard/autonomous/unrestricted startup, danger acknowledgement, admin disable, deny-by-default manifests, and canonical daemon dispatch |
| Protected browser grants | Core `consent`, `browser::grant`, `browser::engine`, and `browser::v2_tests` | Exact request digests, provider authentication seam and deadline, persistent-indicator activation, Stop/session teardown, forged legacy artifact refusal, exact PID/window manifest scope, and the live-origin decision path used before mutation |
diff --git a/libs/cua-driver/rust/crates/cua-driver/src/cli.rs b/libs/cua-driver/rust/crates/cua-driver/src/cli.rs
index 81546e382f..6b6034caa2 100644
--- a/libs/cua-driver/rust/crates/cua-driver/src/cli.rs
+++ b/libs/cua-driver/rust/crates/cua-driver/src/cli.rs
@@ -4830,62 +4830,32 @@ fn read_stdin_json() -> Option<serde_json::Value> {
serde_json::from_str(stripped).ok()
}
-#[cfg(test)]
-mod stdin_bom_tests {
- /// Manual cross-check that the BOM-stripping logic round-trips correctly
- /// without needing a real stdin pipe.
- #[test]
- fn strip_prefix_handles_utf8_bom() {
- let with_bom = "\u{feff}{\"pid\":42}";
- let stripped = with_bom.strip_prefix('\u{feff}').unwrap_or(with_bom);
- assert_eq!(stripped, "{\"pid\":42}");
- let v: serde_json::Value = serde_json::from_str(stripped).unwrap();
- assert_eq!(v["pid"], 42);
+fn first_sentence(text: &str) -> String {
+ let trimmed = text.trim();
+ if trimmed.is_empty() {
+ return String::new();
}
-
- #[test]
- fn strip_prefix_no_op_when_no_bom() {
- let plain = "{\"pid\":7}";
- let stripped = plain.strip_prefix('\u{feff}').unwrap_or(plain);
- assert_eq!(stripped, plain);
+ let flat: String = trimmed
+ .split("\n\n")
+ .next()
+ .unwrap_or(trimmed)
+ .split('\n')
+ .collect::<Vec<_>>()
+ .join(" ");
+ let mut sentence = String::new();
+ let mut prev = ' ';
+ for ch in flat.chars() {
+ if (prev == '.' || prev == '?' || prev == '!') && ch == ' ' {
+ break;
+ }
+ sentence.push(ch);
+ prev = ch;
}
-}
-
-/// Normalise a user-provided tool name into a safe PostHog event suffix.
-///
-/// Tool names are concatenated onto `cua_driver_api_` to build per-tool
-/// telemetry event names. The raw string is user-controlled (any CLI
-/// arg or MCP request can specify it), so we:
-///
-/// 1. ASCII-lowercase
-/// 2. Keep only `[a-z0-9_]` — drop punctuation, slashes, dots, anything else
-/// 3. Truncate to 64 chars (event names are a dashboard axis, not free text)
-/// 4. Fall back to `"unknown"` when the result is empty (e.g. all non-ASCII
-/// input), so we still record *that* a call happened without inventing
-/// a per-payload event name.
-#[cfg(test)]
-fn sanitize_tool_name(name: &str) -> String {
- const MAX_LEN: usize = 64;
- const FALLBACK: &str = "unknown";
-
- let cleaned: String = name
- .chars()
- .filter_map(|c| {
- let lc = c.to_ascii_lowercase();
- if lc.is_ascii_alphanumeric() || lc == '_' {
- Some(lc)
- } else {
- None
- }
- })
- .take(MAX_LEN)
- .collect();
-
- if cleaned.is_empty() {
- FALLBACK.to_owned()
- } else {
- cleaned
+ let mut s = sentence.trim().to_string();
+ if s.ends_with('.') {
+ s.pop();
}
+ s
}
#[cfg(test)]
@@ -5189,46 +5159,6 @@ mod tests {
);
}
- #[test]
- fn sanitize_tool_name_passes_through_canonical_names() {
- assert_eq!(sanitize_tool_name("click"), "click");
- assert_eq!(sanitize_tool_name("move_mouse"), "move_mouse");
- assert_eq!(sanitize_tool_name("ScrollUp"), "scrollup");
- }
-
- #[test]
- fn sanitize_tool_name_strips_punctuation_and_path_separators() {
- // Path-like input would otherwise leak directory names into event
- // names — strip everything that's not [a-z0-9_].
- assert_eq!(sanitize_tool_name("foo.bar/baz"), "foobarbaz");
- assert_eq!(sanitize_tool_name("../etc/passwd"), "etcpasswd");
- assert_eq!(sanitize_tool_name("click-element!"), "clickelement");
- }
-
- #[test]
- fn sanitize_tool_name_falls_back_when_non_ascii() {
- // Non-ASCII characters are dropped entirely — without a fallback
- // we'd emit `cua_driver_api_` (empty suffix), which collides with
- // the bare `cua_driver_call` event.
- assert_eq!(sanitize_tool_name("クリック"), "unknown");
- assert_eq!(sanitize_tool_name("🚀"), "unknown");
- }
-
- #[test]
- fn sanitize_tool_name_falls_back_on_empty_or_all_stripped() {
- assert_eq!(sanitize_tool_name(""), "unknown");
- assert_eq!(sanitize_tool_name("---"), "unknown");
- assert_eq!(sanitize_tool_name("///"), "unknown");
- }
-
- #[test]
- fn sanitize_tool_name_caps_length_at_64() {
- let long_name = "a".repeat(200);
- let sanitized = sanitize_tool_name(&long_name);
- assert_eq!(sanitized.len(), 64);
- assert!(sanitized.chars().all(|c| c == 'a'));
- }
-
// ── Surface 8: manifest shape ───────────────────────────────────────────
/// The manifest must carry the four documented top-level keys so a
@@ -5357,50 +5287,4 @@ mod tests {
);
}
}
-
- /// Hermes / Codex / Claude Code can read `mcp_invocation` and drop
- /// their hardcoded `["mcp"]` defaults. The invocation must point at
- /// an executable path, and the `args` array MUST be `["mcp"]` — no
- /// `--something` flag drift, no rename, no removal.
- #[test]
- fn manifest_mcp_invocation_is_stable() {
- let m = build_manifest();
- let inv = m.get("mcp_invocation").expect("mcp_invocation");
- let args: Vec<&str> = inv
- .get("args")
- .and_then(|v| v.as_array())
- .expect("args[] array")
- .iter()
- .filter_map(|v| v.as_str())
- .collect();
- assert_eq!(args, vec!["mcp"]);
- }
-}
-
-fn first_sentence(text: &str) -> String {
- let trimmed = text.trim();
- if trimmed.is_empty() {
- return String::new();
- }
- let flat: String = trimmed
- .split("\n\n")
- .next()
- .unwrap_or(trimmed)
- .split('\n')
- .collect::<Vec<_>>()
- .join(" ");
- let mut sentence = String::new();
- let mut prev = ' ';
- for ch in flat.chars() {
- if (prev == '.' || prev == '?' || prev == '!') && ch == ' ' {
- break;
- }
- sentence.push(ch);
- prev = ch;
- }
- let mut s = sentence.trim().to_string();
- if s.ends_with('.') {
- s.pop();
- }
- s
}
diff --git a/libs/cua-driver/rust/crates/cua-driver/src/extension_manager.rs b/libs/cua-driver/rust/crates/cua-driver/src/extension_manager.rs
index 07f2f962c3..003fa04568 100644
--- a/libs/cua-driver/rust/crates/cua-driver/src/extension_manager.rs
+++ b/libs/cua-driver/rust/crates/cua-driver/src/extension_manager.rs
@@ -812,7 +812,6 @@ fn run_inner(args: &[String]) -> Result<()> {
None => print_infos(&store, REGISTRY, json),
},
"install" | "update" => {
- ensure_mutations_supported()?;
let id = required_id(id, subcommand)?;
let entry = registry_entry(id)?;
let source = resolve_install_source(entry, &parsed, &store)?;
@@ -842,7 +841,6 @@ fn run_inner(args: &[String]) -> Result<()> {
Ok(())
}
"remove" => {
- ensure_mutations_supported()?;
let id = required_id(id, "remove")?;
let entry = registry_entry(id)?;
store.remove(entry)?;
@@ -993,10 +991,6 @@ fn parse_command(args: &[String]) -> Result<ParsedCommand> {
})
}
-fn ensure_mutations_supported() -> Result<()> {
- Ok(())
-}
-
fn required_id<'a>(id: Option<&'a str>, command: &str) -> Result<&'a str> {
id.ok_or_else(|| anyhow!("usage: cua-driver extension {command} <name>"))
}
@@ -5857,11 +5851,6 @@ mod tests {
}
}
- #[test]
- fn mutation_platform_contract_is_explicit() {
- assert!(ensure_mutations_supported().is_ok());
- }
-
#[test]
fn activation_failure_restores_previous_version() {
let temp = TempDir::new().unwrap();
diff --git a/libs/cua-driver/rust/crates/cua-driver/src/perception_cli.rs b/libs/cua-driver/rust/crates/cua-driver/src/perception_cli.rs
index 243087c6dc..c7dec5ac76 100644
--- a/libs/cua-driver/rust/crates/cua-driver/src/perception_cli.rs
+++ b/libs/cua-driver/rust/crates/cua-driver/src/perception_cli.rs
@@ -590,6 +590,13 @@ mod tests {
#[test]
fn arguments_require_both_paths_and_json() {
assert!(parse_args(&["parse".into(), "--json".into()]).is_err());
+ assert!(parse_args(&[
+ "parse".into(),
+ "--image".into(),
+ "image.png".into(),
+ "--json".into(),
+ ])
+ .is_err());
assert!(parse_args(&[
"parse".into(),
"--image".into(),
@@ -628,29 +635,4 @@ mod tests {
assert!(!is_rfc3339(invalid), "accepted {invalid}");
}
}
-
- #[test]
- fn successful_local_result_is_non_actionable_and_uses_a_separate_id_namespace() {
- let digest = "ab".repeat(32);
- let capture_id = local_capture_id(&digest);
- let mut output = json!({
- "schema": "cua.visual_regions_v1",
- "capture": {"capture_id": capture_id}
- });
- insert_local_input(&mut output, Some("snapshot-1".into()), digest).unwrap();
-
- assert_eq!(output["schema"], "cua.visual_regions_v1");
- assert!(output["capture"]["capture_id"]
- .as_str()
- .unwrap()
- .starts_with("local_png_"));
- assert!(!output["capture"]["capture_id"]
- .as_str()
- .unwrap()
- .starts_with("capture_"));
- assert_eq!(output["local_input"]["action_eligible"], false);
- assert_eq!(output["local_input"]["action_authority"], "none");
- assert!(output["local_input"].get("image_path").is_none());
- assert!(output["local_input"].get("capture_metadata_path").is_none());
- }
}
diff --git a/libs/cua-driver/rust/crates/cua-driver/src/private_worker.rs b/libs/cua-driver/rust/crates/cua-driver/src/private_worker.rs
index a7405f059d..e9188f34b4 100644
--- a/libs/cua-driver/rust/crates/cua-driver/src/private_worker.rs
+++ b/libs/cua-driver/rust/crates/cua-driver/src/private_worker.rs
@@ -335,13 +335,3 @@ fn write_response(writer: &mut impl Write, response: &ChannelResponse) -> anyhow
writer.flush()?;
Ok(())
}
-
-#[cfg(test)]
-mod tests {
- use super::requested_generation;
-
- #[test]
- fn ordinary_process_is_not_a_private_worker() {
- assert!(requested_generation().is_none());
- }
-}
diff --git a/libs/cua-driver/rust/crates/cua-driver/src/release_channel.rs b/libs/cua-driver/rust/crates/cua-driver/src/release_channel.rs
index a64c205035..f2739d3334 100644
--- a/libs/cua-driver/rust/crates/cua-driver/src/release_channel.rs
+++ b/libs/cua-driver/rust/crates/cua-driver/src/release_channel.rs
@@ -167,15 +167,4 @@ mod tests {
None
);
}
-
- #[test]
- fn missing_state_defaults_stable_and_valid_state_round_trips() {
- let root = tempfile::tempdir().expect("tempdir");
- let path = root.path().join(FILE_NAME);
- assert_eq!(selected_at(&path), Ok(ReleaseChannel::Stable));
- set_at(&path, ReleaseChannel::Nightly).expect("persist nightly");
- assert_eq!(selected_at(&path), Ok(ReleaseChannel::Nightly));
- set_at(&path, ReleaseChannel::Stable).expect("persist stable");
- assert_eq!(selected_at(&path), Ok(ReleaseChannel::Stable));
- }
}
diff --git a/libs/cua-driver/rust/crates/cua-driver/src/skills.rs b/libs/cua-driver/rust/crates/cua-driver/src/skills.rs
index c40d979a16..755ea067d5 100644
--- a/libs/cua-driver/rust/crates/cua-driver/src/skills.rs
+++ b/libs/cua-driver/rust/crates/cua-driver/src/skills.rs
@@ -1292,7 +1292,7 @@ mod tests {
}
#[test]
- fn extracted_skill_pack_keeps_history_consultation_policy() {
+ fn extracted_skill_pack_keeps_canonical_skill_bytes() {
let crate_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
let files = SKILL_FILES
.iter()
@@ -1315,7 +1315,15 @@ mod tests {
let packaged = std::fs::read_to_string(dest.path().join("SKILL.md"))
.expect("extracted skill must be readable");
- assert_history_consultation_policy(&packaged, "extracted skill pack");
+ // The canonical guidance phrases are owned by the bundled_skill_* tests;
+ // extraction must deliver those exact bytes.
+ assert_eq!(
+ packaged.as_bytes(),
+ std::fs::read(crate_dir.join("../../Skills/cua-driver/SKILL.md"))
+ .unwrap()
+ .as_slice(),
+ "extracted SKILL.md must equal the canonical skill"
+ );
for reference in ["WORKFLOW.md", "RUNTIME.md"] {
assert!(
packaged.contains(&format!("]({reference})")),
diff --git a/libs/cua-driver/rust/crates/cua-driver/src/version_check.rs b/libs/cua-driver/rust/crates/cua-driver/src/version_check.rs
index ba0561585f..f84ed194ad 100644
--- a/libs/cua-driver/rust/crates/cua-driver/src/version_check.rs
+++ b/libs/cua-driver/rust/crates/cua-driver/src/version_check.rs
@@ -321,29 +321,6 @@ pub(crate) fn check_update_state_with_ownership(no_cache: bool, managed: bool) -
}
}
-/// Mark `version` as dismissed so the banner stops nagging the user about
-/// this specific release. They will see the next banner the moment a
-/// strictly-newer tag ships.
-///
-/// Idempotent. Failures (no HOME, IO error) are logged via
-/// `tracing::debug!` and silently dropped — dismissal is a UX nicety, not
-/// a correctness boundary.
-///
-/// Exposed publicly so a future interactive prompt (TUI, GUI helper) can
-/// wire it in without re-implementing the persistence layer. No call site
-/// in the current binary — the banner today is informational only.
-#[allow(dead_code)]
-pub fn dismiss_version(version: &str) {
- let mut cache = read_cache().unwrap_or_default();
- if !cache.dismissed_versions.iter().any(|v| v == version) {
- cache.dismissed_versions.push(version.to_owned());
- }
- if let Err(e) = write_cache(&cache) {
- tracing::debug!(target: "cua_driver::version_check",
- "failed to persist dismissal: {e}");
- }
-}
-
// ── Core logic (testable seam) ───────────────────────────────────────────
/// Inner routine wired up by [`maybe_announce_update`].
@@ -437,8 +414,8 @@ fn run_check_and_announce_with_ownership<F, W>(
}
};
- // Re-read dismissals: dismiss_version may have run between our cache
- // load and now (e.g. on a separately-spawned task in the same process).
+ // Re-read dismissals: another writer may have updated the cache between
+ // our load and now.
let dismissed = read_cache()
.map(|c| c.dismissed_versions)
.unwrap_or(cached.dismissed_versions);
@@ -1098,33 +1075,6 @@ mod tests {
});
}
- #[test]
- fn dismissed_versions_persist_across_writes() {
- let _g = ENV_LOCK.lock().unwrap();
- with_isolated_home(|_| {
- // First dismissal.
- dismiss_version("0.1.4");
- let after_first = read_cache().expect("cache after first");
- assert_eq!(after_first.dismissed_versions, vec!["0.1.4".to_owned()]);
-
- // Second dismissal of a different version appends, doesn't replace.
- dismiss_version("0.1.5");
- let after_second = read_cache().expect("cache after second");
- assert_eq!(
- after_second.dismissed_versions,
- vec!["0.1.4".to_owned(), "0.1.5".to_owned()],
- );
-
- // Re-dismissing an already-dismissed version is idempotent.
- dismiss_version("0.1.4");
- let after_dup = read_cache().expect("cache after dup");
- assert_eq!(
- after_dup.dismissed_versions,
- vec!["0.1.4".to_owned(), "0.1.5".to_owned()],
- );
- });
- }
-
// ── 20h refresh threshold ───────────────────────────────────────────
#[test]
diff --git a/libs/cua-driver/rust/crates/cua-driver/tests/compatibility_contract_test.rs b/libs/cua-driver/rust/crates/cua-driver/tests/compatibility_contract_test.rs
index 019b1c877a..66f46e3bda 100644
--- a/libs/cua-driver/rust/crates/cua-driver/tests/compatibility_contract_test.rs
+++ b/libs/cua-driver/rust/crates/cua-driver/tests/compatibility_contract_test.rs
@@ -216,8 +216,15 @@ fn assert_mcp_contract(driver: &mut RawDriver, fixture: &Value) {
);
}
+ // A notification gets no response: the next message read must answer the
+ // following request, not the notification.
+ driver.send(&json!({"jsonrpc": "2.0", "method": "notifications/initialized"}));
driver.send(&json!({"jsonrpc": "2.0", "id": 2, "method": "tools/list"}));
let tools_list = driver.recv();
+ assert_eq!(
+ tools_list["id"], 2,
+ "notifications/initialized must not produce a response: {tools_list:?}"
+ );
let expected_tools = &fixture["tools_list"];
assert_eq!(
tools_list["result"]["schema_version"],
diff --git a/libs/cua-driver/rust/crates/cua-driver/tests/daemon_required_test.rs b/libs/cua-driver/rust/crates/cua-driver/tests/daemon_required_test.rs
index a697901e8e..5e9482aae7 100644
--- a/libs/cua-driver/rust/crates/cua-driver/tests/daemon_required_test.rs
+++ b/libs/cua-driver/rust/crates/cua-driver/tests/daemon_required_test.rs
@@ -1,6 +1,5 @@
//! Public tool transports must fail closed when no daemon is reachable.
-#[cfg(not(target_os = "macos"))]
use std::io::Write as _;
use std::process::Command;
@@ -211,6 +210,50 @@ fn named_session_survives_across_one_shot_cli_calls() {
assert_eq!(sessions["count"], 0);
}
+#[test]
+fn cli_call_strips_a_utf8_bom_from_piped_stdin_arguments() {
+ // PowerShell 5.1 `Set-Content -Encoding utf8` prepends a BOM. The piped
+ // arguments must still parse; otherwise the call silently runs with
+ // default arguments and the named session below is never created.
+ let mut driver = CliDriver::new();
+ assert!(driver.available(), "test daemon failed to start");
+ let session = format!("synthetic-cli-bom-{}", std::process::id());
+ let socket = driver
+ .daemon_socket()
+ .expect("test daemon socket")
+ .to_owned();
+
+ let mut child = Command::new(env!("CARGO_BIN_EXE_cua-driver"))
+ .args(["call", "start_session", "--socket", &socket])
+ .stdin(std::process::Stdio::piped())
+ .stdout(std::process::Stdio::piped())
+ .stderr(std::process::Stdio::piped())
+ .spawn()
+ .expect("spawn cua-driver call");
+ let payload = serde_json::json!({"session": session, "capture_scope": "window"});
+ {
+ let mut stdin = child.stdin.take().expect("piped stdin");
+ write!(stdin, "\u{feff}{payload}").expect("write BOM-prefixed arguments");
+ }
+ let started = child.wait_with_output().expect("wait for cua-driver call");
+ assert!(
+ started.status.success(),
+ "BOM-prefixed start_session failed: {}",
+ String::from_utf8_lossy(&started.stderr)
+ );
+
+ let state = driver.call("get_session_state", serde_json::json!({"session": session}));
+ assert!(
+ !state.is_error(),
+ "BOM-prefixed arguments were not applied: {}",
+ state.text()
+ );
+ assert_eq!(state.structured()["session"], session);
+
+ let ended = driver.call("end_session", serde_json::json!({"session": session}));
+ assert!(!ended.is_error(), "end failed: {}", ended.text());
+}
+
#[test]
fn implicitly_started_named_session_survives_across_one_shot_cli_calls() {
let mut driver = CliDriver::new();
@@ -432,11 +475,7 @@ fn capability_manifest_narrows_standard_mode() {
driver.available(),
"standard manifest daemon failed to start"
);
- assert!(!driver.call("get_config", serde_json::json!({})).is_error());
- assert!(driver.call("list_apps", serde_json::json!({})).is_error());
- assert!(driver
- .call("get_screen_size", serde_json::json!({}))
- .is_error());
+ assert_manifest_narrows(&mut driver);
}
#[test]
@@ -459,9 +498,37 @@ fn capability_manifest_narrows_unrestricted_mode() {
driver.available(),
"unrestricted manifest daemon failed to start"
);
- assert!(!driver.call("get_config", serde_json::json!({})).is_error());
- assert!(driver.call("list_apps", serde_json::json!({})).is_error());
- assert!(driver
- .call("get_screen_size", serde_json::json!({}))
- .is_error());
+ assert_manifest_narrows(&mut driver);
+}
+
+/// The allow-listed tool runs, while the denied and undeclared tools are
+/// refused by the capability manifest itself rather than by a scope or consent
+/// guard that would also refuse them without a manifest.
+fn assert_manifest_narrows(driver: &mut CliDriver) {
+ let allowed = driver.call("get_config", serde_json::json!({}));
+ assert!(
+ !allowed.is_error(),
+ "allowed call failed: {}",
+ allowed.text()
+ );
+
+ let denied = driver.call("list_apps", serde_json::json!({}));
+ assert!(denied.is_error());
+ assert!(
+ denied
+ .text()
+ .contains("capability manifest denies tool 'list_apps'"),
+ "unexpected denial: {}",
+ denied.text()
+ );
+
+ let undeclared = driver.call("get_screen_size", serde_json::json!({}));
+ assert!(undeclared.is_error());
+ assert!(
+ undeclared
+ .text()
+ .contains("tool 'get_screen_size' is outside the capability manifest"),
+ "unexpected undeclared refusal: {}",
+ undeclared.text()
+ );
}
diff --git a/libs/cua-driver/rust/crates/cua-driver/tests/perception_cli_test.rs b/libs/cua-driver/rust/crates/cua-driver/tests/perception_cli_test.rs
index a5227cd987..7474ad1e4f 100644
--- a/libs/cua-driver/rust/crates/cua-driver/tests/perception_cli_test.rs
+++ b/libs/cua-driver/rust/crates/cua-driver/tests/perception_cli_test.rs
@@ -341,6 +341,9 @@ fn installed_fixture_parses_local_input_without_action_authority() {
assert_eq!(value["local_input"]["action_authority"], "none");
assert_eq!(value["local_input"]["action_eligible"], false);
+ // Local input paths stay private to the caller.
+ assert!(value["local_input"].get("image_path").is_none());
+ assert!(value["local_input"].get("capture_metadata_path").is_none());
assert_eq!(
value["local_input"]["snapshot_id"],
"snapshot-local-fixture"
@@ -445,28 +448,6 @@ fn invalid_installed_extension_fails_as_artifact_invalid() {
assert_eq!(parse_error(&output)["error"]["code"], "artifact_invalid");
}
-#[test]
-fn parser_rejects_missing_json_or_paths() {
- let temp = TempDir::new().unwrap();
- for args in [
- vec!["perception", "parse", "--json"],
- vec!["perception", "parse", "--image", "input.png", "--json"],
- vec![
- "perception",
- "parse",
- "--image",
- "input.png",
- "--capture",
- "capture.json",
- ],
- ] {
- assert!(
- !run(temp.path(), &args).status.success(),
- "accepted {args:?}"
- );
- }
-}
-
#[test]
fn argument_failure_has_an_exact_json_envelope() {
let temp = TempDir::new().unwrap();
diff --git a/libs/cua-driver/rust/crates/cua-driver/tests/protocol_element_token_test.rs b/libs/cua-driver/rust/crates/cua-driver/tests/protocol_element_token_test.rs
index a179be813a..fdbf01818b 100644
--- a/libs/cua-driver/rust/crates/cua-driver/tests/protocol_element_token_test.rs
+++ b/libs/cua-driver/rust/crates/cua-driver/tests/protocol_element_token_test.rs
@@ -95,33 +95,6 @@ fn token_accepting_tools_advertise_element_token_in_schema_and_capabilities() {
}
}
-/// `get_window_state` claims `accessibility.element_tokens`
-/// because it EMITS the tokens (the other side of the contract from
-/// the action tools above).
-#[test]
-fn get_window_state_claims_element_tokens_capability() {
- let resp = match fetch_tools_list() {
- Some(r) => r,
- None => return,
- };
- let tools = resp["result"]["tools"].as_array().expect("tools array");
- let gws = tools
- .iter()
- .find(|t| t["name"].as_str() == Some("get_window_state"))
- .expect("get_window_state missing");
- let caps: Vec<&str> = gws["capabilities"]
- .as_array()
- .unwrap()
- .iter()
- .filter_map(|v| v.as_str())
- .collect();
- assert!(
- caps.contains(&"accessibility.element_tokens"),
- "Surface 6: get_window_state must claim accessibility.element_tokens \
- (it emits the tokens). Current claims: {caps:?}"
- );
-}
-
/// The native menu operation is a path contract, never another entry point for
/// mutable snapshot indices.
#[test]
diff --git a/libs/cua-driver/rust/crates/cua-driver/tests/protocol_handshake_test.rs b/libs/cua-driver/rust/crates/cua-driver/tests/protocol_handshake_test.rs
index 63b65985eb..55efaa93e5 100644
--- a/libs/cua-driver/rust/crates/cua-driver/tests/protocol_handshake_test.rs
+++ b/libs/cua-driver/rust/crates/cua-driver/tests/protocol_handshake_test.rs
@@ -1,78 +1,16 @@
-//! MCP JSON-RPC handshake + tools/list contract tests.
+//! MCP JSON-RPC tools/list roster and tool-error surface tests.
//!
-//! initialize handshake, the registered-tools roster, per-tool capability
-//! claims, the capability/schema version envelope, and the unknown-tool /
-//! unknown-action error surfaces. Split out of the old monolithic
-//! `mcp_protocol_test.rs`; mac/windows pairs are merged into one fn that
-//! branches only where the platforms genuinely differ.
+//! The registered-tools roster and the unknown-tool / unknown-action error
+//! surfaces. The initialize envelope, version fields, and unknown-method error
+//! are owned by `compatibility_contract_test`; per-tool capability and
+//! annotation fields by `schema_consistency_test`. Split out of the old
+//! monolithic `mcp_protocol_test.rs`; mac/windows pairs are merged into one fn
+//! that branches only where the platforms genuinely differ.
#![cfg(any(target_os = "macos", target_os = "windows"))]
use cua_driver_testkit::RawDriver;
-#[test]
-#[cfg(any(target_os = "macos", target_os = "windows"))]
-fn initialize_handshake() {
- let Some(mut d) = RawDriver::spawn() else {
- return;
- };
-
- // 1. Send initialize request.
- d.send(&serde_json::json!({
- "jsonrpc": "2.0",
- "id": 1,
- "method": "initialize",
- "params": {
- "protocolVersion": "2024-11-05",
- "clientInfo": { "name": "test-client", "version": "0.0.1" }
- }
- }));
- let resp = d.recv();
- assert_eq!(resp["jsonrpc"], "2.0");
- assert_eq!(resp["id"], 1);
- assert!(resp["result"]["protocolVersion"].is_string());
- // The server reports "cua-driver" on every platform. (The old Windows
- // mirror asserted a stale "cua-driver-rs"; it had never been run.)
- assert_eq!(resp["result"]["serverInfo"]["name"], "cua-driver");
-
- // 2. Send notifications/initialized (no response expected).
- d.send(&serde_json::json!({
- "jsonrpc": "2.0",
- "method": "notifications/initialized"
- }));
-
- // 3. Request tool list.
- d.send(&serde_json::json!({"jsonrpc": "2.0", "id": 2, "method": "tools/list"}));
- let resp = d.recv();
- assert_eq!(resp["id"], 2);
- let tools = resp["result"]["tools"].as_array().expect("tools array");
- assert!(!tools.is_empty(), "Should have at least one tool");
-
- // Verify tool names match reference implementation.
- let tool_names: Vec<&str> = tools.iter().filter_map(|t| t["name"].as_str()).collect();
- for expected in &[
- "list_apps",
- "list_windows",
- "get_window_state",
- "click",
- "type_text",
- "press_key",
- ] {
- assert!(
- tool_names.contains(expected),
- "Missing tool: {} (have: {:?})",
- expected,
- tool_names
- );
- }
-
- // 4. Verify unknown method returns -32601.
- d.send(&serde_json::json!({"jsonrpc": "2.0", "id": 3, "method": "unknown/method"}));
- let resp = d.recv();
- assert_eq!(resp["id"], 3);
- assert_eq!(resp["error"]["code"], -32601);
-}
-
#[test]
#[cfg(any(target_os = "macos", target_os = "windows"))]
fn all_expected_tools_registered() {
@@ -132,139 +70,6 @@ fn all_expected_tools_registered() {
}
}
-#[test]
-#[cfg(target_os = "macos")]
-fn tools_list_includes_per_tool_capabilities() {
- //! Surface 4 contract (part 1): every entry in `tools/list` must
- //! include a `capabilities` array of dotted-namespace tokens.
- //! Downstream consumers (Hermes' cua_backend.py, Codex) dispatch
- //! by capability instead of hardcoding tool names, so this is the
- //! wire contract. Additive-only — existing keys must still be
- //! present.
- let Some(mut d) = RawDriver::spawn() else {
- return;
- };
-
- d.send(&serde_json::json!({"jsonrpc":"2.0","id":1,"method":"initialize","params":{}}));
- d.recv();
-
- d.send(&serde_json::json!({"jsonrpc":"2.0","id":2,"method":"tools/list"}));
- let resp = d.recv();
- let result = &resp["result"];
-
- let tools = result["tools"].as_array().expect("tools array");
- assert!(!tools.is_empty(), "tools array must be non-empty");
-
- // Every entry has a `capabilities` array (may be empty for tools
- // without a mapping in `default_capabilities_for`).
- for tool in tools {
- let name = tool["name"].as_str().unwrap_or("<no name>");
- assert!(
- tool["capabilities"].is_array(),
- "tool {name:?} missing capabilities array: {tool:?}"
- );
- }
-
- // Specifically: `click` claims input.pointer.click + .left, and
- // `type_text` claims input.keyboard.type — these are the contracts
- // Hermes' cua_backend.py is expected to route by.
- let click = tools
- .iter()
- .find(|t| t["name"] == "click")
- .expect("click tool must be registered");
- let click_caps: Vec<&str> = click["capabilities"]
- .as_array()
- .unwrap()
- .iter()
- .filter_map(|v| v.as_str())
- .collect();
- assert!(
- click_caps.contains(&"input.pointer.click"),
- "click missing input.pointer.click: {click_caps:?}"
- );
- assert!(
- click_caps.contains(&"input.pointer.click.left"),
- "click missing input.pointer.click.left: {click_caps:?}"
- );
-
- let type_text = tools
- .iter()
- .find(|t| t["name"] == "type_text")
- .expect("type_text tool must be registered");
- let tt_caps: Vec<&str> = type_text["capabilities"]
- .as_array()
- .unwrap()
- .iter()
- .filter_map(|v| v.as_str())
- .collect();
- assert!(
- tt_caps.contains(&"input.keyboard.type"),
- "type_text missing input.keyboard.type: {tt_caps:?}"
- );
-
- // Regression guard for additive-only contract: every pre-existing
- // top-level field on a tool entry must still be present.
- for tool in tools {
- let name = tool["name"].as_str().unwrap_or("<no name>");
- assert!(tool["name"].is_string(), "{name}: name missing");
- assert!(
- tool["description"].is_string(),
- "{name}: description missing"
- );
- assert!(
- tool["inputSchema"].is_object(),
- "{name}: inputSchema missing"
- );
- assert!(
- tool["annotations"].is_object(),
- "{name}: annotations missing"
- );
- }
-}
-
-#[test]
-#[cfg(target_os = "macos")]
-fn tools_list_includes_capability_and_schema_versions() {
- //! Surface 4 contract (part 2): top-level `tools/list` response
- //! must include `capability_version` and `schema_version` so
- //! downstream consumers (Hermes' cua_backend.py, Codex) can gate
- //! strict-vs-tolerant capability matching by version. Both pinned
- //! at "1" on first ship.
- let Some(mut d) = RawDriver::spawn() else {
- return;
- };
-
- d.send(&serde_json::json!({"jsonrpc":"2.0","id":1,"method":"initialize","params":{}}));
- d.recv();
-
- d.send(&serde_json::json!({"jsonrpc":"2.0","id":2,"method":"tools/list"}));
- let resp = d.recv();
- let result = &resp["result"];
-
- // Both version fields default to "1" on first ship — the surface
- // is brand new, so there's no pre-existing contract to bump.
- assert_eq!(
- result["capability_version"], "1",
- "capability_version must default to \"1\" on first ship"
- );
- assert_eq!(
- result["schema_version"], "1",
- "schema_version must default to \"1\" on first ship"
- );
-
- // Additive guard: tools array must still be there alongside the
- // new envelope keys — old consumers that only read `tools` keep
- // working.
- assert!(
- result["tools"].is_array(),
- "tools array must still be present alongside version envelope"
- );
- assert!(
- !result["tools"].as_array().unwrap().is_empty(),
- "tools array must be non-empty"
- );
-}
-
#[test]
#[cfg(any(target_os = "macos", target_os = "windows"))]
fn tools_call_unknown_tool() {
diff --git a/libs/cua-driver/rust/crates/cua-driver/tests/protocol_media_test.rs b/libs/cua-driver/rust/crates/cua-driver/tests/protocol_media_test.rs
index cff3bfeef4..bf149f5bc1 100644
--- a/libs/cua-driver/rust/crates/cua-driver/tests/protocol_media_test.rs
+++ b/libs/cua-driver/rust/crates/cua-driver/tests/protocol_media_test.rs
@@ -1,11 +1,11 @@
//! Image / capture / recording tool tests.
//!
-//! screenshot (full-display + JPEG), zoom + the zoom→from_zoom click round
-//! trip, the recording session lifecycle (start/stop + action.json), recording
-//! screenshot capture, the `record_video` flag, trajectory replay, click
-//! `debug_image_out`, and the `set_config` screenshot-resize pipeline. Split
-//! out of the old monolithic `mcp_protocol_test.rs`; mac/windows pairs merge
-//! and branch only where assertions differ.
+//! zoom + the zoom→from_zoom click round trip, the recording session
+//! lifecycle (start/stop + action.json), recording screenshot capture,
+//! trajectory replay, click `debug_image_out`, and the `set_config`
+//! screenshot-resize pipeline. Split out of the old monolithic
+//! `mcp_protocol_test.rs`; mac/windows pairs merge and branch only where
+//! assertions differ.
//!
//! Tests that dispatch a real click into whichever window is on screen are
//! `#[ignore]`d so a plain `cargo test` never sends input. Run them with
@@ -22,131 +22,6 @@ fn spawn_unrestricted() -> Option<RawDriver> {
])
}
-#[test]
-#[cfg(target_os = "windows")]
-fn screenshot() {
- let Some(mut d) = RawDriver::spawn() else {
- return;
- };
-
- d.send(&serde_json::json!({"jsonrpc":"2.0","id":1,"method":"initialize","params":{}}));
- d.recv();
-
- // Full-display screenshot (no window_id).
- d.send(&serde_json::json!({
- "jsonrpc":"2.0","id":2,"method":"tools/call",
- "params":{"name":"screenshot","arguments":{}}
- }));
- let resp = d.recv();
- assert!(resp["error"].is_null(), "Protocol error: {resp:?}");
- let content = resp["result"]["content"].as_array().expect("content array");
- assert!(!content.is_empty(), "screenshot returned empty content");
-
- // JPEG format.
- d.send(&serde_json::json!({
- "jsonrpc":"2.0","id":3,"method":"tools/call",
- "params":{"name":"screenshot","arguments":{"format":"jpeg","quality":70}}
- }));
- let resp = d.recv();
- assert!(
- resp["error"].is_null(),
- "Protocol error from screenshot jpeg: {resp:?}"
- );
- if !resp["result"]["isError"].as_bool().unwrap_or(false) {
- let content = resp["result"]["content"].as_array().expect("content array");
- let has_jpeg = content.iter().any(|c| {
- c["type"] == "image"
- && c["mimeType"].as_str().unwrap_or("") == "image/jpeg"
- && c["data"].as_str().map(|s| s.len() > 10).unwrap_or(false)
- });
- assert!(
- has_jpeg,
- "Expected image/jpeg in screenshot response: {content:?}"
- );
- let sc = &resp["result"]["structuredContent"];
- assert!(sc["width"].as_f64().unwrap_or(0.0) > 0.0);
- assert!(sc["height"].as_f64().unwrap_or(0.0) > 0.0);
- assert_eq!(sc["format"].as_str().unwrap_or(""), "jpeg");
- }
-}
-
-#[test]
-#[cfg(target_os = "macos")]
-fn screenshot_no_window_id() {
- //! Call screenshot without window_id — should capture the full display and return image content.
- let Some(mut d) = RawDriver::spawn() else {
- return;
- };
-
- d.send(&serde_json::json!({"jsonrpc":"2.0","id":1,"method":"initialize","params":{}}));
- d.recv();
-
- d.send(&serde_json::json!({
- "jsonrpc":"2.0","id":2,"method":"tools/call",
- "params":{"name":"screenshot","arguments":{}}
- }));
- let resp = d.recv();
- assert!(
- resp["error"].is_null(),
- "Protocol error from screenshot: {resp:?}"
- );
- let content = resp["result"]["content"].as_array().expect("content array");
- assert!(
- !content.is_empty(),
- "screenshot should return at least one content item"
- );
-}
-
-#[test]
-#[cfg(target_os = "macos")]
-fn screenshot_jpeg_format() {
- //! Call screenshot with format=jpeg — should return a JPEG image.
- let Some(mut d) = RawDriver::spawn() else {
- return;
- };
-
- d.send(&serde_json::json!({"jsonrpc":"2.0","id":1,"method":"initialize","params":{}}));
- d.recv();
-
- d.send(&serde_json::json!({
- "jsonrpc":"2.0","id":2,"method":"tools/call",
- "params":{"name":"screenshot","arguments":{"format":"jpeg","quality":70}}
- }));
- let resp = d.recv();
- assert!(
- resp["error"].is_null(),
- "Protocol error from screenshot: {resp:?}"
- );
- let content = resp["result"]["content"].as_array().expect("content array");
- let is_error = resp["result"]["isError"].as_bool().unwrap_or(false);
- if !is_error {
- let has_jpeg = content.iter().any(|c| {
- c["type"] == "image"
- && c["mimeType"].as_str().unwrap_or("") == "image/jpeg"
- && c["data"].as_str().map(|s| s.len() > 10).unwrap_or(false)
- });
- assert!(
- has_jpeg,
- "Expected image/jpeg in screenshot response, got: {content:?}"
- );
- // Verify structured content has width and height.
- let sc = &resp["result"]["structuredContent"];
- assert!(
- sc["width"].as_f64().unwrap_or(0.0) > 0.0,
- "Expected positive width in structuredContent"
- );
- assert!(
- sc["height"].as_f64().unwrap_or(0.0) > 0.0,
- "Expected positive height in structuredContent"
- );
- assert_eq!(
- sc["format"].as_str().unwrap_or(""),
- "jpeg",
- "Expected format=jpeg"
- );
- }
-}
-
#[test]
#[cfg(any(target_os = "macos", target_os = "windows"))]
fn zoom_tool_returns_jpeg() {
@@ -532,53 +407,6 @@ fn recording_screenshot_capture() {
let _ = std::fs::remove_dir_all(&tmp_dir);
}
-#[test]
-#[cfg(any(target_os = "macos", target_os = "windows"))]
-fn start_recording_record_video_flag_accepted() {
- //! `record_video` is the new on/off flag (replaces the old
- //! `video_experimental`). Default is true. This test passes
- //! `record_video: false` to bypass the ffmpeg dependency in CI;
- //! we only verify that the schema accepts the call and the
- //! session enters the enabled state. Full video lifecycle is
- //! covered by the manual demo + the per-platform smoke when
- //! ffmpeg is installed.
- let Some(mut d) = spawn_unrestricted() else {
- return;
- };
-
- let tmp_dir = std::env::temp_dir().join(format!("cua-driver-rs-recvid-{}", std::process::id()));
- let tmp_str = tmp_dir.to_string_lossy().to_string();
- std::fs::create_dir_all(&tmp_dir).unwrap();
-
- d.send(&serde_json::json!({"jsonrpc":"2.0","id":1,"method":"initialize","params":{}}));
- d.recv();
-
- d.send(&serde_json::json!({
- "jsonrpc":"2.0","id":2,"method":"tools/call",
- "params":{"name":"start_recording","arguments":{
- "output_dir": tmp_str, "record_video": false
- }}
- }));
- let resp = d.recv();
- assert!(
- resp["error"].is_null(),
- "Expected no JSON-RPC error, got: {resp:?}"
- );
- let is_err = resp["result"]["isError"].as_bool().unwrap_or(false);
- assert!(
- !is_err,
- "start_recording with record_video:false should succeed: {resp:?}"
- );
-
- d.send(&serde_json::json!({
- "jsonrpc":"2.0","id":3,"method":"tools/call",
- "params":{"name":"stop_recording","arguments":{}}
- }));
- d.recv();
- drop(d);
- let _ = std::fs::remove_dir_all(&tmp_dir);
-}
-
#[test]
#[cfg(any(target_os = "macos", target_os = "windows"))]
fn replay_trajectory() {
diff --git a/libs/cua-driver/rust/crates/cua-driver/tests/protocol_schema_test.rs b/libs/cua-driver/rust/crates/cua-driver/tests/protocol_schema_test.rs
index c8f4a0c1da..0cde058c7b 100644
--- a/libs/cua-driver/rust/crates/cua-driver/tests/protocol_schema_test.rs
+++ b/libs/cua-driver/rust/crates/cua-driver/tests/protocol_schema_test.rs
@@ -147,30 +147,13 @@ fn tools_list_schema_shape() {
.filter(|tool| tool["inputSchema"]["properties"]["delivery_mode"].is_object())
.filter_map(|tool| tool["name"].as_str())
.collect();
- let capability_tools: BTreeSet<&str> = tools
- .iter()
- .filter(|tool| {
- tool["capabilities"].as_array().is_some_and(|capabilities| {
- capabilities
- .iter()
- .any(|capability| capability == "input.delivery_mode")
- })
- })
- .filter_map(|tool| tool["name"].as_str())
- .collect();
let expected_tools: BTreeSet<&str> = DELIVERY_MODE_TOOLS.iter().copied().collect();
+ // The matching `input.delivery_mode` capability claim is owned by
+ // `schema_consistency_test::registered_tool_contracts_match_on_active_backend`.
assert_eq!(
schema_tools, expected_tools,
"unexpected delivery_mode schema set"
);
- assert_eq!(
- capability_tools, expected_tools,
- "input.delivery_mode must match the exact runtime schema support set"
- );
- assert_eq!(
- list_resp["result"]["capability_version"], "1",
- "adding one capability token is additive and must not bump the vocabulary version"
- );
// Session capture scope remains advertised only for compatibility. New
// clients choose one typed window or desktop target on each action.
let capture_scope = &properties("start_session")["capture_scope"];
@@ -311,9 +294,15 @@ fn legacy_page_mutation_requires_unrestricted_launch_and_operator_opt_in() {
}
#[test]
-#[cfg(target_os = "linux")]
-fn linux_cursor_motion_knobs_are_applied() {
- let mut driver = RawDriver::spawn().expect("spawn source-built Linux driver");
+#[cfg(any(target_os = "linux", target_os = "macos"))]
+fn cursor_motion_knobs_are_applied() {
+ // macOS serves cursor-overlay controls only when the daemon hosts the
+ // overlay; Linux applies the knobs without one.
+ #[cfg(target_os = "macos")]
+ let driver = RawDriver::spawn_with_overlay();
+ #[cfg(not(target_os = "macos"))]
+ let driver = RawDriver::spawn();
+ let mut driver = driver.expect("spawn source-built driver");
driver.send(&serde_json::json!({
"jsonrpc": "2.0",
"id": 1,
@@ -329,7 +318,7 @@ fn linux_cursor_motion_knobs_are_applied() {
"params": {
"name": "set_agent_cursor_motion",
"arguments": {
- "session": "schema-linux",
+ "session": "schema-motion",
"arc_size": 0.4,
"spring": 0.85,
"glide_duration_ms": 500,
@@ -341,10 +330,10 @@ fn linux_cursor_motion_knobs_are_applied() {
let response = driver.recv();
assert!(
!response["result"]["isError"].as_bool().unwrap_or(false),
- "Linux cursor motion update failed: {response:?}"
+ "cursor motion update failed: {response:?}"
);
let structured = &response["result"]["structuredContent"];
- assert_eq!(structured["session"].as_str(), Some("schema-linux"));
+ assert_eq!(structured["session"].as_str(), Some("schema-motion"));
assert_eq!(structured["motion"]["arc_size"].as_f64(), Some(0.4));
assert_eq!(
structured["motion"]["glide_duration_ms"].as_f64(),
diff --git a/libs/cua-driver/rust/crates/cua-driver/tests/protocol_session_test.rs b/libs/cua-driver/rust/crates/cua-driver/tests/protocol_session_test.rs
index 57fc1d8c61..391047017e 100644
--- a/libs/cua-driver/rust/crates/cua-driver/tests/protocol_session_test.rs
+++ b/libs/cua-driver/rust/crates/cua-driver/tests/protocol_session_test.rs
@@ -1,8 +1,8 @@
//! Multi-client / multi-cursor / overlay session tests.
//!
//! Concurrent driver processes, per-cursor instance state, cross-process
-//! isolation, the live overlay render loop, and the `set_agent_cursor_motion`
-//! Bezier knobs. Split out of the old monolithic `mcp_protocol_test.rs`;
+//! isolation, and the live overlay render loop. Cursor motion knobs are owned
+//! by `protocol_schema_test::cursor_motion_knobs_are_applied`. Split out of the old monolithic `mcp_protocol_test.rs`;
//! mac/windows pairs merge and branch only where assertions differ.
//!
//! Note: the originals asserted process liveness with `child.try_wait()`.
@@ -21,88 +21,6 @@ fn spawn_unrestricted_with_overlay() -> Option<RawDriver> {
])
}
-#[test]
-#[cfg(any(target_os = "macos", target_os = "windows"))]
-fn concurrent_clients() {
- //! Verify two concurrent cua-driver-rs processes both respond correctly.
- //! This tests the "multiple cua-driver processes" scenario relevant to
- //! the multi-cursor use case.
- let mut drivers: Vec<RawDriver> = Vec::new();
- for _ in 0..2 {
- let Some(d) = RawDriver::spawn() else {
- return;
- };
- drivers.push(d);
- }
-
- for (i, d) in drivers.iter_mut().enumerate() {
- d.send(&serde_json::json!({
- "jsonrpc": "2.0",
- "id": i + 1,
- "method": "initialize",
- "params": {}
- }));
-
- let resp = d.recv();
- assert_eq!(resp["id"], (i + 1) as i64);
- assert!(
- resp["result"]["protocolVersion"].is_string(),
- "Process {i} failed to initialize"
- );
- }
-}
-
-#[test]
-#[cfg(target_os = "macos")]
-fn concurrent_clients_with_cursor_moves() {
- //! Two concurrent cua-driver processes, each driving their own cursor, should not crash.
- //! This covers the multi-cursor use case where two Codex agents run simultaneously.
- let mut drivers: Vec<RawDriver> = Vec::new();
- for _ in 0..2 {
- let Some(d) = spawn_unrestricted_with_overlay() else {
- return;
- };
- drivers.push(d);
- }
-
- // Initialize all processes.
- for (i, d) in drivers.iter_mut().enumerate() {
- d.send(&serde_json::json!({"jsonrpc":"2.0","id":1,"method":"initialize","params":{}}));
- let resp = d.recv();
- assert_eq!(resp["id"], 1, "Process {i} initialize failed");
- }
-
- // Each process moves its cursor to different positions.
- let positions = [(100.0_f64, 200.0_f64), (500.0, 600.0)];
- for ((i, d), (px, py)) in drivers.iter_mut().enumerate().zip(positions.iter()) {
- d.send(&serde_json::json!({
- "jsonrpc":"2.0","id":2,"method":"tools/call",
- "params":{"name":"move_cursor","arguments":{"x":px,"y":py}}
- }));
- let resp = d.recv();
- assert!(
- !resp["result"]["isError"].as_bool().unwrap_or(false),
- "Process {i} move_cursor failed: {resp:?}"
- );
- }
-
- std::thread::sleep(std::time::Duration::from_millis(100));
-
- // Each process must still be alive: probe with one more request (a crashed
- // process would EOF and panic in recv()).
- for (i, d) in drivers.iter_mut().enumerate() {
- d.send(&serde_json::json!({
- "jsonrpc":"2.0","id":99,"method":"tools/call",
- "params":{"name":"get_agent_cursor_state","arguments":{}}
- }));
- let resp = d.recv();
- assert_eq!(
- resp["id"], 99,
- "cua-driver process {i} crashed during concurrent cursor test"
- );
- }
-}
-
#[test]
#[cfg(any(target_os = "macos", target_os = "windows"))]
fn concurrent_multi_driver_isolation() {
@@ -200,13 +118,29 @@ fn concurrent_multi_driver_isolation() {
let mv_a = child_a.recv();
let mv_b = child_b.recv();
assert!(
- mv_a["error"].is_null(),
+ !mv_a["result"]["isError"].as_bool().unwrap_or(false),
"Driver A move_cursor failed: {mv_a:?}"
);
assert!(
- mv_b["error"].is_null(),
+ !mv_b["result"]["isError"].as_bool().unwrap_or(false),
"Driver B move_cursor failed: {mv_b:?}"
);
+
+ // Both processes must survive the concurrent overlay moves: probe each
+ // once more after the render loop ticks (a crashed process would EOF
+ // and panic in recv()).
+ std::thread::sleep(std::time::Duration::from_millis(100));
+ for (label, driver) in [("A", &mut child_a), ("B", &mut child_b)] {
+ driver.send(&serde_json::json!({
+ "jsonrpc":"2.0","id":6,"method":"tools/call",
+ "params":{"name":"get_config","arguments":{}}
+ }));
+ let alive = driver.recv();
+ assert_eq!(
+ alive["id"], 6,
+ "Driver {label} crashed during concurrent cursor moves: {alive:?}"
+ );
+ }
}
}
@@ -331,44 +265,3 @@ fn overlay_move_cursor_stays_alive() {
"cua-driver crashed during overlay move_cursor test"
);
}
-
-#[test]
-#[cfg(target_os = "macos")]
-fn set_agent_cursor_motion_bezier_knobs() {
- //! set_agent_cursor_motion with Bezier/timing knobs — verifies schema accepts them
- //! and returns a non-error response with the updated values in the response text.
- let Some(mut d) = spawn_unrestricted_with_overlay() else {
- return;
- };
-
- d.send(&serde_json::json!({"jsonrpc":"2.0","id":1,"method":"initialize","params":{}}));
- d.recv();
-
- // Set Bezier motion knobs including integer-encoded numbers (common from MCP clients).
- d.send(&serde_json::json!({
- "jsonrpc":"2.0","id":2,"method":"tools/call",
- "params":{"name":"set_agent_cursor_motion","arguments":{
- "cursor_id": "agent1",
- "arc_size": 0.4,
- "spring": 0.85,
- "glide_duration_ms": 500,
- "dwell_after_click_ms": 200,
- "idle_hide_ms": 5000
- }}
- }));
- let resp = d.recv();
- assert!(
- resp["error"].is_null(),
- "Protocol error from set_agent_cursor_motion: {resp:?}"
- );
- assert!(
- !resp["result"]["isError"].as_bool().unwrap_or(false),
- "set_agent_cursor_motion returned isError: {resp:?}"
- );
- // Response text should mention the new glide duration.
- let text = resp["result"]["content"][0]["text"].as_str().unwrap_or("");
- assert!(
- text.contains("500") || text.contains("motion"),
- "Expected motion summary in response, got: {text}"
- );
-}
diff --git a/libs/cua-driver/rust/crates/cua-driver/tests/protocol_tools_call_test.rs b/libs/cua-driver/rust/crates/cua-driver/tests/protocol_tools_call_test.rs
index 8651c07cda..6419c411c6 100644
--- a/libs/cua-driver/rust/crates/cua-driver/tests/protocol_tools_call_test.rs
+++ b/libs/cua-driver/rust/crates/cua-driver/tests/protocol_tools_call_test.rs
@@ -2,17 +2,17 @@
//!
//! Drives the real tools end-to-end over JSON-RPC: list_apps, get_config /
//! check_permissions, the accessibility tree, list_windows, screen size /
-//! cursor position, window-state AX mode, scroll, type_text, hotkey,
-//! press_key, click / double_click / right_click, and set_value. Split out
-//! of the old monolithic `mcp_protocol_test.rs`; mac/windows pairs merge into
-//! one fn and branch only where the platforms differ (list_apps `apps` vs
-//! `processes`, get_config platform string, check_permissions keys, type_text
-//! target app, hotkey modifier, etc.).
+//! cursor position, window-state AX mode, and the hidden `type_text_chars`
+//! alias. Split out of the old monolithic `mcp_protocol_test.rs`; mac/windows
+//! pairs merge into one fn and branch only where the platforms differ
+//! (list_apps `apps` vs `processes`, get_config platform string,
+//! check_permissions keys, etc.).
//!
-//! Tests that dispatch real input (scroll, type_text, hotkey, press_key,
-//! click, set_value) target whichever window is on screen, so they are
-//! `#[ignore]`d and never run under a plain `cargo test`. Run them with
-//! `--ignored` only on a disposable desktop.
+//! Action delivery (click, double/right click, scroll, type_text, press_key,
+//! hotkey, set_value) is owned by the state-verified fixture suites:
+//! `cross_platform_behavior_test` and the `harness_*` tests. Tests here that
+//! dispatch real input are `#[ignore]`d and never run under a plain
+//! `cargo test`. Run them with `--ignored` only on a disposable desktop.
#![cfg(any(target_os = "macos", target_os = "windows"))]
@@ -493,192 +493,6 @@ fn get_window_state_returns_both_with_opt_out() {
);
}
-#[test]
-#[cfg(any(target_os = "macos", target_os = "windows"))]
-#[ignore = "sends real input to a live desktop window; run with --ignored only on a disposable desktop"]
-fn scroll_tool() {
- //! scroll with direction=down, by=line, amount=1 against the first available window.
- //! Verifies the tool is accepted and returns content, not a protocol error.
- let Some(mut d) = spawn_unrestricted() else {
- return;
- };
-
- d.send(&serde_json::json!({"jsonrpc":"2.0","id":1,"method":"initialize","params":{}}));
- d.recv();
-
- // Find a pid with a window.
- d.send(&serde_json::json!({
- "jsonrpc":"2.0","id":2,"method":"tools/call",
- "params":{"name":"list_apps","arguments":{}}
- }));
- let resp = d.recv();
- let pid = if cfg!(target_os = "windows") {
- // Windows list_apps returns "processes".
- let procs = resp["result"]["structuredContent"]["processes"].as_array();
- let Some(proc_) = procs.and_then(|a| a.iter().find(|p| p["pid"].as_i64().is_some())) else {
- eprintln!("No processes found — skipping scroll test");
- return;
- };
- proc_["pid"].as_i64().unwrap()
- } else {
- let apps = resp["result"]["structuredContent"]["apps"].as_array();
- let Some(app) = apps.and_then(|a| a.iter().find(|a| a["pid"].as_i64().is_some())) else {
- eprintln!("No apps found — skipping scroll test");
- return;
- };
- app["pid"].as_i64().unwrap()
- };
-
- // scroll with minimal parameters — window_id is auto-resolved from pid.
- d.send(&serde_json::json!({
- "jsonrpc":"2.0","id":3,"method":"tools/call",
- "params":{"name":"scroll","arguments":{"pid": pid, "direction": "down", "amount": 1}}
- }));
- let resp = d.recv();
- assert!(
- resp["error"].is_null(),
- "Protocol error from scroll: {resp:?}"
- );
- let content = resp["result"]["content"].as_array().expect("content array");
- assert!(!content.is_empty(), "scroll returned empty content");
-}
-
-#[test]
-#[cfg(target_os = "macos")]
-#[ignore = "sends real input to a live desktop window; run with --ignored only on a disposable desktop"]
-fn type_text_tool() {
- //! Opens TextEdit (or reuses it if already running) and types a short string via type_text.
- //! Skips gracefully if TextEdit is not available or has no window.
- let Some(mut d) = spawn_unrestricted() else {
- return;
- };
-
- d.send(&serde_json::json!({"jsonrpc":"2.0","id":1,"method":"initialize","params":{}}));
- d.recv();
-
- // Launch TextEdit (no-op if already running).
- d.send(&serde_json::json!({
- "jsonrpc":"2.0","id":2,"method":"tools/call",
- "params":{"name":"launch_app","arguments":{"name":"TextEdit"}}
- }));
- d.recv();
- std::thread::sleep(std::time::Duration::from_millis(800));
-
- // Find TextEdit's pid.
- d.send(&serde_json::json!({
- "jsonrpc":"2.0","id":3,"method":"tools/call",
- "params":{"name":"list_apps","arguments":{}}
- }));
- let resp = d.recv();
- let apps = resp["result"]["structuredContent"]["apps"].as_array();
- let Some(app) = apps.and_then(|a| {
- a.iter().find(|a| {
- a["name"]
- .as_str()
- .map(|n| n.eq_ignore_ascii_case("textedit"))
- .unwrap_or(false)
- })
- }) else {
- eprintln!("TextEdit not found — skipping type_text test");
- return;
- };
- let pid = app["pid"].as_i64().unwrap();
-
- // Find TextEdit's first on-screen window.
- d.send(&serde_json::json!({
- "jsonrpc":"2.0","id":4,"method":"tools/call",
- "params":{"name":"list_windows","arguments":{"pid": pid, "on_screen_only": true}}
- }));
- let resp = d.recv();
- let wins = resp["result"]["structuredContent"]["windows"].as_array();
- let Some(win) = wins.and_then(|a| a.first()) else {
- eprintln!("TextEdit has no on-screen windows — skipping type_text test");
- return;
- };
- let wid = win["window_id"].as_u64().unwrap();
-
- // type_text into TextEdit's window.
- d.send(&serde_json::json!({
- "jsonrpc":"2.0","id":5,"method":"tools/call",
- "params":{"name":"type_text","arguments":{"pid": pid, "window_id": wid, "text": "cua-test"}}
- }));
- let resp = d.recv();
- assert!(
- resp["error"].is_null(),
- "Protocol error from type_text: {resp:?}"
- );
- let content = resp["result"]["content"].as_array().expect("content array");
- assert!(!content.is_empty(), "type_text returned empty content");
-}
-
-#[test]
-#[cfg(target_os = "windows")]
-#[ignore = "sends real input to a live desktop window; run with --ignored only on a disposable desktop"]
-fn type_text_notepad() {
- //! Launch Notepad, type a short string via type_text. Skips if Notepad unavailable.
- let Some(mut d) = spawn_unrestricted() else {
- return;
- };
-
- d.send(&serde_json::json!({"jsonrpc":"2.0","id":1,"method":"initialize","params":{}}));
- d.recv();
-
- // Launch Notepad.
- d.send(&serde_json::json!({
- "jsonrpc":"2.0","id":2,"method":"tools/call",
- "params":{"name":"launch_app","arguments":{"name":"notepad.exe"}}
- }));
- d.recv();
- std::thread::sleep(std::time::Duration::from_millis(1000));
-
- // Find Notepad in running processes.
- d.send(&serde_json::json!({
- "jsonrpc":"2.0","id":3,"method":"tools/call",
- "params":{"name":"list_apps","arguments":{}}
- }));
- let resp = d.recv();
- let procs = resp["result"]["structuredContent"]["processes"].as_array();
- let Some(proc_) = procs.and_then(|a| {
- a.iter().find(|p| {
- p["name"]
- .as_str()
- .map(|n| n.to_lowercase().contains("notepad"))
- .unwrap_or(false)
- })
- }) else {
- eprintln!("Notepad not found — skipping type_text test");
- return;
- };
- let pid = proc_["pid"].as_i64().unwrap();
-
- // Find Notepad's window.
- d.send(&serde_json::json!({
- "jsonrpc":"2.0","id":4,"method":"tools/call",
- "params":{"name":"list_windows","arguments":{"pid":pid,"on_screen_only":true}}
- }));
- let resp = d.recv();
- let wins = resp["result"]["structuredContent"]["windows"].as_array();
- let Some(win) = wins.and_then(|a| a.first()) else {
- eprintln!("Notepad has no on-screen windows — skipping type_text test");
- return;
- };
- let wid = win["window_id"].as_u64().unwrap();
-
- d.send(&serde_json::json!({
- "jsonrpc":"2.0","id":5,"method":"tools/call",
- "params":{"name":"type_text","arguments":{"pid":pid,"window_id":wid,"text":"cua-test"}}
- }));
- let resp = d.recv();
- assert!(
- resp["error"].is_null(),
- "Protocol error from type_text: {resp:?}"
- );
- assert!(!resp["result"]["content"]
- .as_array()
- .map(|a| a.is_empty())
- .unwrap_or(true));
-}
-
#[test]
#[cfg(target_os = "macos")]
#[ignore = "sends real input to a live desktop window; run with --ignored only on a disposable desktop"]
@@ -760,342 +574,3 @@ fn type_text_chars_tool() {
"Unexpected message: {msg}"
);
}
-
-#[test]
-#[cfg(any(target_os = "macos", target_os = "windows"))]
-#[ignore = "sends real input to a live desktop window; run with --ignored only on a disposable desktop"]
-fn hotkey_keys_array() {
- //! Verify hotkey accepts a keys array without a protocol error.
- let Some(mut d) = spawn_unrestricted() else {
- return;
- };
-
- d.send(&serde_json::json!({"jsonrpc":"2.0","id":1,"method":"initialize","params":{}}));
- d.recv();
-
- d.send(&serde_json::json!({
- "jsonrpc":"2.0","id":2,"method":"tools/call",
- "params":{"name":"list_windows","arguments":{}}
- }));
- let resp = d.recv();
- let windows = resp["result"]["structuredContent"]["windows"].as_array();
- let first_win = windows.and_then(|a| a.iter().find(|w| w["pid"].as_i64().is_some()));
-
- let Some(win) = first_win else {
- eprintln!("No windows found — skipping hotkey keys array test");
- return;
- };
- let pid = win["pid"].as_i64().unwrap();
- let wid = win["window_id"].as_u64().unwrap();
-
- // keys array should be parsed and the tool invoked; result may succeed or fail depending
- // on whether the target app accepts the hotkey, but there must be no protocol error.
- // Windows uses ["ctrl","a"]; macOS uses ["cmd","a"].
- let keys = if cfg!(target_os = "windows") {
- serde_json::json!(["ctrl", "a"])
- } else {
- serde_json::json!(["cmd", "a"])
- };
- d.send(&serde_json::json!({
- "jsonrpc":"2.0","id":3,"method":"tools/call",
- "params":{"name":"hotkey","arguments":{
- "pid": pid, "window_id": wid, "keys": keys
- }}
- }));
- let resp = d.recv();
- assert!(
- resp["error"].is_null(),
- "Protocol error from hotkey: {resp:?}"
- );
- let content = resp["result"]["content"].as_array().expect("content array");
- assert!(!content.is_empty(), "hotkey should return content");
-}
-
-#[test]
-#[cfg(any(target_os = "macos", target_os = "windows"))]
-#[ignore = "sends real input to a live desktop window; run with --ignored only on a disposable desktop"]
-fn press_key_harmless() {
- //! press_key with a harmless key (F24 — virtually no app responds to it) sent to the
- //! first available window. Just verifies the tool doesn't return a protocol error.
- let Some(mut d) = spawn_unrestricted() else {
- return;
- };
-
- d.send(&serde_json::json!({"jsonrpc":"2.0","id":1,"method":"initialize","params":{}}));
- d.recv();
-
- // Find a window to target.
- d.send(&serde_json::json!({
- "jsonrpc":"2.0","id":2,"method":"tools/call",
- "params":{"name":"list_windows","arguments":{}}
- }));
- let resp = d.recv();
- let wins = resp["result"]["structuredContent"]["windows"].as_array();
- let Some(win) = wins.and_then(|a| a.iter().find(|w| w["pid"].as_i64().is_some())) else {
- eprintln!("No windows found — skipping press_key test");
- return;
- };
- let pid = win["pid"].as_i64().unwrap();
- let wid = win["window_id"].as_u64().unwrap();
-
- // F24 is a function key that virtually no app binds — safe to send.
- d.send(&serde_json::json!({
- "jsonrpc":"2.0","id":3,"method":"tools/call",
- "params":{"name":"press_key","arguments":{"pid": pid, "window_id": wid, "key": "F24"}}
- }));
- let resp = d.recv();
- assert!(
- resp["error"].is_null(),
- "Protocol error from press_key: {resp:?}"
- );
- // Tool may succeed or return an app error, but must NOT be a protocol-level error.
- let content = resp["result"]["content"].as_array().expect("content array");
- assert!(!content.is_empty(), "press_key returned empty content");
-}
-
-#[test]
-#[cfg(any(target_os = "macos", target_os = "windows"))]
-#[ignore = "sends real input to a live desktop window; run with --ignored only on a disposable desktop"]
-fn click_pixel_path() {
- //! click at window-local (5, 5) — title bar area, safe to click without disrupting UI.
- //! Verifies the pixel-coordinate path for click works without a protocol error.
- let Some(mut d) = spawn_unrestricted() else {
- return;
- };
-
- d.send(&serde_json::json!({"jsonrpc":"2.0","id":1,"method":"initialize","params":{}}));
- d.recv();
-
- // Find an on-screen window.
- d.send(&serde_json::json!({
- "jsonrpc":"2.0","id":2,"method":"tools/call",
- "params":{"name":"list_windows","arguments":{"on_screen_only": true}}
- }));
- let resp = d.recv();
- let wins = resp["result"]["structuredContent"]["windows"].as_array();
- let Some(win) = wins.and_then(|a| a.iter().find(|w| w["pid"].as_i64().is_some())) else {
- eprintln!("No on-screen windows — skipping click pixel path test");
- return;
- };
- let pid = win["pid"].as_i64().unwrap();
- let wid = win["window_id"].as_u64().unwrap();
-
- // Click at (5, 5) in window-local coords — title bar, harmless.
- d.send(&serde_json::json!({
- "jsonrpc":"2.0","id":3,"method":"tools/call",
- "params":{"name":"click","arguments":{"pid": pid, "window_id": wid, "x": 5.0, "y": 5.0}}
- }));
- let resp = d.recv();
- assert!(
- resp["error"].is_null(),
- "Protocol error from click: {resp:?}"
- );
- let content = resp["result"]["content"].as_array().expect("content array");
- assert!(!content.is_empty(), "click returned empty content");
-}
-
-#[test]
-#[cfg(target_os = "windows")]
-#[ignore = "sends real input to a live desktop window; run with --ignored only on a disposable desktop"]
-fn double_click_and_right_click() {
- let Some(mut d) = spawn_unrestricted() else {
- return;
- };
-
- d.send(&serde_json::json!({"jsonrpc":"2.0","id":1,"method":"initialize","params":{}}));
- d.recv();
-
- d.send(&serde_json::json!({
- "jsonrpc":"2.0","id":2,"method":"tools/call",
- "params":{"name":"list_windows","arguments":{"on_screen_only":true}}
- }));
- let resp = d.recv();
- let wins = resp["result"]["structuredContent"]["windows"].as_array();
- let Some(win) = wins.and_then(|a| a.iter().find(|w| w["pid"].as_i64().is_some())) else {
- eprintln!("No on-screen windows — skipping double/right click test");
- return;
- };
- let pid = win["pid"].as_i64().unwrap();
- let wid = win["window_id"].as_u64().unwrap();
-
- d.send(&serde_json::json!({
- "jsonrpc":"2.0","id":3,"method":"tools/call",
- "params":{"name":"double_click","arguments":{"pid":pid,"window_id":wid,"x":5.0,"y":5.0}}
- }));
- let resp = d.recv();
- assert!(
- resp["error"].is_null(),
- "Protocol error from double_click: {resp:?}"
- );
- assert!(!resp["result"]["content"]
- .as_array()
- .map(|a| a.is_empty())
- .unwrap_or(true));
-
- d.send(&serde_json::json!({
- "jsonrpc":"2.0","id":4,"method":"tools/call",
- "params":{"name":"right_click","arguments":{"pid":pid,"window_id":wid,"x":5.0,"y":5.0}}
- }));
- let resp = d.recv();
- assert!(
- resp["error"].is_null(),
- "Protocol error from right_click: {resp:?}"
- );
- assert!(!resp["result"]["content"]
- .as_array()
- .map(|a| a.is_empty())
- .unwrap_or(true));
-}
-
-#[test]
-#[cfg(target_os = "macos")]
-#[ignore = "sends real input to a live desktop window; run with --ignored only on a disposable desktop"]
-fn double_click_and_right_click_pixel_path() {
- //! double_click and right_click at title-bar coords — verifies both tools accept pixel path.
- let Some(mut d) = spawn_unrestricted() else {
- return;
- };
-
- d.send(&serde_json::json!({"jsonrpc":"2.0","id":1,"method":"initialize","params":{}}));
- d.recv();
-
- d.send(&serde_json::json!({
- "jsonrpc":"2.0","id":2,"method":"tools/call",
- "params":{"name":"list_windows","arguments":{"on_screen_only": true}}
- }));
- let resp = d.recv();
- let wins = resp["result"]["structuredContent"]["windows"].as_array();
- let Some(win) = wins.and_then(|a| a.iter().find(|w| w["pid"].as_i64().is_some())) else {
- eprintln!("No on-screen windows — skipping double/right click test");
- return;
- };
- let pid = win["pid"].as_i64().unwrap();
- let wid = win["window_id"].as_u64().unwrap();
-
- // double_click at safe coords.
- d.send(&serde_json::json!({
- "jsonrpc":"2.0","id":3,"method":"tools/call",
- "params":{"name":"double_click","arguments":{"pid": pid, "window_id": wid, "x": 5.0, "y": 5.0}}
- }));
- let resp = d.recv();
- assert!(
- resp["error"].is_null(),
- "Protocol error from double_click: {resp:?}"
- );
- assert!(
- !resp["result"]["content"]
- .as_array()
- .map(|a| a.is_empty())
- .unwrap_or(true),
- "double_click returned empty content"
- );
-
- // right_click at same coords.
- d.send(&serde_json::json!({
- "jsonrpc":"2.0","id":4,"method":"tools/call",
- "params":{"name":"right_click","arguments":{"pid": pid, "window_id": wid, "x": 5.0, "y": 5.0}}
- }));
- let resp = d.recv();
- assert!(
- resp["error"].is_null(),
- "Protocol error from right_click: {resp:?}"
- );
- assert!(
- !resp["result"]["content"]
- .as_array()
- .map(|a| a.is_empty())
- .unwrap_or(true),
- "right_click returned empty content"
- );
-}
-
-#[test]
-#[cfg(target_os = "macos")]
-#[ignore = "sends real input to a live desktop window; run with --ignored only on a disposable desktop"]
-fn set_value_via_element_index() {
- //! get_window_state on TextEdit → find a text-area element → set_value on it.
- //! Skips gracefully if TextEdit is not available.
- let Some(mut d) = spawn_unrestricted() else {
- return;
- };
-
- d.send(&serde_json::json!({"jsonrpc":"2.0","id":1,"method":"initialize","params":{}}));
- d.recv();
-
- // Ensure TextEdit is running.
- d.send(&serde_json::json!({
- "jsonrpc":"2.0","id":2,"method":"tools/call",
- "params":{"name":"launch_app","arguments":{"name":"TextEdit"}}
- }));
- d.recv();
- std::thread::sleep(std::time::Duration::from_millis(800));
-
- // Find TextEdit.
- d.send(&serde_json::json!({
- "jsonrpc":"2.0","id":3,"method":"tools/call",
- "params":{"name":"list_apps","arguments":{}}
- }));
- let resp = d.recv();
- let apps = resp["result"]["structuredContent"]["apps"].as_array();
- let Some(app) = apps.and_then(|a| {
- a.iter().find(|a| {
- a["name"]
- .as_str()
- .map(|n| n.eq_ignore_ascii_case("textedit"))
- .unwrap_or(false)
- })
- }) else {
- eprintln!("TextEdit not found — skipping set_value test");
- return;
- };
- let pid = app["pid"].as_i64().unwrap();
-
- // Get first window.
- d.send(&serde_json::json!({
- "jsonrpc":"2.0","id":4,"method":"tools/call",
- "params":{"name":"list_windows","arguments":{"pid": pid, "on_screen_only": true}}
- }));
- let resp = d.recv();
- let wins = resp["result"]["structuredContent"]["windows"].as_array();
- let Some(win) = wins.and_then(|a| a.first()) else {
- eprintln!("TextEdit has no on-screen windows — skipping set_value test");
- return;
- };
- let wid = win["window_id"].as_u64().unwrap();
-
- // Walk AX tree to get element_count — we'll target element_index 0.
- d.send(&serde_json::json!({
- "jsonrpc":"2.0","id":5,"method":"tools/call",
- "params":{"name":"get_window_state","arguments":{"pid": pid, "window_id": wid, "capture_mode": "ax"}}
- }));
- let resp = d.recv();
- assert!(
- resp["error"].is_null(),
- "Protocol error from get_window_state: {resp:?}"
- );
- let element_count = resp["result"]["structuredContent"]["element_count"]
- .as_u64()
- .unwrap_or(0);
- if element_count == 0 {
- eprintln!("No AX elements — skipping set_value test");
- return;
- }
- let snapshot_id = resp["result"]["structuredContent"]["snapshot_id"]
- .as_str()
- .expect("get_window_state snapshot_id")
- .to_owned();
-
- // set_value on element 0 — this is the document / text area in a new TextEdit document.
- d.send(&serde_json::json!({
- "jsonrpc":"2.0","id":6,"method":"tools/call",
- "params":{"name":"set_value","arguments":{"pid": pid, "window_id": wid, "element_index": 0, "snapshot_id": snapshot_id, "value": "cua-test-value"}}
- }));
- let resp = d.recv();
- // set_value may fail if element 0 is not settable; accept tool-level errors but not protocol errors.
- assert!(
- resp["error"].is_null(),
- "Protocol error from set_value: {resp:?}"
- );
- let content = resp["result"]["content"].as_array().expect("content array");
- assert!(!content.is_empty(), "set_value returned empty content");
-}
diff --git a/libs/cua-driver/rust/crates/cua-driver/tests/release_channel_cli_test.rs b/libs/cua-driver/rust/crates/cua-driver/tests/release_channel_cli_test.rs
index b7f004335d..e735cb221d 100644
--- a/libs/cua-driver/rust/crates/cua-driver/tests/release_channel_cli_test.rs
+++ b/libs/cua-driver/rust/crates/cua-driver/tests/release_channel_cli_test.rs
@@ -41,6 +41,17 @@ fn channel_cli_persists_and_reports_the_selected_channel() {
);
let status: serde_json::Value = serde_json::from_slice(&status.stdout).expect("status json");
assert_eq!(status["selected_channel"], "nightly");
+
+ let restored = run(home.path(), &["channel", "set", "stable", "--json"]);
+ assert!(
+ restored.status.success(),
+ "{}",
+ String::from_utf8_lossy(&restored.stderr)
+ );
+ assert_eq!(
+ std::fs::read_to_string(home.path().join("release-channel")).expect("saved preference"),
+ "stable\n"
+ );
}
#[test]
diff --git a/libs/cua-driver/rust/crates/cua-driver/tests/schema_consistency_test.rs b/libs/cua-driver/rust/crates/cua-driver/tests/schema_consistency_test.rs
index 8183b7b9ea..1f6dc63394 100644
--- a/libs/cua-driver/rust/crates/cua-driver/tests/schema_consistency_test.rs
+++ b/libs/cua-driver/rust/crates/cua-driver/tests/schema_consistency_test.rs
@@ -51,6 +51,17 @@ fn registered_tool_contracts_match_on_active_backend() {
let mut violations: Vec<String> = Vec::new();
for tool in tools {
let name = tool["name"].as_str().unwrap_or("<unnamed>");
+ // Consumers route by capability token and read annotations, so every
+ // entry carries both, even when the capability list is empty.
+ if !tool["capabilities"].is_array() {
+ violations.push(format!("{name}: capabilities array is missing"));
+ }
+ if !tool["annotations"].is_object() {
+ violations.push(format!("{name}: annotations object is missing"));
+ }
+ if !tool["description"].is_string() {
+ violations.push(format!("{name}: description is missing"));
+ }
match tool.pointer("/risk/class").and_then(|value| value.as_str()) {
Some("unclassified") => {
violations.push(format!("{name}: risk class is unclassified"));
diff --git a/libs/cua-driver/rust/crates/cua-driver/tests/transport_config_persistence_test.rs b/libs/cua-driver/rust/crates/cua-driver/tests/transport_config_persistence_test.rs
index 4ee00c9d6f..cb553e1700 100644
--- a/libs/cua-driver/rust/crates/cua-driver/tests/transport_config_persistence_test.rs
+++ b/libs/cua-driver/rust/crates/cua-driver/tests/transport_config_persistence_test.rs
@@ -1,23 +1,21 @@
-//! Transport axis: `set_config` visibility across the CLI vs MCP transports.
+//! Transport axis: CLI `set_config` visibility across daemon-backed shell
+//! processes.
//!
-//! This is the one behavior that only shows up when a test covers BOTH
-//! transports, so it lives on the shared testkit `Driver` abstraction:
-//!
-//! - **CLI** (`CliDriver`) starts a fresh shell process for each call, but all
-//! calls go through one test-owned daemon.
-//! - **MCP** (`McpDriver`) is one long-lived proxy connection to its own
-//! test-owned daemon.
+//! `CliDriver` starts a fresh shell process for each call, but all calls go
+//! through one test-owned daemon, so a `set_config` in one process must be
+//! visible to the next. MCP in-session visibility is owned by
+//! `protocol_tools_call_test::get_config_and_check_permissions`.
//!
//! Uses `max_image_dimension` as the persisted key. `capture_mode` /
//! `capture_scope` are NO LONGER settings (`capture_scope` is per-session), so
//! `max_image_dimension` is the remaining
//! disk-persisted config field and the right probe for this transport behavior.
//!
-//! Both tests are `#[ignore]`: they mutate the real on-disk config, so they
-//! save the prior value and restore it. Run explicitly:
+//! The test is `#[ignore]`: an anonymous CLI `set_config` mutates the real
+//! on-disk config, so it saves the prior value and restores it. Run explicitly:
//! cargo test -p cua-driver --test transport_config_persistence_test -- --ignored --nocapture
-use cua_driver_testkit::{CliDriver, Driver, McpDriver};
+use cua_driver_testkit::{CliDriver, Driver};
const KEY: &str = "max_image_dimension";
/// A distinctive probe value unlikely to be the current setting.
@@ -64,40 +62,3 @@ fn cli_set_config_visible_across_daemon_backed_invocations() {
);
}
}
-
-/// MCP: a `set_config` is visible to a later call on the SAME long-lived driver
-/// (session scope). Restores the prior value before dropping the connection.
-#[test]
-#[ignore]
-fn mcp_set_config_visible_within_session() {
- let Some(mut driver) = McpDriver::spawn() else {
- return;
- };
-
- let original = config_max_dim(
- driver
- .call("get_config", serde_json::json!({}))
- .structured(),
- );
-
- let set = driver.call(
- "set_config",
- serde_json::json!({ "key": KEY, "value": PROBE }),
- );
- assert!(!set.is_error(), "MCP set_config errored: {}", set.text());
-
- let after = driver.call("get_config", serde_json::json!({}));
- assert_eq!(
- config_max_dim(after.structured()),
- Some(PROBE),
- "MCP set_config not visible within the same session: {}",
- after.text()
- );
-
- if let Some(orig) = original {
- let _ = driver.call(
- "set_config",
- serde_json::json!({ "key": KEY, "value": orig }),
- );
- }
-}