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-spaces): name a local Space what it was created as (#4849)

ddupontb0a6348133a3
diff --git a/libs/cua/crates/cua-spaces/src/spaces.rs b/libs/cua/crates/cua-spaces/src/spaces.rs
index 4b5922710b..9902eaadac 100644
--- a/libs/cua/crates/cua-spaces/src/spaces.rs
+++ b/libs/cua/crates/cua-spaces/src/spaces.rs
@@ -1439,11 +1439,13 @@ impl Spaces {
/// cua-spacesd, retries until the driver answers or `budget` runs out
/// (the driver may start a moment after the port is published; bounded:
/// at most `budget / 2s` attempts). Otherwise one bounded handshake, and
- /// a Space of declared services when no driver answers.
+ /// a Space of declared services when no driver answers. `name` is the
+ /// Space's name (without one, the guest's hostname).
async fn connect_when_ready(
&self,
id: &SpaceId,
credential: &Credential,
+ name: Option<&str>,
budget: Duration,
expect_spacesd: bool,
) -> Result<Space> {
@@ -1452,13 +1454,13 @@ impl Spaces {
.inner
.probe_timeout
.min(budget.max(Duration::from_secs(1)));
- return self.connect_with(id, credential, None, probe).await;
+ return self.connect_with(id, credential, name, probe).await;
}
let deadline = tokio::time::Instant::now() + budget;
let max_attempts = (budget.as_secs() / 2).max(1) + 1;
let mut last = None;
for _ in 0..max_attempts {
- match self.connect(id, credential, None).await {
+ match self.connect(id, credential, name).await {
Ok(s) if s.has_spacesd() => return Ok(s),
Ok(_) => last = Some("cua-spacesd did not answer yet".to_string()),
Err(e @ Error::Env(cua_spacesd_client::Error::Unauthenticated(_))) => {
@@ -1664,7 +1666,7 @@ impl Spaces {
cua_sandbox_core::progress::Phase::Connecting,
));
let space = match self
- .connect_when_ready(&id, &credential, Duration::from_secs(120), expect_env)
+ .connect_when_ready(&id, &credential, None, Duration::from_secs(120), expect_env)
.await
{
Ok(s) => s,
@@ -2215,7 +2217,7 @@ impl Spaces {
cua_sandbox_core::progress::Phase::Connecting,
));
let space = match self
- .connect_when_ready(&id, &credential, remaining, expect_env)
+ .connect_when_ready(&id, &credential, Some(&name), remaining, expect_env)
.await
{
Ok(s) => s,
@@ -2294,7 +2296,7 @@ impl Spaces {
..Default::default()
};
match self
- .connect_when_ready(&id, &credential, budget, j.spacesd)
+ .connect_when_ready(&id, &credential, Some(&j.name), budget, j.spacesd)
.await
{
Ok(space) => match self.store(&space, credential) {
diff --git a/libs/cua/crates/cua-spaces/tests/providers.rs b/libs/cua/crates/cua-spaces/tests/providers.rs
index 8a3e55ede1..6e68969885 100644
--- a/libs/cua/crates/cua-spaces/tests/providers.rs
+++ b/libs/cua/crates/cua-spaces/tests/providers.rs
@@ -351,6 +351,63 @@ async fn create_locally_starts_with_a_fresh_token_and_delete_deletes() {
assert!(fresh.list().unwrap().is_empty());
}
+/// A local Space is listed under the name it was created with (or the
+/// generated `space-<hex>`), not the guest's hostname (a container's short
+/// id); `add` without a name still shows the hostname (#4707).
+#[tokio::test]
+async fn a_local_space_is_named_what_it_was_created_as() {
+ let srv = MockServer::start(MockAuth::default()).await;
+ let rt = Arc::new(FakeRuntime {
+ port: srv.addr.port(),
+ started: Mutex::new(vec![]),
+ deleted: Mutex::new(vec![]),
+ running: Mutex::new(BTreeMap::new()),
+ });
+ let reg = tempfile::tempdir().unwrap();
+ let state = tempfile::tempdir().unwrap();
+ let spaces = Spaces::builder()
+ .home(reg.path())
+ .sandboxes(
+ cua_sandbox_core::Sandboxes::builder()
+ .local(rt.clone())
+ .state_dir(state.path())
+ .build(),
+ )
+ .build();
+ let create = |name: Option<&str>| SpaceCreate {
+ on: Some(On::Local),
+ image: Some("cua-e2e-local/linux:docker-local-arm64".into()),
+ spacesd: Some(true),
+ name: name.map(str::to_string),
+ timeout: Some(Duration::from_secs(20)),
+ ..Default::default()
+ };
+ let named = spaces
+ .create(create(Some("todo7b-probe")))
+ .await
+ .unwrap()
+ .ready()
+ .unwrap();
+ assert_eq!(named.id, "local:todo7b-probe");
+ assert_eq!(named.name, "todo7b-probe");
+ let generated = spaces.create(create(None)).await.unwrap().ready().unwrap();
+ let short = generated.id.strip_prefix("local:").unwrap();
+ assert!(short.starts_with("space-"), "{}", generated.id);
+ assert_eq!(generated.name, short);
+ let listed: BTreeMap<String, String> = spaces
+ .list()
+ .unwrap()
+ .into_iter()
+ .map(|i| (i.id, i.name))
+ .collect();
+ assert_eq!(listed[&named.id], "todo7b-probe");
+ assert_eq!(listed[&generated.id], short);
+
+ // Control: a Space added without a name shows the guest's hostname.
+ let added = spaces.add(&srv.url(), None, None).await.unwrap();
+ assert_eq!(added.name, "mock");
+}
+
/// `cua spaces create linux` (and `macos:26`, `macos:26-slim`) on this
/// machine: the alias names the canonical image, as it does in the cloud.
/// The local runtime only knows registry references, so before this it