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): show running Spaces first in the notch, never cut them for stopped ones (#6215)

dduponta68e2c986eb2
diff --git a/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/WebHost/SyntheticStreamProvider.swift b/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/WebHost/SyntheticStreamProvider.swift
index add9b2f33a..a59d810f83 100644
--- a/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/WebHost/SyntheticStreamProvider.swift
+++ b/apps/cua-spaces-macos/Sources/CuaSpacesMacKit/WebHost/SyntheticStreamProvider.swift
@@ -260,6 +260,22 @@ extension FixtureSpacesBackend {
kind: nil, arch: nil, reachable: true, error: nil, host: "m1", hostName: "ellieln",
power: nil, powerState: "running", cloud: nil, cloudPlace: nil, cloudDelete: nil, stopReason: nil, sharing: nil))
}
+ // `CUA_SPACES_FIXTURE_STOPPED=<n>`: `n` suspended or stopped Spaces that
+ // one of your machines provides, with no recorded add date (so they read
+ // as seen just now), the notch's ordering regression.
+ if let k = environment["CUA_SPACES_FIXTURE_STOPPED"].flatMap(Int.init), k > 0 {
+ let names = ["cua-builder", "onb-new", "onb-old", "windows-aws", "dev-box", "ci-runner", "scratch", "qa-mac"]
+ for i in 0..<min(k, names.count) {
+ let state = i % 2 == 0 ? "suspended" : "stopped"
+ base.append(AppSpaceRow(
+ id: "relay:ip-172-31-46-222/\(names[i])", name: names[i], displayName: nil, provider: "relay",
+ spacesdVersion: "0.7.0", features: ["desktop_stream"], addedAt: nil,
+ os: .unknown, osName: nil, osPrettyName: nil, image: nil, imageDigest: nil,
+ kind: nil, arch: nil, reachable: false, error: nil, host: "ip-172-31-46-222",
+ hostName: "ip-172-31-46-222", power: i % 2 == 0 ? "suspend" : "stop", powerState: state,
+ cloud: nil, cloudPlace: nil, cloudDelete: nil, stopReason: nil, sharing: nil))
+ }
+ }
guard let n = environment["CUA_SPACES_FIXTURE_SPACES"].flatMap(Int.init), n > 0,
let template = base.first else { return base }
let extra = (1...min(n, 32)).map { i -> AppSpaceRow in
diff --git a/libs/cua/crates/cua-spaces-app-core/parity/golden/create-retry.json b/libs/cua/crates/cua-spaces-app-core/parity/golden/create-retry.json
index 28c2b23b59..76654cd0d7 100644
--- a/libs/cua/crates/cua-spaces-app-core/parity/golden/create-retry.json
+++ b/libs/cua/crates/cua-spaces-app-core/parity/golden/create-retry.json
@@ -686,8 +686,8 @@
"os-macos Mac [spaces.status.starting] 1000 100%"
],
"tiles": [
- "os-macos Mac, macOS, This Mac, Failed - Failed",
- "os-macos Mac, macOS, This Mac, Starting 1000 Ready"
+ "os-macos Mac, macOS, This Mac, Starting 1000 Ready",
+ "os-macos Mac, macOS, This Mac, Failed - Failed"
]
}
},
@@ -751,8 +751,8 @@
"os-macos Mac [spaces.status.starting] 1000 100%"
],
"tiles": [
- "os-macos Mac, macOS, This Mac, Failed - Failed",
- "os-macos Mac, macOS, This Mac, Starting 1000 Ready"
+ "os-macos Mac, macOS, This Mac, Starting 1000 Ready",
+ "os-macos Mac, macOS, This Mac, Failed - Failed"
]
}
}
diff --git a/libs/cua/crates/cua-spaces-app-core/parity/golden/delete-space.json b/libs/cua/crates/cua-spaces-app-core/parity/golden/delete-space.json
index 54f40c74ea..0ee8c54063 100644
--- a/libs/cua/crates/cua-spaces-app-core/parity/golden/delete-space.json
+++ b/libs/cua/crates/cua-spaces-app-core/parity/golden/delete-space.json
@@ -62,8 +62,8 @@
"os-linux keep [spaces.status.running] - -"
],
"tiles": [
- "os-linux demo, Linux, This Mac, Deleting… - Deleting…",
- "os-linux keep, Linux, This Mac, Running - -"
+ "os-linux keep, Linux, This Mac, Running - -",
+ "os-linux demo, Linux, This Mac, Deleting… - Deleting…"
]
},
"isDeleting": true,
@@ -130,8 +130,8 @@
"os-linux keep [spaces.status.running] - -"
],
"tiles": [
- "os-linux demo, Linux, This Mac, Deleting… - Deleting…",
- "os-linux keep, Linux, This Mac, Running - -"
+ "os-linux keep, Linux, This Mac, Running - -",
+ "os-linux demo, Linux, This Mac, Deleting… - Deleting…"
]
},
"isDeleting": null,
@@ -198,8 +198,8 @@
"os-linux keep [spaces.status.running] - -"
],
"tiles": [
- "os-linux demo, Linux, This Mac, Deleting… - Deleting…",
- "os-linux keep, Linux, This Mac, Running - -"
+ "os-linux keep, Linux, This Mac, Running - -",
+ "os-linux demo, Linux, This Mac, Deleting… - Deleting…"
]
},
"isDeleting": null,
@@ -266,8 +266,8 @@
"os-linux keep [spaces.status.running] - -"
],
"tiles": [
- "os-linux demo, Linux, This Mac, Deleting… - Deleting…",
- "os-linux keep, Linux, This Mac, Running - -"
+ "os-linux keep, Linux, This Mac, Running - -",
+ "os-linux demo, Linux, This Mac, Deleting… - Deleting…"
]
},
"isDeleting": 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 d7e89d3c88..6e24918511 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
@@ -242,8 +242,8 @@
"tiles": [
"Aurora [os-ubuntu]",
"Lab PC [os-windows]",
- "Builder [os-macos] (no drop)",
- "Starter [os-linux] (no drop)"
+ "Starter [os-linux] (no drop)",
+ "Builder [os-macos] (no drop)"
]
},
"notch": "dwell-elapsed"
@@ -273,8 +273,8 @@
"tiles": [
"Aurora [os-ubuntu]",
"Lab PC [os-windows]",
- "Builder [os-macos] (no drop)",
- "Starter [os-linux] (no drop)"
+ "Starter [os-linux] (no drop)",
+ "Builder [os-macos] (no drop)"
]
},
"notch": "drag-permission false"
@@ -307,8 +307,8 @@
"tiles": [
"Aurora [os-ubuntu]",
"Lab PC [os-windows]",
- "Builder [os-macos] (no drop)",
- "Starter [os-linux] (no drop)"
+ "Starter [os-linux] (no drop)",
+ "Builder [os-macos] (no drop)"
]
},
"notch": "hover-exit"
@@ -340,8 +340,8 @@
"tiles": [
"Aurora [os-ubuntu]",
"Lab PC [os-windows]",
- "Builder [os-macos] (no drop)",
- "Starter [os-linux] (no drop)"
+ "Starter [os-linux] (no drop)",
+ "Builder [os-macos] (no drop)"
]
},
"notch": "hover-enter"
@@ -371,8 +371,8 @@
"tiles": [
"Aurora [os-ubuntu]",
"Lab PC [os-windows]",
- "Builder [os-macos] (no drop)",
- "Starter [os-linux] (no drop)"
+ "Starter [os-linux] (no drop)",
+ "Builder [os-macos] (no drop)"
]
},
"notch": "close-elapsed"
@@ -405,8 +405,8 @@
"tiles": [
"Aurora [os-ubuntu]",
"Lab PC [os-windows]",
- "Builder [os-macos] (no drop)",
- "Starter [os-linux] (no drop)"
+ "Starter [os-linux] (no drop)",
+ "Builder [os-macos] (no drop)"
]
},
"notch": "hover-exit"
@@ -453,8 +453,8 @@
"tiles": [
"Aurora [os-ubuntu]",
"Lab PC [os-windows]",
- "Builder [os-macos] (no drop)",
- "Starter [os-linux] (no drop)"
+ "Starter [os-linux] (no drop)",
+ "Builder [os-macos] (no drop)"
]
},
"notch": "drop-targeted true"
@@ -486,8 +486,8 @@
"tiles": [
"Aurora [os-ubuntu]",
"Lab PC [os-windows]",
- "Builder [os-macos] (no drop)",
- "Starter [os-linux] (no drop)"
+ "Starter [os-linux] (no drop)",
+ "Builder [os-macos] (no drop)"
]
},
"notch": "drop-targeted false"
@@ -541,8 +541,8 @@
"tiles": [
"Aurora [os-ubuntu]",
"Lab PC [os-windows]",
- "Builder [os-macos] (no drop)",
- "Starter [os-linux] (no drop)"
+ "Starter [os-linux] (no drop)",
+ "Builder [os-macos] (no drop)"
]
},
"notch": "click"
@@ -629,8 +629,8 @@
"tiles": [
"Aurora [os-ubuntu]",
"Lab PC [os-windows]",
- "Builder [os-macos] (no drop)",
- "Starter [os-linux] (no drop)"
+ "Starter [os-linux] (no drop)",
+ "Builder [os-macos] (no drop)"
]
},
"notch": "drag enter-notch"
@@ -653,8 +653,8 @@
"tiles": [
"Aurora [os-ubuntu]",
"Lab PC [os-windows] (targeted)",
- "Builder [os-macos] (no drop)",
- "Starter [os-linux] (no drop)"
+ "Starter [os-linux] (no drop)",
+ "Builder [os-macos] (no drop)"
]
},
"notch": "drag over"
@@ -677,8 +677,8 @@
"tiles": [
"Aurora [os-ubuntu]",
"Lab PC [os-windows]",
- "Builder [os-macos] (no drop)",
- "Starter [os-linux] (no drop)"
+ "Starter [os-linux] (no drop)",
+ "Builder [os-macos] (no drop)"
]
},
"notch": "drag out"
@@ -773,8 +773,8 @@
"tiles": [
"Aurora [os-ubuntu]",
"Lab PC [os-windows]",
- "Builder [os-macos] (no drop)",
- "Starter [os-linux] (no drop)"
+ "Starter [os-linux] (no drop)",
+ "Builder [os-macos] (no drop)"
]
},
"notch": "click"
@@ -858,8 +858,8 @@
"tiles": [
"Aurora [os-ubuntu]",
"Lab PC [os-windows]",
- "Builder [os-macos] (no drop)",
- "Starter [os-linux] (no drop)"
+ "Starter [os-linux] (no drop)",
+ "Builder [os-macos] (no drop)"
]
},
"notch": "escape"
@@ -917,8 +917,8 @@
"tiles": [
"Aurora [os-ubuntu]",
"Lab PC [os-windows]",
- "Builder [os-macos] (no drop)",
- "Starter [os-linux] (no drop)"
+ "Starter [os-linux] (no drop)",
+ "Builder [os-macos] (no drop)"
]
},
"notch": "escape"
diff --git a/libs/cua/crates/cua-spaces-app-core/parity/golden/provisioning.json b/libs/cua/crates/cua-spaces-app-core/parity/golden/provisioning.json
index 40d1852a46..0ca2a64fa1 100644
--- a/libs/cua/crates/cua-spaces-app-core/parity/golden/provisioning.json
+++ b/libs/cua/crates/cua-spaces-app-core/parity/golden/provisioning.json
@@ -558,9 +558,9 @@
"os-linux demo [spaces.status.running] - -"
],
"tiles": [
- "os-macos Mac, macOS, This Mac, Failed - Failed",
"os-linux New Space, Linux, This Mac, Starting 805 Booting…",
- "os-linux demo, Linux, This Mac, Running - -"
+ "os-linux demo, Linux, This Mac, Running - -",
+ "os-macos Mac, macOS, This Mac, Failed - Failed"
]
}
},
@@ -642,9 +642,9 @@
"os-linux demo [spaces.status.running] - -"
],
"tiles": [
- "os-macos Mac, macOS, This Mac, Failed - Failed",
"os-linux New Space, Linux, This Mac, Starting 985 Connecting…",
- "os-linux demo, Linux, This Mac, Running - -"
+ "os-linux demo, Linux, This Mac, Running - -",
+ "os-macos Mac, macOS, This Mac, Failed - Failed"
]
}
},
@@ -726,9 +726,9 @@
"os-linux demo [spaces.status.running] - -"
],
"tiles": [
- "os-macos Mac, macOS, This Mac, Failed - Failed",
"os-linux New Space, Linux, This Mac, Starting 1000 Ready",
- "os-linux demo, Linux, This Mac, Running - -"
+ "os-linux demo, Linux, This Mac, Running - -",
+ "os-macos Mac, macOS, This Mac, Failed - Failed"
]
}
},
@@ -954,9 +954,9 @@
"os-linux Omarchy [spaces.status.failed] - The Cua daemon isn't running. Start Cua, or run `cua daemon start`."
],
"tiles": [
- "os-linux Omarchy, Linux, pending:3, Failed - Failed",
"os-linux New Space, Linux, This Mac, Starting 1000 Ready",
- "os-linux demo, Linux, This Mac, Running - -"
+ "os-linux demo, Linux, This Mac, Running - -",
+ "os-linux Omarchy, Linux, pending:3, Failed - Failed"
]
}
},
diff --git a/libs/cua/crates/cua-spaces-app-core/parity/golden/space-power.json b/libs/cua/crates/cua-spaces-app-core/parity/golden/space-power.json
index 135d847512..9db1d223ef 100644
--- a/libs/cua/crates/cua-spaces-app-core/parity/golden/space-power.json
+++ b/libs/cua/crates/cua-spaces-app-core/parity/golden/space-power.json
@@ -678,10 +678,10 @@
"os-linux studio [spaces.status.running] - - <power spaces.power.turn_off>"
],
"tiles": [
- "os-linux box, Linux, This Mac, Stopped - -",
"os-macos mac, macOS, This Mac, Running - -",
"os-linux studio, Linux, Mac mini, Running - -",
- "os-linux pool-c, Linux, pool-c, Running - -"
+ "os-linux pool-c, Linux, pool-c, Running - -",
+ "os-linux box, Linux, This Mac, Stopped - -"
]
},
"powering": [],
@@ -907,10 +907,10 @@
"os-linux studio [spaces.status.running] - - <power spaces.power.turn_off>"
],
"tiles": [
- "os-linux box, Linux, This Mac, Stopped - -",
"os-macos mac, macOS, This Mac, Running - -",
"os-linux studio, Linux, Mac mini, Running - -",
- "os-linux pool-c, Linux, pool-c, Running - -"
+ "os-linux pool-c, Linux, pool-c, Running - -",
+ "os-linux box, Linux, This Mac, Stopped - -"
]
},
"powering": [
@@ -1023,10 +1023,10 @@
"os-linux studio [spaces.status.running] - - <power spaces.power.turn_off>"
],
"tiles": [
- "os-linux box, Linux, This Mac, Stopped - -",
"os-macos mac, macOS, This Mac, Turning off… - -",
"os-linux studio, Linux, Mac mini, Running - -",
- "os-linux pool-c, Linux, pool-c, Running - -"
+ "os-linux pool-c, Linux, pool-c, Running - -",
+ "os-linux box, Linux, This Mac, Stopped - -"
]
},
"powering": [
@@ -1140,10 +1140,10 @@
"os-linux studio [spaces.status.running] - - <power spaces.power.turn_off>"
],
"tiles": [
- "os-linux box, Linux, This Mac, Stopped - -",
"os-macos mac, macOS, This Mac, Turning off… - -",
"os-linux studio, Linux, Mac mini, Running - -",
- "os-linux pool-c, Linux, pool-c, Running - -"
+ "os-linux pool-c, Linux, pool-c, Running - -",
+ "os-linux box, Linux, This Mac, Stopped - -"
]
},
"powering": [
@@ -1257,10 +1257,10 @@
"os-linux studio [spaces.status.running] - - <power spaces.power.turn_off>"
],
"tiles": [
- "os-linux box, Linux, This Mac, Stopped - -",
- "os-macos mac, macOS, This Mac, Stopped - -",
"os-linux studio, Linux, Mac mini, Running - -",
- "os-linux pool-c, Linux, pool-c, Running - -"
+ "os-linux pool-c, Linux, pool-c, Running - -",
+ "os-linux box, Linux, This Mac, Stopped - -",
+ "os-macos mac, macOS, This Mac, Stopped - -"
]
},
"powering": [
@@ -1373,10 +1373,10 @@
"os-linux studio [spaces.status.turning_off] - - <power spaces.status.turning_off busy>"
],
"tiles": [
- "os-linux box, Linux, This Mac, Stopped - -",
- "os-macos mac, macOS, This Mac, Stopped - -",
"os-linux studio, Linux, Mac mini, Turning off… - -",
- "os-linux pool-c, Linux, pool-c, Running - -"
+ "os-linux pool-c, Linux, pool-c, Running - -",
+ "os-linux box, Linux, This Mac, Stopped - -",
+ "os-macos mac, macOS, This Mac, Stopped - -"
]
},
"powering": [
@@ -1490,10 +1490,10 @@
"os-linux studio [spaces.status.turning_off] - - <power spaces.status.turning_off busy>"
],
"tiles": [
- "os-linux box, Linux, This Mac, Stopped - -",
- "os-macos mac, macOS, This Mac, Stopped - -",
"os-linux studio, Linux, Mac mini, Turning off… - -",
- "os-linux pool-c, Linux, pool-c, Running - -"
+ "os-linux pool-c, Linux, pool-c, Running - -",
+ "os-linux box, Linux, This Mac, Stopped - -",
+ "os-macos mac, macOS, This Mac, Stopped - -"
]
},
"powering": [
@@ -1607,10 +1607,10 @@
"os-linux studio [spaces.status.stopped] - - <power spaces.power.turn_on on>"
],
"tiles": [
+ "os-linux pool-c, Linux, pool-c, Running - -",
"os-linux box, Linux, This Mac, Stopped - -",
"os-macos mac, macOS, This Mac, Stopped - -",
- "os-linux studio, Linux, Mac mini, Stopped - -",
- "os-linux pool-c, Linux, pool-c, Running - -"
+ "os-linux studio, Linux, Mac mini, Stopped - -"
]
},
"powering": [
@@ -1723,10 +1723,10 @@
"os-linux studio [spaces.status.stopped] - - <power spaces.power.turn_on on>"
],
"tiles": [
- "os-linux box, Linux, This Mac, Stopped - -",
"os-macos mac, macOS, This Mac, Turning on… - -",
- "os-linux studio, Linux, Mac mini, Stopped - -",
- "os-linux pool-c, Linux, pool-c, Running - -"
+ "os-linux pool-c, Linux, pool-c, Running - -",
+ "os-linux box, Linux, This Mac, Stopped - -",
+ "os-linux studio, Linux, Mac mini, Stopped - -"
]
},
"powering": [
@@ -1839,10 +1839,10 @@
"os-linux studio [spaces.status.stopped] - - <power spaces.power.turn_on on>"
],
"tiles": [
+ "os-linux pool-c, Linux, pool-c, Running - -",
"os-linux box, Linux, This Mac, Stopped - -",
"os-macos mac, macOS, This Mac, Deleting… - Deleting…",
- "os-linux studio, Linux, Mac mini, Stopped - -",
- "os-linux pool-c, Linux, pool-c, Running - -"
+ "os-linux studio, Linux, Mac mini, Stopped - -"
]
},
"powering": [
@@ -1933,9 +1933,9 @@
"os-linux studio [spaces.status.stopped] - - <power spaces.power.turn_on on>"
],
"tiles": [
+ "os-linux pool-c, Linux, pool-c, Running - -",
"os-linux box, Linux, This Mac, Stopped - -",
- "os-linux studio, Linux, Mac mini, Stopped - -",
- "os-linux pool-c, Linux, pool-c, Running - -"
+ "os-linux studio, Linux, Mac mini, Stopped - -"
]
},
"powering": [
diff --git a/libs/cua/crates/cua-spaces-app-core/src/notch/mod.rs b/libs/cua/crates/cua-spaces-app-core/src/notch/mod.rs
index e6b94c693b..e49d54e74d 100644
--- a/libs/cua/crates/cua-spaces-app-core/src/notch/mod.rs
+++ b/libs/cua/crates/cua-spaces-app-core/src/notch/mod.rs
@@ -505,8 +505,9 @@ pub fn filter(spaces: &[Space], query: &str) -> Vec<Space> {
/// The Space tiles: the Spaces the user can open
/// ([`crate::spaces::openable_spaces`]: Spaces, and the desktops of your
/// other machines that are there to open; never This machine or a machine
-/// that only provides Spaces), in MRU order, at most [`MAX_TILES`]. Stopped
-/// Spaces are tiles too (dimmed, and they take drops), but the tab counts
+/// that only provides Spaces): the ones that are on first, in MRU order.
+/// Stopped Spaces are tiles too, after them (dimmed, and they take drops;
+/// at most [`MAX_TILES`] tiles unless more are on), but the tab counts
/// only the ones that are on.
pub fn tiles(spaces: &[Space], targeted: Option<&str>) -> Vec<NotchTile> {
tiles_matching(spaces, targeted, "")
@@ -544,12 +545,39 @@ pub fn tiles_pinned(
.cloned()
.collect();
let mut sorted = sort_by_mru(&listed);
- // Pinned first, in pin order; the rest keep their MRU order.
- sorted.sort_by_key(|s| pinned.iter().position(|p| *p == s.id).unwrap_or(usize::MAX));
+ // Pinned first, in pin order; then the Spaces that are on, then the
+ // desktops of other machines that are on, then the stopped and
+ // suspended ones. Each group keeps its MRU order. Without the
+ // grouping, a row that was added or seen later than your running
+ // Spaces sorted ahead of them and, with the cap, pushed them out.
+ sorted.sort_by_key(|s| {
+ let desktop = is_remote_desktop(s);
+ let on = crate::spaces::is_on(s)
+ || (desktop && desktop_availability(s) == DesktopAvailability::Available);
+ let group = match (on, desktop) {
+ (true, false) => 0u8,
+ (true, true) => 1,
+ (false, _) => 2,
+ };
+ (
+ pinned.iter().position(|p| *p == s.id).unwrap_or(usize::MAX),
+ group,
+ )
+ });
+ // The cap trims only stopped and suspended tiles: a Space that is on
+ // or pinned always gets its tile (the strip scrolls).
+ let mut kept = 0usize;
sorted
.into_iter()
.filter(|s| matches(s, query))
- .take(MAX_TILES)
+ .filter(|s| {
+ kept += 1;
+ kept <= MAX_TILES
+ || crate::spaces::is_on(s)
+ || (is_remote_desktop(s)
+ && desktop_availability(s) == DesktopAvailability::Available)
+ || pinned.contains(&s.id)
+ })
.map(|s| {
let desktop = is_remote_desktop(&s);
let note = if desktop {
@@ -2421,14 +2449,14 @@ mod tests {
// The search still narrows the pinned ones.
let pinned: Vec<String> = vec!["relay:wsl".into()];
assert!(tiles_pinned(&spaces, None, "nothing like it", &pinned).is_empty());
- // Pinned tiles survive the cap: the seventh Space is the one cut.
+ // Pinned tiles survive the cap: the seventh stopped Space is the one cut.
let many: Vec<Space> = (0..MAX_TILES + 2)
.map(|i| {
let mut s = space(
&format!("local:{i}"),
&format!("S{i}"),
SpaceOs::Linux,
- SpaceStatus::Running,
+ SpaceStatus::Suspended,
);
s.last_used_at = 100 - i as i64;
s
@@ -2440,6 +2468,59 @@ mod tests {
assert_eq!(t[0].id, last);
}
+ /// The owner's report: four running Spaces on This Mac were missing from
+ /// the notch while suspended and stopped rows filled it. Rows that were
+ /// seen later sorted first by last use, and the cap cut the running ones.
+ #[test]
+ fn running_spaces_come_before_stopped_ones_and_are_never_cut() {
+ let mut spaces: Vec<Space> = (0..4)
+ .map(|i| {
+ let mut s = space(
+ &format!("local:run{i}"),
+ &format!("run{i}"),
+ SpaceOs::Linux,
+ SpaceStatus::Running,
+ );
+ s.last_used_at = 10 + i as i64;
+ s
+ })
+ .collect();
+ for i in 0..8 {
+ let mut s = space(
+ &format!("local:off{i}"),
+ &format!("off{i}"),
+ SpaceOs::Linux,
+ SpaceStatus::Suspended,
+ );
+ s.last_used_at = 1_000 + i as i64;
+ spaces.push(s);
+ }
+ let t = tiles_pinned(&spaces, None, "", &[]);
+ let ids: Vec<&str> = t.iter().map(|t| t.id.as_str()).collect();
+ // Every running Space is there, first.
+ for i in 0..4 {
+ assert!(
+ ids[..4].contains(&format!("local:run{i}").as_str()),
+ "{ids:?}"
+ );
+ }
+ // The stopped ones follow, capped.
+ assert_eq!(t.len(), MAX_TILES);
+ assert!(t[4..].iter().all(|t| t.dim));
+ // More running Spaces than the cap: all of them still get a tile.
+ let running: Vec<Space> = (0..MAX_TILES + 3)
+ .map(|i| {
+ space(
+ &format!("local:r{i}"),
+ &format!("R{i}"),
+ SpaceOs::Linux,
+ SpaceStatus::Running,
+ )
+ })
+ .collect();
+ assert_eq!(tiles_pinned(&running, None, "", &[]).len(), MAX_TILES + 3);
+ }
+
/// A pinned desktop that is off or no longer shared stays, dimmed, and
/// says why; it takes no drop. Unpinned, it is gone again.
#[test]