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): guest volume paths are POSIX on every host; Windows test fixes (#5860)

cua-agents[bot]7ce332441a1b
diff --git a/.gitattributes b/.gitattributes
index 94e6c5fbaa..9ac06bb106 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -5,3 +5,6 @@
docs/content/docs/cua-driver/reference/** text eol=lf
scripts/docs-generators/cli-specs/** text eol=lf
scripts/docs-generators/headers/** text eol=lf
+# The elastic solver's golden decisions are compared byte for byte with what
+# serde writes (LF); a CRLF checkout (Windows) would fail every scenario.
+libs/cua/crates/cua-cluster/testdata/elastic/** text eol=lf
diff --git a/libs/cua/crates/cua-cli/src/jobs_cmd.rs b/libs/cua/crates/cua-cli/src/jobs_cmd.rs
index faf211849f..504a0006ab 100644
--- a/libs/cua/crates/cua-cli/src/jobs_cmd.rs
+++ b/libs/cua/crates/cua-cli/src/jobs_cmd.rs
@@ -811,7 +811,6 @@ pub fn project_bundle(dir: &Path, files: &[String]) -> Result<Vec<u8>, CuaError>
for f in files {
let p = dir.join(f);
let data = std::fs::read(&p).map_err(io)?;
- #[cfg_attr(not(unix), allow(unused_mut))]
let mut mode = 0o644;
#[cfg(unix)]
{
@@ -823,6 +822,14 @@ pub fn project_bundle(dir: &Path, files: &[String]) -> Result<Vec<u8>, CuaError>
mode = 0o755;
}
}
+ // A Windows file has no mode to keep, and the node that runs it does:
+ // a script (it starts with `#!`) stays executable.
+ #[cfg(not(unix))]
+ {
+ if data.starts_with(b"#!") {
+ mode = 0o755;
+ }
+ }
let mut h = tar::Header::new_gnu();
h.set_size(data.len() as u64);
h.set_mode(mode);
diff --git a/libs/cua/crates/cua-cluster/src/gang_mesh.rs b/libs/cua/crates/cua-cluster/src/gang_mesh.rs
index f0cbe14bfa..251fbfdb3c 100644
--- a/libs/cua/crates/cua-cluster/src/gang_mesh.rs
+++ b/libs/cua/crates/cua-cluster/src/gang_mesh.rs
@@ -247,17 +247,22 @@ mod tests {
#[tokio::test]
async fn without_a_mesh_node_the_placed_addresses_stay_and_say_so() {
let home = tempfile::tempdir().unwrap();
+ // Why the mesh is not used: no node here (macOS, Linux), or no mesh
+ // on this OS at all (Windows).
+ let why = if cfg!(unix) {
+ "the mesh is off on this computer"
+ } else {
+ "gang traffic over the mesh needs macOS or Linux"
+ };
let r = MeshPeerRouter::new(home.path())
.route(&gang(0, &["m-a", "m-b"]), MemberNet::machine())
.await
.unwrap()
.expect("routed");
assert_eq!(r.peers, ["10.0.0.1:47010", "10.0.0.2:47010"]);
- assert!(
- r.notes[0]
- == "rank traffic uses the placed addresses: the mesh is off on this computer",
- "{:?}",
- r.notes
+ assert_eq!(
+ r.notes[0],
+ format!("rank traffic uses the placed addresses: {why}")
);
assert_eq!(
r.notes[1],
@@ -290,7 +295,7 @@ mod tests {
.route(&gang(0, &["m-a", "m-b"]), vm)
.await
.unwrap_err();
- assert!(e.contains("the mesh is off on this computer"), "{e}");
+ assert!(e.contains(why), "{e}");
}
#[tokio::test]
diff --git a/libs/cua/crates/cua-spaces/src/named_volumes.rs b/libs/cua/crates/cua-spaces/src/named_volumes.rs
index 4069b70fdf..19f2817490 100644
--- a/libs/cua/crates/cua-spaces/src/named_volumes.rs
+++ b/libs/cua/crates/cua-spaces/src/named_volumes.rs
@@ -86,13 +86,11 @@ impl VolumeMount {
self.name
)));
}
- let path = Path::new(&self.path);
- if !path.is_absolute()
- || self.path == "/"
+ // The path is inside the guest, where paths are POSIX whatever this
+ // machine is: a Windows host's `Path` calls `/mnt/a` relative.
+ if !self.path.starts_with('/')
+ || self.path.trim_matches('/').is_empty()
|| self.path.split('/').any(|seg| seg == "." || seg == "..")
- || !path
- .components()
- .all(|c| matches!(c, Component::RootDir | Component::Normal(_)))
{
return Err(Error::invalid(format!(
"volume {:?}: the path {:?} must be absolute, without `.` or `..` (for example \
@@ -117,6 +115,11 @@ impl VolumeMount {
}
}
+/// The folders of a guest path, in order (empty ones, from `//`, dropped).
+fn guest_segments(path: &str) -> Vec<&str> {
+ path.split('/').filter(|s| !s.is_empty()).collect()
+}
+
/// Checks a Space's mounts: each valid, no two at the same or nested paths.
pub fn validate(mounts: &[VolumeMount]) -> Result<()> {
if mounts.len() > MAX_MOUNTS {
@@ -127,10 +130,10 @@ pub fn validate(mounts: &[VolumeMount]) -> Result<()> {
}
for (i, m) in mounts.iter().enumerate() {
m.check()?;
- let p = Path::new(&m.path);
+ let p = guest_segments(&m.path);
for other in &mounts[..i] {
- let q = Path::new(&other.path);
- if p.starts_with(q) || q.starts_with(p) {
+ let q = guest_segments(&other.path);
+ if p.starts_with(&q) || q.starts_with(&p) {
return Err(Error::invalid(format!(
"volumes {:?} and {:?} are mounted at {} and {}: paths cannot be the same \
or inside one another",