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(spaces): tell a Windows PC without QEMU before a virtual computer create (CUA-2089) (#5755)
Francesco Bonacci1b99a27ee41a
diff --git a/libs/cua/crates/cua-daemon/src/local.rs b/libs/cua/crates/cua-daemon/src/local.rsindex eb9e144b30..3d635a5c17 100644--- a/libs/cua/crates/cua-daemon/src/local.rs+++ b/libs/cua/crates/cua-daemon/src/local.rs@@ -2422,7 +2422,7 @@ async fn preflight_refusal(os: cua_vmm::GuestOs, backend: BackendKind) -> Runtimlet req = cua_vmm::preflight::request(cua_vmm::preflight::guest_of(os), runs, None);let mut facts = cua_vmm::preflight::gather(&req).await;facts.free_bytes = None;- match cua_create_failure::preflight::evaluate(&req, &facts)+ match cua_vmm::preflight::evaluate(&req, &facts).into_iter().next(){diff --git a/libs/cua/crates/cua-spaces-app-core/src/wizard.rs b/libs/cua/crates/cua-spaces-app-core/src/wizard.rsindex c0dd50d222..c3abab5eaa 100644--- a/libs/cua/crates/cua-spaces-app-core/src/wizard.rs+++ b/libs/cua/crates/cua-spaces-app-core/src/wizard.rs@@ -1185,6 +1185,12 @@ fn local_engine_detail(image: &SandboxImage, env: &WizardEnv) -> Option<String>})}+/// What a Windows PC without QEMU is told (the same words as the daemon's+/// preflight, `cua_vmm::preflight::QEMU_MISSING_WINDOWS`).+const WINDOWS_QEMU_MISSING: &str = "Virtual computers on Windows need a free program called QEMU, \+ and it isn't installed on this PC. Install it from qemu.org (the Windows download), then try \+ again.";+/// This Mac can run `image` now: a local runtime answers, and one of the/// image's engines is among the doctor's ready ones. While that list is not/// known, every engine counts as ready except QEMU: the app never installs@@ -3460,9 +3466,22 @@ pub fn view_on(state: &WizardState, env: &WizardEnv, os: SpaceOs) -> WizardViewSome(LocalEngine::Qemu) => "QEMU",_ => "container",};- match local_engine_detail(&image, env) {- Some(why) => format!("{} cannot run {what} Spaces: {why}.", os.this_machine()),- None => format!("{} cannot run {what} Spaces.", os.this_machine()),+ let why = local_engine_detail(&image, env);+ if image.local == Some(LocalEngine::Qemu)+ && os == SpaceOs::Windows+ && why+ .as_deref()+ .is_none_or(|w| w.starts_with("QEMU not found"))+ {+ // Cua never installs QEMU on Windows: say what to get.+ WINDOWS_QEMU_MISSING.to_string()+ } else {+ match why {+ Some(why) => {+ format!("{} cannot run {what} Spaces: {why}.", os.this_machine())+ }+ None => format!("{} cannot run {what} Spaces.", os.this_machine()),+ }}} else {env.local_reason@@ -4076,10 +4095,7 @@ mod tests {local_backends: None,..env()};- assert_eq!(- blocked(&unknown).as_deref(),- Some("This PC cannot run QEMU Spaces.")- );+ assert_eq!(blocked(&unknown).as_deref(), Some(WINDOWS_QEMU_MISSING));// Docker Desktop is up, QEMU is not: the doctor's reason.let docker_only = WizardEnv {local_backends: Some(vec!["container".into()]),@@ -4092,13 +4108,7 @@ mod tests {),..env()};- assert_eq!(- blocked(&docker_only).as_deref(),- Some(- "This PC cannot run QEMU Spaces: QEMU not found; missing: qemu-system-x86_64 \- / qemu-img."- )- );+ assert_eq!(blocked(&docker_only).as_deref(), Some(WINDOWS_QEMU_MISSING));// A Linux container is still offered with the same env.let linux = reduce(&initial(&unknown),diff --git a/libs/cua/crates/cua-vmm/src/auto.rs b/libs/cua/crates/cua-vmm/src/auto.rsindex 3a27d6c8eb..bbc5bb28ed 100644--- a/libs/cua/crates/cua-vmm/src/auto.rs+++ b/libs/cua/crates/cua-vmm/src/auto.rs@@ -925,7 +925,14 @@ pub fn select(req: &SelectRequest, report: &DoctorReport) -> Result<Selection> {provisioning: l.provisioning,});}- Err(VmmError::missing("QEMU", q.missing.join(", ")))+ Err(VmmError::missing(+ "QEMU",+ if host.os == HostOs::Windows {+ crate::preflight::QEMU_MISSING_WINDOWS.to_string()+ } else {+ q.missing.join(", ")+ },+ ))}},}diff --git a/libs/cua/crates/cua-vmm/src/host.rs b/libs/cua/crates/cua-vmm/src/host.rsindex b7debdd444..a3a1658c97 100644--- a/libs/cua/crates/cua-vmm/src/host.rs+++ b/libs/cua/crates/cua-vmm/src/host.rs@@ -88,11 +88,27 @@ pub fn which(name: &str) -> Option<PathBuf> {}dirs.push(home_dir().join(".local/bin"));dirs.push(cua_home().join("bin"));+ dirs.extend(windows_install_dirs());dirs.into_iter().map(|d| d.join(&exe)).find(|p| is_executable(p))}+/// Where Windows installers put tools without adding them to `PATH`. The+/// QEMU installer is one: it installs to `C:\Program Files\qemu` and+/// leaves `PATH` alone, so a PC that has QEMU would still look as if it+/// did not.+fn windows_install_dirs() -> Vec<PathBuf> {+ if !cfg!(windows) {+ return Vec::new();+ }+ ["ProgramFiles", "ProgramW6432", "ProgramFiles(x86)"]+ .iter()+ .filter_map(std::env::var_os)+ .map(|d| PathBuf::from(d).join("qemu"))+ .collect()+}+fn is_executable(p: &Path) -> bool {#[cfg(unix)]{diff --git a/libs/cua/crates/cua-vmm/src/preflight.rs b/libs/cua/crates/cua-vmm/src/preflight.rsindex ccad8c48bc..c0d911bd28 100644--- a/libs/cua/crates/cua-vmm/src/preflight.rs+++ b/libs/cua/crates/cua-vmm/src/preflight.rs@@ -8,12 +8,21 @@use std::collections::BTreeMap;use cua_create_failure::preflight::{- self as pf, Engine, Facts, Guest, Host, Issue, Request, Runs, VirtGap,+ self as pf, Engine, Facts, FixAction, Guest, Host, Issue, IssueKind, Request, Runs, VirtGap,};use crate::disk::{CONTAINER_PULL_ESTIMATE, GIB, LUME_PULL_ESTIMATE, VM_CREATE_ESTIMATE};use crate::types::GuestOs;+/// What a Windows PC without QEMU is told. Cua never installs QEMU on+/// Windows, so a virtual computer cannot start until the person does.+pub const QEMU_MISSING_WINDOWS: &str = "Virtual computers on Windows need a free program called \+ QEMU, and it isn't installed on this PC. Install it from qemu.org (the Windows download), \+ then try again.";++/// Where the QEMU download for Windows is.+pub const QEMU_WINDOWS_URL: &str = "https://www.qemu.org/download/#windows";+/// A Windows VM image and its disk: bigger than a Linux VM's.pub const WINDOWS_VM_ESTIMATE: u64 = 20 * GIB;@@ -79,7 +88,39 @@ pub async fn gather(req: &Request) -> Facts {/// The failed checks for creating `req` here, most important first. Empty:/// go ahead.pub async fn check(req: &Request) -> Vec<Issue> {- pf::evaluate(req, &gather(req).await)+ evaluate(req, &gather(req).await)+}++/// [`pf::evaluate`] plus the checks that need the host's own tools: on a+/// Windows PC, whether QEMU is there to run a virtual computer.+pub fn evaluate(req: &Request, facts: &Facts) -> Vec<Issue> {+ let mut out = pf::evaluate(req, facts);+ if let Some(issue) = qemu_issue(req, qemu_installed) {+ out.insert(0, issue);+ }+ out+}++fn qemu_installed() -> bool {+ let arch = crate::types::Arch::host();+ crate::host::which(&format!("qemu-system-{}", arch.qemu())).is_some()+ && crate::host::which("qemu-img").is_some()+}++/// Windows is the one host Cua never sets QEMU up on, so a VM there needs+/// it installed first. `installed` is only asked when it matters.+fn qemu_issue(req: &Request, installed: impl FnOnce() -> bool) -> Option<Issue> {+ if req.host != Host::Windows || req.runs != Runs::Vm || installed() {+ return None;+ }+ Some(Issue {+ kind: IssueKind::VirtualizationUnavailable,+ message: QEMU_MISSING_WINDOWS.to_string(),+ fix: Some(pf::Fix {+ label: "Get QEMU".into(),+ action: FixAction::OpenUrl(QEMU_WINDOWS_URL.into()),+ }),+ })}/// [`check`] for the Spaces a shell can offer, by name (`linux_container`,@@ -104,7 +145,7 @@ pub async fn report() -> BTreeMap<String, Vec<Issue>> {// create's own disk guards decide.let mut facts = gather(&req).await;facts.free_bytes = None;- out.insert(name.to_string(), pf::evaluate(&req, &facts));+ out.insert(name.to_string(), evaluate(&req, &facts));}out}@@ -196,6 +237,42 @@ mod tests {);}+ #[test]+ fn a_windows_pc_without_qemu_is_told_before_a_vm_create() {+ let vm = request(Guest::Windows, Runs::Vm, None);+ let on_windows = Request {+ host: Host::Windows,+ ..vm+ };+ let issue = qemu_issue(&on_windows, || false).expect("QEMU is missing");+ assert_eq!(issue.message, QEMU_MISSING_WINDOWS);+ assert_eq!(+ issue.fix.unwrap().action,+ FixAction::OpenUrl(QEMU_WINDOWS_URL.into())+ );+ // QEMU there, a container, or another host: nothing to say, and the+ // lookup is not even made.+ assert!(qemu_issue(&on_windows, || true).is_none());+ let container = Request {+ runs: Runs::Container,+ ..on_windows+ };+ assert!(qemu_issue(&container, || unreachable!()).is_none());+ let on_linux = Request {+ host: Host::Linux,+ ..on_windows+ };+ assert!(qemu_issue(&on_linux, || unreachable!()).is_none());+ }++ #[test]+ fn the_qemu_sentence_is_plain() {+ let text = QEMU_MISSING_WINDOWS.to_lowercase();+ assert!(+ !text.contains('\u{2014}') && !text.contains("hypervisor") && !text.contains("path")+ );+ }+#[tokio::test]async fn the_report_names_every_space_this_host_can_run() {let r = report().await;