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(spaces): New Space Continue did nothing for a Windows image on a Windows PC (#6724)

ddupont2f2af6925c21
diff --git a/apps/cua-spaces-web/src/bridge/new-space.ts b/apps/cua-spaces-web/src/bridge/new-space.ts
index 035a9b4e3f..c84e1179c9 100644
--- a/apps/cua-spaces-web/src/bridge/new-space.ts
+++ b/apps/cua-spaces-web/src/bridge/new-space.ts
@@ -53,8 +53,9 @@ export function nameSeed(): number {
}
export const wizardInitial = (core: CoreClient, env: WizardEnv) =>
core.call<WizardState>("wizard.initial", { env: env.nameSeed == null ? { ...env, nameSeed: nameSeed() } : env });
-export const wizardReduce = (core: CoreClient, state: WizardState, action: WizardAction, env: WizardEnv) =>
- core.call<WizardState>("wizard.reduce", { state, action, env });
+/** Advances the wizard; `os` is the system the app runs on, which decides whether Continue is allowed. */
+export const wizardReduce = (core: CoreClient, state: WizardState, action: WizardAction, env: WizardEnv, os: HostOs = hostOs()) =>
+ core.call<WizardState>("wizard.reduce", { state, action, env, hostOs: os });
/** The wizard as drawn, in the words of the system the app runs on (`hostOs`). */
export const wizardView = (core: CoreClient, state: WizardState, env: WizardEnv, os: HostOs = hostOs()) =>
core.call<WizardView>("wizard.view", { state, env, hostOs: os });
diff --git a/apps/cua-spaces/src/components/desktop/NewSpaceWizard.test.tsx b/apps/cua-spaces/src/components/desktop/NewSpaceWizard.test.tsx
index cb6158147e..287d2442e9 100644
--- a/apps/cua-spaces/src/components/desktop/NewSpaceWizard.test.tsx
+++ b/apps/cua-spaces/src/components/desktop/NewSpaceWizard.test.tsx
@@ -486,6 +486,16 @@ describe("QEMU VMs", () => {
pick("ghcr.io/trycua/windows:2022");
expect(continueButton()).toBeEnabled();
});
+
+ it("go on to the next step on a Windows PC when Continue is enabled (it did nothing)", () => {
+ vi.spyOn(navigator, "platform", "get").mockReturnValue("Win32");
+ renderWizard({ localBackends: ["docker", "qemu"] });
+ runOn("local");
+ pick("ghcr.io/trycua/windows:2022");
+ expect(continueButton()).toBeEnabled();
+ next();
+ expect(screen.getByRole("slider", { name: "CPU cores" })).toBeInTheDocument();
+ });
});
describe("default placement", () => {
diff --git a/apps/cua-spaces/src/components/desktop/NewSpaceWizard.tsx b/apps/cua-spaces/src/components/desktop/NewSpaceWizard.tsx
index 7d367ba1a3..323331389e 100644
--- a/apps/cua-spaces/src/components/desktop/NewSpaceWizard.tsx
+++ b/apps/cua-spaces/src/components/desktop/NewSpaceWizard.tsx
@@ -297,7 +297,7 @@ export function NewSpaceWizard({
);
const [state, setState] = useState<WizardState>(() =>
(quick ? [{ type: "choose-os", os: quick }] : (startActions ?? [])).reduce<WizardState>(
- (s, action) => core<WizardState>("wizard.reduce", { state: s, action, env }),
+ (s, action) => core<WizardState>("wizard.reduce", { state: s, action, env, hostOs: hostOs() }),
// The wasm core has no randomness: a seed for the name an unnamed
// Space gets (the core shows it and creates the Space with it).
core<WizardState>("wizard.initial", { env: { ...env, nameSeed: nameSeed() } }),
@@ -311,11 +311,11 @@ export function NewSpaceWizard({
onCancel();
};
const dispatch = (action: WizardAction) =>
- setState((s) => core<WizardState>("wizard.reduce", { state: s, action, env }));
+ setState((s) => core<WizardState>("wizard.reduce", { state: s, action, env, hostOs: hostOs() }));
// Until the person picks, follow the configured default (it can arrive
// after the sheet opens); the core ignores it once they picked.
useEffect(() => {
- setState((s) => core<WizardState>("wizard.reduce", { state: s, action: { type: "sync-default", location: defaultLocation }, env }));
+ setState((s) => core<WizardState>("wizard.reduce", { state: s, action: { type: "sync-default", location: defaultLocation }, env, hostOs: hostOs() }));
}, [defaultLocation, env]);
const v = core<WizardView>("wizard.view", { state, env, hostOs: hostOs() });
// Before paint, so a quick create never shows the sheet; once, because StrictMode runs mount effects twice.
diff --git a/libs/cua/crates/cua-spaces-app-core/src/dispatch.rs b/libs/cua/crates/cua-spaces-app-core/src/dispatch.rs
index a30d8ab9b6..33dc40db42 100644
--- a/libs/cua/crates/cua-spaces-app-core/src/dispatch.rs
+++ b/libs/cua/crates/cua-spaces-app-core/src/dispatch.rs
@@ -585,10 +585,14 @@ pub fn call_value(method: &str, args: Value) -> Result<Value, CoreError> {
a.get::<Option<String>>("keyvault")?.as_deref(),
)),
"wizard.initial" => out(wizard::initial(&a.get("env")?)),
- "wizard.reduce" => out(wizard::reduce(
+ // `hostOs`: the shell's system, which decides whether Continue is
+ // allowed (macOS when absent).
+ "wizard.reduce" => out(wizard::reduce_on(
&a.get("state")?,
&a.get("action")?,
&a.get("env")?,
+ a.get::<Option<SpaceOs>>("hostOs")?
+ .unwrap_or(SpaceOs::Macos),
)),
// `hostOs`: the shell's system, for its words (macOS when absent).
"wizard.view" => out(wizard::view_on(
diff --git a/libs/cua/crates/cua-spaces-app-core/src/wizard.rs b/libs/cua/crates/cua-spaces-app-core/src/wizard.rs
index b970a744bd..28c9380285 100644
--- a/libs/cua/crates/cua-spaces-app-core/src/wizard.rs
+++ b/libs/cua/crates/cua-spaces-app-core/src/wizard.rs
@@ -2215,6 +2215,19 @@ fn rebase(state: &mut WizardState, image_ref: &str) {
/// Advances the wizard. `env` decides whether Continue is allowed.
pub fn reduce(state: &WizardState, action: &WizardAction, env: &WizardEnv) -> WizardState {
+ reduce_on(state, action, env, SpaceOs::Macos)
+}
+
+/// [`reduce`] in a shell on `os`. Continue is allowed by the view the person
+/// sees ([`view_on`]), so the shell must name its system here too: judged as
+/// a Mac, the Windows image is "coming soon" and Continue silently did
+/// nothing on a Windows PC.
+pub fn reduce_on(
+ state: &WizardState,
+ action: &WizardAction,
+ env: &WizardEnv,
+ os: SpaceOs,
+) -> WizardState {
let mut s = state.clone();
match action {
WizardAction::SyncDefault { location } => {
@@ -2388,7 +2401,7 @@ pub fn reduce(state: &WizardState, action: &WizardAction, env: &WizardEnv) -> Wi
// A typed value is used first (one that breaks the limits
// keeps the step, with why).
commit_resource(&mut s, env);
- if s.step < 3 && view(&s, env).can_continue {
+ if s.step < 3 && view_on(&s, env, os).can_continue {
s.step += 1;
}
}
@@ -4812,6 +4825,35 @@ mod tests {
assert_eq!(tile.title, "Windows");
}
+ /// Continue is judged for the system the shell runs on: on a Windows PC
+ /// the Windows image advances the wizard (judged as a Mac it silently
+ /// stayed on the first step), and on a Mac it still does not.
+ #[test]
+ fn continue_advances_a_windows_image_on_a_windows_pc() {
+ let e = WizardEnv {
+ local_backends: Some(vec!["qemu".into()]),
+ ..env()
+ };
+ let s = reduce_on(
+ &initial(&e),
+ &WizardAction::ChooseImage {
+ image_ref: "ghcr.io/trycua/windows:2022".into(),
+ },
+ &e,
+ SpaceOs::Windows,
+ );
+ let s = reduce_on(
+ &s,
+ &WizardAction::ChoosePlacement { on: "local".into() },
+ &e,
+ SpaceOs::Windows,
+ );
+ assert!(view_on(&s, &e, SpaceOs::Windows).can_continue);
+ let next = |os| reduce_on(&s, &WizardAction::Next, &e, os).step;
+ assert_eq!(next(SpaceOs::Windows), 1);
+ assert_eq!(next(SpaceOs::Macos), 0);
+ }
+
/// A Windows VM runs on QEMU, which the app never installs: on a PC
/// without it (or before the doctor answered) the Windows image is not
/// offered here, so nothing downloads gigabytes only to fail.
diff --git a/libs/cua/crates/cua-vmm/src/storage.rs b/libs/cua/crates/cua-vmm/src/storage.rs
index 4a3c5b8534..2c410e9fc0 100644
--- a/libs/cua/crates/cua-vmm/src/storage.rs
+++ b/libs/cua/crates/cua-vmm/src/storage.rs
@@ -236,7 +236,28 @@ pub fn volume_name(path: &Path) -> String {
if p.as_os_str().is_empty() {
p = PathBuf::from("/");
}
- platform::volume_name(&p).unwrap_or_else(|| "this Mac".into())
+ platform::volume_name(&p).unwrap_or_else(|| fallback_volume_name(&p))
+}
+
+/// What to call a volume the platform cannot name: the drive on Windows
+/// (`C:`), else the machine, in the person's words ("this Mac" was shown on
+/// a Windows PC).
+fn fallback_volume_name(path: &Path) -> String {
+ if cfg!(windows) {
+ if let Some(std::path::Component::Prefix(prefix)) = path.components().next() {
+ let drive = prefix.as_os_str().to_string_lossy();
+ // `\?\C:` (extended) or `C:`: keep the drive letter.
+ if let Some(i) = drive.find(':') {
+ return drive[i - 1..=i].to_string();
+ }
+ }
+ return "this PC".into();
+ }
+ if cfg!(target_os = "macos") {
+ "this Mac".into()
+ } else {
+ "this computer".into()
+ }
}
#[cfg(target_os = "macos")]
@@ -340,6 +361,22 @@ mod platform {
mod tests {
use super::*;
+ #[test]
+ fn an_unnamed_volume_is_called_by_the_hosts_own_words() {
+ let name = fallback_volume_name(Path::new(if cfg!(windows) {
+ r"C:\Users\a"
+ } else {
+ "/home/a"
+ }));
+ if cfg!(windows) {
+ assert_eq!(name, "C:");
+ } else if cfg!(target_os = "macos") {
+ assert_eq!(name, "this Mac");
+ } else {
+ assert_eq!(name, "this computer");
+ }
+ }
+
#[test]
fn stable_keeps_lume_s_own_vm_directory_rules() {
let home = Path::new("/Users/a");