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): leave the machines that provide Spaces out of the menu bar count (#5050)

ddupont97b2394fc117
diff --git a/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/Models/AppModel.swift b/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/Models/AppModel.swift
index 469b37b839..49ff3857f5 100644
--- a/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/Models/AppModel.swift
+++ b/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/Models/AppModel.swift
@@ -1075,8 +1075,8 @@ public final class AppModel {
}
/// The menu bar item's status line.
- /// Counts the Spaces the user can open, the notch's count (This machine
- /// only while it is shared and reachable).
+ /// Counts the Spaces the user can open, the notch's count (never This
+ /// machine or another of your machines, even while they provide Spaces).
public var statusLine: String { appStatusLine(count: appOpenableCount(spaces: spaces)) }
/// The menu bar item's menu: the count, Cua Volume's sync state next to
diff --git a/apps/cua-spaces/src/App.test.tsx b/apps/cua-spaces/src/App.test.tsx
index 5d09850247..ed330aea9b 100644
--- a/apps/cua-spaces/src/App.test.tsx
+++ b/apps/cua-spaces/src/App.test.tsx
@@ -45,7 +45,7 @@ const tileNames = () =>
describe("ambient -> switcher", () => {
it("starts ambient with dots and count, expands on click and drives the native mode", async () => {
const { bridge, user } = renderApp();
- const ambient = screen.getByRole("button", { name: /4 Spaces, 2 active/ });
+ const ambient = screen.getByRole("button", { name: /3 Spaces, 2 active/ });
expect(ambient).toBeInTheDocument();
await waitFor(() => expect(bridge.modes).toContain("ambient"));
@@ -61,31 +61,31 @@ describe("ambient -> switcher", () => {
it("collapses with Escape", async () => {
const { user } = renderApp();
- await user.click(screen.getByRole("button", { name: /4 Spaces/ }));
+ await user.click(screen.getByRole("button", { name: /3 Spaces/ }));
await user.keyboard("{Escape}");
// Island (the default theme) springs the panel back into the notch before
// collapsing to the ambient tab, so the tab reappears asynchronously.
- expect(await screen.findByRole("button", { name: /4 Spaces/ })).toBeInTheDocument();
+ expect(await screen.findByRole("button", { name: /3 Spaces/ })).toBeInTheDocument();
});
});
describe("menu-bar presentation", () => {
it("shows the ambient 'N Spaces' tab in the default notch mode", () => {
renderApp();
- expect(screen.getByRole("button", { name: /4 Spaces, 2 active/ })).toBeInTheDocument();
+ expect(screen.getByRole("button", { name: /3 Spaces, 2 active/ })).toBeInTheDocument();
});
it("hides the ambient tab when menu-bar mode is stored (status item is the entry)", () => {
window.localStorage.setItem(SETTINGS_KEYS.menuBar, "true");
renderApp();
- expect(screen.queryByRole("button", { name: /4 Spaces, 2 active/ })).toBeNull();
+ expect(screen.queryByRole("button", { name: /3 Spaces, 2 active/ })).toBeNull();
});
});
describe("keyboard selection and MRU", () => {
it("moves focus with arrows, selects with Enter, reorders MRU, confirms, then collapses", async () => {
const { user } = renderApp();
- await user.click(screen.getByRole("button", { name: /4 Spaces/ }));
+ await user.click(screen.getByRole("button", { name: /3 Spaces/ }));
// The filter box is focused on open; arrow keys then drive tile navigation.
expect(screen.getByRole("searchbox")).toHaveFocus();
@@ -101,16 +101,16 @@ describe("keyboard selection and MRU", () => {
expect(tileNames()).toEqual(["Linux Build", "This Mac", "Windows QA", "Research"]);
expect(screen.getAllByRole("status")[0]).toHaveTextContent("Switching to Linux Build");
- await waitFor(() => expect(screen.getByRole("button", { name: /4 Spaces/ })).toBeInTheDocument());
+ await waitFor(() => expect(screen.getByRole("button", { name: /3 Spaces/ })).toBeInTheDocument());
// Re-open: MRU order persists.
- await user.click(screen.getByRole("button", { name: /4 Spaces/ }));
+ await user.click(screen.getByRole("button", { name: /3 Spaces/ }));
// The grid mounts as the notch opens: wait for it, as for the collapse.
await waitFor(() => expect(tileNames()[0]).toBe("Linux Build"));
});
it("wraps from the New tile back to the first Space and reaches New with End", async () => {
const { user } = renderApp();
- await user.click(screen.getByRole("button", { name: /4 Spaces/ }));
+ await user.click(screen.getByRole("button", { name: /3 Spaces/ }));
await user.keyboard("{End}");
expect(screen.getByRole("option", { name: /New Space/ })).toHaveFocus();
await user.keyboard("{ArrowRight}");
@@ -138,17 +138,17 @@ describe("New Space opens a window, never a notch panel", () => {
it("Cmd/Ctrl+N asks the shell for the New Space window and folds the notch away", async () => {
const { spacesList, user } = renderWithList();
- await user.click(screen.getByRole("button", { name: /4 Spaces/ }));
+ await user.click(screen.getByRole("button", { name: /3 Spaces/ }));
await user.keyboard("{Control>}n{/Control}");
expect(spacesList.openNewSpace).toHaveBeenCalledTimes(1);
expect(screen.queryByRole("heading", { name: "New Fleet" })).toBeNull();
expect(screen.queryByRole("dialog", { name: "New Space" })).toBeNull();
- expect(await screen.findByRole("button", { name: /4 Spaces/ })).toBeInTheDocument();
+ expect(await screen.findByRole("button", { name: /3 Spaces/ })).toBeInTheDocument();
});
it("the + New tile does the same", async () => {
const { spacesList, user } = renderWithList();
- await user.click(screen.getByRole("button", { name: /4 Spaces/ }));
+ await user.click(screen.getByRole("button", { name: /3 Spaces/ }));
await user.click(screen.getByRole("option", { name: /New Space/ }));
expect(spacesList.openNewSpace).toHaveBeenCalledTimes(1);
expect(screen.queryByRole("searchbox")).toBeNull();
diff --git a/apps/cua-spaces/src/components/Ambient.test.tsx b/apps/cua-spaces/src/components/Ambient.test.tsx
index 90fad0b878..c03c5467ac 100644
--- a/apps/cua-spaces/src/components/Ambient.test.tsx
+++ b/apps/cua-spaces/src/components/Ambient.test.tsx
@@ -42,9 +42,9 @@ describe("Ambient tab and activity (the core's notch module)", () => {
it("is two rows: the count over the word", () => {
const { container } = render(<Ambient spaces={FIXTURE_SPACES} displayStyle="notched" onExpand={vi.fn()} />);
// The Spaces the user can open (the core's count, the menu bar item's too):
- // the fixture's This Mac is shared and reachable, so it counts.
+ // the fixture's This Mac provides Spaces, but a machine is not a Space.
const n = openableCount(FIXTURE_SPACES);
- expect(n).toBe(remote.length + 1);
+ expect(n).toBe(remote.length);
expect(container.querySelector(".ambient-tab-count")).toHaveTextContent(String(n));
expect(container.querySelector(".ambient-tab-word")).toHaveTextContent(n === 1 ? "Space" : "Spaces");
});
diff --git a/libs/cua/crates/cua-spaces-app-core/parity/golden/menu-count.json b/libs/cua/crates/cua-spaces-app-core/parity/golden/menu-count.json
index 47e7c7ae9c..d7a2f4f569 100644
--- a/libs/cua/crates/cua-spaces-app-core/parity/golden/menu-count.json
+++ b/libs/cua/crates/cua-spaces-app-core/parity/golden/menu-count.json
@@ -17,15 +17,15 @@
{
"agree": true,
"case": "this machine hosting",
- "count": 1,
+ "count": 0,
"menu": [
- "status: 1 Space (disabled)",
+ "status: No Spaces (disabled)",
"open: Open Cua Spaces",
"new-space: New Space…",
"settings: Settings…",
"quit: Quit Cua Spaces"
],
- "notch": "1"
+ "notch": "0"
},
{
"agree": true,
@@ -69,15 +69,15 @@
{
"agree": true,
"case": "remote spaces and hosting",
- "count": 3,
+ "count": 2,
"menu": [
- "status: 3 Spaces (disabled)",
+ "status: 2 Spaces (disabled)",
"open: Open Cua Spaces",
"new-space: New Space…",
"settings: Settings…",
"quit: Quit Cua Spaces"
],
- "notch": "3"
+ "notch": "2"
},
{
"agree": true,
diff --git a/libs/cua/crates/cua-spaces-app-core/parity/golden/notch.json b/libs/cua/crates/cua-spaces-app-core/parity/golden/notch.json
index 94831fbf75..37425c953b 100644
--- a/libs/cua/crates/cua-spaces-app-core/parity/golden/notch.json
+++ b/libs/cua/crates/cua-spaces-app-core/parity/golden/notch.json
@@ -210,7 +210,7 @@
"phase": "closed",
"prompt": null,
"tab": [
- "5",
+ "4",
"Spaces"
],
"tiles": []
@@ -426,7 +426,7 @@
"phase": "closed",
"prompt": null,
"tab": [
- "5",
+ "4",
"Spaces"
],
"tiles": []
@@ -507,7 +507,7 @@
"phase": "closed",
"prompt": null,
"tab": [
- "5",
+ "4",
"Spaces"
],
"tiles": []
@@ -564,7 +564,7 @@
"phase": "closed",
"prompt": null,
"tab": [
- "5",
+ "4",
"Spaces"
],
"tiles": []
@@ -717,7 +717,7 @@
"phase": "closed",
"prompt": null,
"tab": [
- "5",
+ "4",
"Spaces"
],
"tiles": []
@@ -739,7 +739,7 @@
"phase": "closed",
"prompt": null,
"tab": [
- "5",
+ "4",
"Spaces"
],
"tiles": []
@@ -940,7 +940,7 @@
"phase": "closed",
"prompt": null,
"tab": [
- "5",
+ "4",
"Spaces"
],
"tiles": []
@@ -962,7 +962,7 @@
"phase": "closed",
"prompt": null,
"tab": [
- "5",
+ "4",
"Spaces"
],
"tiles": []
@@ -984,7 +984,7 @@
"phase": "closed",
"prompt": null,
"tab": [
- "5",
+ "4",
"Spaces"
],
"tiles": []
@@ -1006,7 +1006,7 @@
"phase": "closed",
"prompt": null,
"tab": [
- "5",
+ "4",
"Spaces"
],
"tiles": []
@@ -1028,7 +1028,7 @@
"phase": "closed",
"prompt": null,
"tab": [
- "5",
+ "4",
"Spaces"
],
"tiles": []
@@ -1109,7 +1109,7 @@
"phase": "closed",
"prompt": null,
"tab": [
- "5",
+ "4",
"Spaces"
],
"tiles": []
diff --git a/libs/cua/crates/cua-spaces-app-core/parity/golden/teleport-review.json b/libs/cua/crates/cua-spaces-app-core/parity/golden/teleport-review.json
index 8a8e013187..13a27128d1 100644
--- a/libs/cua/crates/cua-spaces-app-core/parity/golden/teleport-review.json
+++ b/libs/cua/crates/cua-spaces-app-core/parity/golden/teleport-review.json
@@ -570,7 +570,7 @@
"phase": "closed",
"prompt": null,
"tab": [
- "3",
+ "2",
"Spaces"
],
"tiles": []
@@ -653,7 +653,7 @@
"phase": "closed",
"prompt": null,
"tab": [
- "3",
+ "2",
"Spaces"
],
"tiles": []
@@ -761,7 +761,7 @@
"phase": "closed",
"prompt": null,
"tab": [
- "3",
+ "2",
"Spaces"
],
"tiles": []
diff --git a/libs/cua/crates/cua-spaces-app-core/parity/menu-count.json b/libs/cua/crates/cua-spaces-app-core/parity/menu-count.json
index 6426c62c8d..e84142d93d 100644
--- a/libs/cua/crates/cua-spaces-app-core/parity/menu-count.json
+++ b/libs/cua/crates/cua-spaces-app-core/parity/menu-count.json
@@ -1,6 +1,6 @@
{
"name": "menu-count",
- "about": "The menu bar item and the notch tab count the same Spaces (This machine only while it is shared and reachable; a provider's Spaces count), and the menu shows Cua Volume's sync state next to the count when sync applies: synced, syncing, conflicts (they open the Volume page) and offline; nothing on this Mac's store with one device; a bucket that has not answered for 30 s is offline.",
+ "about": "The menu bar item and the notch tab count the same Spaces (never This machine or another machine's own desktop, even while it provides Spaces; the Spaces a machine provides count), and the menu shows Cua Volume's sync state next to the count when sync applies: synced, syncing, conflicts (they open the Volume page) and offline; nothing on this Mac's store with one device; a bucket that has not answered for 30 s is offline.",
"now": 1800000000000,
"cases": [
{
@@ -203,6 +203,20 @@
"os": "linux",
"reachable": true,
"error": null
+ },
+ {
+ "id": "relay:space-ca12d6d23907f387",
+ "name": "space-ca12d6d23907f387",
+ "provider": "relay",
+ "host": "studio-linux",
+ "spacesdVersion": "0.4.0",
+ "features": [
+ "desktop_stream"
+ ],
+ "addedAt": "2026-09-25T08:00:00Z",
+ "os": "linux",
+ "reachable": true,
+ "error": null
}
],
"sync": null,
@@ -275,6 +289,20 @@
"os": "linux",
"reachable": true,
"error": null
+ },
+ {
+ "id": "relay:space-ca12d6d23907f387",
+ "name": "space-ca12d6d23907f387",
+ "provider": "relay",
+ "host": "studio-linux",
+ "spacesdVersion": "0.4.0",
+ "features": [
+ "desktop_stream"
+ ],
+ "addedAt": "2026-09-25T08:00:00Z",
+ "os": "linux",
+ "reachable": true,
+ "error": null
}
],
"sync": null,
diff --git a/libs/cua/crates/cua-spaces-app-core/src/spaces/mod.rs b/libs/cua/crates/cua-spaces-app-core/src/spaces/mod.rs
index 149c9762b7..30dd349b61 100644
--- a/libs/cua/crates/cua-spaces-app-core/src/spaces/mod.rs
+++ b/libs/cua/crates/cua-spaces-app-core/src/spaces/mod.rs
@@ -365,21 +365,32 @@ pub fn count_active(spaces: &[Space]) -> u32 {
.count() as u32
}
-/// The Spaces the user can open: every Space but "This machine", which
-/// counts only while it is shared as a Space and reachable (its status is
-/// `Local`). A Space a provider hosts on another machine counts. The notch
-/// tab and the menu bar item both show this number.
+/// A machine's own desktop, not a Space: This machine (`this-mac`, and any
+/// row reported as `Local`), or one of your machines sharing its own desktop
+/// over the relay (`relay:<machine>` with no host above it). They belong
+/// with the machines (the sidebar's This Mac and My machines, the web UI's
+/// Machines page), not in the count of Spaces; the web UI's
+/// `isMachineDesktop` is the same rule.
+pub fn is_machine_desktop(space: &Space) -> bool {
+ if space.id == crate::host::THIS_MACHINE_ID || space.status == SpaceStatus::Local {
+ return true;
+ }
+ if space.provider != Some(SpaceProvider::Relay) || space.host.is_some() {
+ return false;
+ }
+ space
+ .id
+ .strip_prefix("relay:")
+ .is_some_and(|own| !own.is_empty() && !own.contains('/') && !own.starts_with("space-"))
+}
+
+/// The Spaces the user can open: every Space but the machines' own
+/// desktops ([`is_machine_desktop`]): not This machine, even while it
+/// provides Spaces, and not one of your machines on the relay. A Space a
+/// machine provides counts. The notch tab and the menu bar item both show
+/// this number.
pub fn openable_count(spaces: &[Space]) -> u32 {
- spaces
- .iter()
- .filter(|s| {
- if s.id == crate::host::THIS_MACHINE_ID {
- s.status == SpaceStatus::Local
- } else {
- s.status != SpaceStatus::Local
- }
- })
- .count() as u32
+ spaces.iter().filter(|s| !is_machine_desktop(s)).count() as u32
}
/// The three ambient status dots.
@@ -612,4 +623,61 @@ mod tests {
let ids: Vec<_> = sorted.iter().map(|s| s.id.as_str()).collect();
assert_eq!(ids, ["space://cloud/cua-spaces-x/p", "b", "a"]);
}
+
+ /// The menu bar's count and the notch tab leave out the machines that
+ /// provide Spaces: This machine while it hosts, and one of your machines
+ /// sharing its own desktop over the relay (`relay:<machine>`, no host).
+ /// One real Space read "3 Spaces" before (This machine, the Space and
+ /// the other Mac); a Space a machine provides still counts.
+ #[test]
+ fn the_count_leaves_out_the_machines_that_provide_spaces() {
+ use crate::host::{HostSummaryInput, this_machine_space};
+ let hosting = HostSummaryInput {
+ configured: true,
+ service_running: true,
+ sharing: true,
+ ..Default::default()
+ };
+ let this_mac = this_machine_space(Some(&hosting), 0, SpaceOs::Macos);
+ assert_eq!(this_mac.status, SpaceStatus::Local);
+ let mut local = row();
+ local.id = "local:fbd1".into();
+ local.provider = "local".into();
+ let mut machine = row();
+ machine.id = "relay:96fedb7e1be65c3d31fa18587febde2c".into();
+ machine.name = "Studio".into();
+ machine.provider = "relay".into();
+ machine.reachable = false;
+ let mut provided = row();
+ provided.id = "relay:space-ca12d6d23907f387".into();
+ provided.provider = "relay".into();
+ provided.host = Some("96fedb7e1be65c3d31fa18587febde2c".into());
+ let mut named = row();
+ named.id = "relay:mac-mini/release-checks".into();
+ named.provider = "relay".into();
+ named.host = Some("mac-mini".into());
+
+ let rows = |rs: &[&SpaceRow]| {
+ let mut out = vec![this_mac.clone()];
+ out.extend(rs.iter().map(|r| row_to_space(r, 0)));
+ out
+ };
+ // This machine hosting, nothing else: no Spaces.
+ assert_eq!(openable_count(&rows(&[])), 0);
+ assert!(is_machine_desktop(&this_mac));
+ // One Space, This machine hosting, another Mac on the relay: 1.
+ let roster = rows(&[&local, &machine]);
+ assert!(is_machine_desktop(&roster[2]));
+ assert_eq!(openable_count(&roster), 1);
+ assert_eq!(crate::notch::tab(&roster).count, "1");
+ // The Spaces that other Mac provides count.
+ assert_eq!(
+ openable_count(&rows(&[&local, &machine, &provided, &named])),
+ 3
+ );
+ // This machine not hosting is not a Space either.
+ let idle = this_machine_space(None, 0, SpaceOs::Macos);
+ assert!(is_machine_desktop(&idle));
+ assert_eq!(openable_count(&[idle]), 0);
+ }
}
diff --git a/libs/cua/crates/cua-spaces-app-core/src/window.rs b/libs/cua/crates/cua-spaces-app-core/src/window.rs
index de9dea5907..9c9e1e6db3 100644
--- a/libs/cua/crates/cua-spaces-app-core/src/window.rs
+++ b/libs/cua/crates/cua-spaces-app-core/src/window.rs
@@ -375,10 +375,18 @@ mod tests {
fn the_menu_and_the_notch_count_the_same_spaces() {
use crate::host::{HostSummaryInput, this_machine_space};
use crate::model::{SpaceOs, SpaceStatus};
+ // A Space your machine "studio" provides (This machine and studio's
+ // own desktop are machines, not Spaces).
let mut remote = this_machine_space(None, 0, SpaceOs::Linux);
- remote.id = "relay:studio".into();
- remote.name = "Studio".into();
+ remote.id = "relay:studio/dev".into();
+ remote.name = "Dev".into();
remote.status = SpaceStatus::Running;
+ remote.provider = Some(crate::model::SpaceProvider::Relay);
+ remote.host = Some("studio".into());
+ let mut studio = remote.clone();
+ studio.id = "relay:studio".into();
+ studio.name = "Studio".into();
+ studio.host = None;
let hosting = HostSummaryInput {
configured: true,
service_running: true,
@@ -387,9 +395,10 @@ mod tests {
};
for (host, extra, want) in [
(None, vec![], 0),
- (Some(hosting.clone()), vec![], 1),
+ (Some(hosting.clone()), vec![], 0),
+ (None, vec![studio.clone()], 0),
(None, vec![remote.clone()], 1),
- (Some(hosting), vec![remote], 2),
+ (Some(hosting), vec![studio, remote], 1),
] {
let mut spaces = vec![this_machine_space(host.as_ref(), 0, SpaceOs::Macos)];
spaces.extend(extra);