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(cua-sdk): name the cua-spacesd release to update to when a Space's is too old (#4508)

ddupont2bce4442c107
diff --git a/libs/cua/crates/cua-spaces/src/host_spaces.rs b/libs/cua/crates/cua-spaces/src/host_spaces.rs
index dd3c795a48..2366ed8543 100644
--- a/libs/cua/crates/cua-spaces/src/host_spaces.rs
+++ b/libs/cua/crates/cua-spaces/src/host_spaces.rs
@@ -200,6 +200,32 @@ fn resolve_image(image: &str) -> (String, String) {
(word.to_string(), os.into())
}
+/// Why the host `name` (its own Space `s`) does not take host Space
+/// calls: Spaces are off on it, or its cua-spacesd predates them (it does
+/// not report `host_spaces` at all).
+fn not_providing(s: &crate::Space, name: &str) -> Error {
+ if s.feature(HOST_SPACES_FEATURE).is_none() {
+ let version = s.capabilities().version.trim();
+ return Error::host(
+ "host spaces",
+ format!(
+ "{name} runs cua-spacesd {}, which is too old to provide Spaces (it does not \
+ report `{HOST_SPACES_FEATURE}`). On {name}, update cua and run `cua host setup` \
+ again: it installs a current cua-spacesd",
+ if version.is_empty() {
+ "of an unknown version"
+ } else {
+ version
+ }
+ ),
+ );
+ }
+ Error::host(
+ "host spaces",
+ format!("{name} does not provide Spaces (on it: `cua host config --provide-spaces on`)"),
+ )
+}
+
fn to_pb(s: &ProvidedSpace) -> pb::HostSpace {
pb::HostSpace {
relay_machine: s.relay_machine.clone(),
@@ -1803,15 +1829,8 @@ impl Spaces {
// settings: check once more.
self.forget_connection(&id).await?;
let s = self.space(&id).await?;
- s.require(HOST_SPACES_FEATURE).map_err(|_| {
- Error::host(
- "host spaces",
- format!(
- "{} does not provide Spaces (on it: `cua host config --provide-spaces on`)",
- if m.name.is_empty() { &m.id } else { &m.name }
- ),
- )
- })?;
+ s.require(HOST_SPACES_FEATURE)
+ .map_err(|_| not_providing(&s, if m.name.is_empty() { &m.id } else { &m.name }))?;
return Ok(s);
}
Ok(s)
@@ -1833,15 +1852,8 @@ impl Spaces {
// settings: check once more.
self.forget_connection(&host.space).await?;
let s = self.space(&host.space).await?;
- s.require(HOST_SPACES_FEATURE).map_err(|_| {
- Error::host(
- "host spaces",
- format!(
- "{} does not provide Spaces (on it: `cua host config --provide-spaces on`)",
- host.name
- ),
- )
- })?;
+ s.require(HOST_SPACES_FEATURE)
+ .map_err(|_| not_providing(&s, &host.name))?;
Ok(s)
}
diff --git a/libs/cua/crates/cua-spaces/src/space.rs b/libs/cua/crates/cua-spaces/src/space.rs
index e714348ec9..71525d0c6e 100644
--- a/libs/cua/crates/cua-spaces/src/space.rs
+++ b/libs/cua/crates/cua-spaces/src/space.rs
@@ -13,6 +13,56 @@ use std::sync::Arc;
/// without cua-spacesd reports it missing.
pub const SPACESD_FEATURE: &str = "spacesd";
+/// The cua-spacesd release to ask for when a driver does not report a
+/// feature the client requires: every published release from this one on
+/// reports it. (Some older builds report it too; one that does not report
+/// it at all predates it.) `None` for a feature without a known floor.
+pub fn spacesd_floor(feature: &str) -> Option<&'static str> {
+ match feature {
+ // `SystemService.AttachRelay`: sharing a Space, `relay_register`,
+ // and every Space a host provides.
+ "relay_attach" => Some("0.2.2"),
+ _ => None,
+ }
+}
+
+/// Whether the cua-spacesd version `version` is older than `floor`
+/// (`x.y.z`, a pre-release suffix ignored). An empty or unparseable
+/// version counts as older: a driver that does not say is not newer.
+pub fn spacesd_older_than(version: &str, floor: &str) -> bool {
+ fn parse(v: &str) -> Option<(u64, u64, u64)> {
+ let v = v.trim().trim_start_matches('v');
+ let core = v.split(['-', '+']).next()?;
+ let mut it = core.split('.').map(|p| p.parse::<u64>().ok());
+ let t = (it.next()??, it.next()??, it.next()??);
+ it.next().is_none().then_some(t)
+ }
+ match (parse(version), parse(floor)) {
+ (Some(v), Some(f)) => v < f,
+ (None, Some(_)) => true,
+ _ => false,
+ }
+}
+
+/// The limitation text for a feature a cua-spacesd of `version` does not
+/// report at all: names the release to update to when the feature has a
+/// floor this version is older than.
+pub fn unreported_feature_limitation(version: &str, feature: &str) -> String {
+ let shown = if version.trim().is_empty() {
+ "of an unknown version"
+ } else {
+ version
+ };
+ match spacesd_floor(feature) {
+ Some(floor) if spacesd_older_than(version, floor) => format!(
+ "its cua-spacesd {shown} is too old: cua-spacesd {floor} and newer report \
+ `{feature}`; update the Space's image (or its cua-spacesd) to one that ships \
+ cua-spacesd {floor} or newer"
+ ),
+ _ => format!("cua-spacesd {shown} does not report this feature"),
+ }
+}
+
/// How a declared service is reached.
#[derive(Clone)]
pub enum ServiceSource {
@@ -361,10 +411,7 @@ impl Space {
None => Err(Error::CapabilityMissing {
space: self.inner.id.to_string(),
feature: name.into(),
- limitation: format!(
- "cua-spacesd {} does not report this feature",
- self.inner.caps.version
- ),
+ limitation: unreported_feature_limitation(&self.inner.caps.version, name),
}),
}
}
@@ -587,6 +634,39 @@ fn humantime_rfc3339(at: std::time::SystemTime) -> String {
#[cfg(test)]
mod tests {
+ use super::*;
+
+ #[test]
+ fn versions_compare_against_a_floor() {
+ assert!(spacesd_older_than("0.1.0", "0.2.2"));
+ assert!(spacesd_older_than("0.2.1", "0.2.2"));
+ assert!(spacesd_older_than("0.0.0-mock", "0.2.2"));
+ assert!(spacesd_older_than("", "0.2.2"));
+ assert!(spacesd_older_than("garbage", "0.2.2"));
+ assert!(!spacesd_older_than("0.2.2", "0.2.2"));
+ assert!(!spacesd_older_than("v0.3.0", "0.2.2"));
+ assert!(!spacesd_older_than("1.0.0-rc.1", "0.2.2"));
+ assert!(!spacesd_older_than("0.1.0", "not-a-version"));
+ }
+
+ #[test]
+ fn an_unreported_feature_names_the_release_to_update_to() {
+ assert_eq!(spacesd_floor("relay_attach"), Some("0.2.2"));
+ let old = unreported_feature_limitation("0.1.0", "relay_attach");
+ assert!(old.contains("cua-spacesd 0.1.0 is too old"), "{old}");
+ assert!(old.contains("cua-spacesd 0.2.2 or newer"), "{old}");
+ // A current driver that still lacks it, or a feature without a
+ // floor, keeps the plain text.
+ assert_eq!(
+ unreported_feature_limitation("0.3.0", "relay_attach"),
+ "cua-spacesd 0.3.0 does not report this feature"
+ );
+ assert_eq!(
+ unreported_feature_limitation("0.1.0", "pty"),
+ "cua-spacesd 0.1.0 does not report this feature"
+ );
+ }
+
#[test]
fn rfc3339_formats_known_instants() {
let at = std::time::UNIX_EPOCH + std::time::Duration::from_secs(1_758_300_000);
diff --git a/libs/cua/crates/cua-spaces/tests/host_spaces.rs b/libs/cua/crates/cua-spaces/tests/host_spaces.rs
index 907b253348..fb6a8b6498 100644
--- a/libs/cua/crates/cua-spaces/tests/host_spaces.rs
+++ b/libs/cua/crates/cua-spaces/tests/host_spaces.rs
@@ -375,12 +375,16 @@ async fn the_host_creates_attaches_lists_and_deletes_with_an_audit() {
async fn an_image_too_old_for_the_relay_says_so_and_is_removed() {
let f = fixture(HostProfile::Spare).await;
f.env.state.unadvertise(&["relay_attach"]);
+ f.env.state.set_version("0.1.0");
let attach = f.register("ada-token", "space-ada00001").await;
let e = f
.create(&ada(), "linux", attach)
.await
.unwrap_err()
.to_string();
+ // It names the version it found and the release to update to (#4480).
+ assert!(e.contains("cua-spacesd 0.1.0 is too old"), "{e}");
+ assert!(e.contains("cua-spacesd 0.2.2 or newer"), "{e}");
assert!(
e.contains("too old to be reached from your other devices"),
"{e}"
diff --git a/libs/cua/crates/cua-spaces/tests/share.rs b/libs/cua/crates/cua-spaces/tests/share.rs
index 45903f70eb..86075ce680 100644
--- a/libs/cua/crates/cua-spaces/tests/share.rs
+++ b/libs/cua/crates/cua-spaces/tests/share.rs
@@ -60,6 +60,9 @@ async fn sharing_a_space_attaches_it_and_moves_people_between_roles() {
.await
.unwrap_err();
assert_eq!(e.tag(), "capability_missing", "{e}");
+ // The mock driver's version predates the feature: the error names the
+ // release to update to.
+ assert!(e.to_string().contains("cua-spacesd 0.2.2 or newer"), "{e}");
assert!(env.state.relay_attached.lock().unwrap().is_none());
env.state.advertise(&["relay_attach"]);
diff --git a/libs/cua/crates/cua-spacesd-client/src/testing.rs b/libs/cua/crates/cua-spacesd-client/src/testing.rs
index 60d20fdc0f..174ad62657 100644
--- a/libs/cua/crates/cua-spacesd-client/src/testing.rs
+++ b/libs/cua/crates/cua-spacesd-client/src/testing.rs
@@ -149,6 +149,8 @@ pub struct MockState {
/// Extra supported features reported by `GetCapabilities` (for clients
/// that gate on stream / window features).
extra_features: Mutex<Vec<String>>,
+ /// `GetCapabilities.version` (default `0.0.0-mock`).
+ version: Mutex<Option<String>>,
/// `GetCapabilitiesResponse::machine_seal_public_key` (S1); empty (an
/// older guest) unless a test sets one with
/// [`MockState::set_machine_seal_public_key`].
@@ -293,6 +295,11 @@ impl MockState {
.retain(|f| !names.contains(&f.as_str()));
}
+ /// Report `version` as this mock's cua-spacesd version.
+ pub fn set_version(&self, version: &str) {
+ *self.version.lock().unwrap() = Some(version.to_string());
+ }
+
/// Report `key` as this mock guest's sealed-delivery public key (S1).
pub fn set_machine_seal_public_key(&self, key: [u8; 32]) {
*self.machine_seal_public_key.lock().unwrap() = key.to_vec();
@@ -584,7 +591,13 @@ impl SystemService for Svc {
return Err(Status::unimplemented("not a spacesd"));
}
Ok(tonic::Response::new(pb::GetCapabilitiesResponse {
- version: "0.0.0-mock".into(),
+ version: self
+ .0
+ .version
+ .lock()
+ .unwrap()
+ .clone()
+ .unwrap_or_else(|| "0.0.0-mock".into()),
protocol_version: cua_proto::ENV_PROTOCOL_VERSION,
protocol_revision: cua_proto::ENV_PROTOCOL_REVISION,
os: Some(pb::OperatingSystem {