Skip to content

Commit eea9751

Browse files
authored
feat(cli): support multiple --upload flags on sandbox create (#1635) (#1645)
Closes #1635 Signed-off-by: Philippe Martin <[email protected]>
1 parent 69764d8 commit eea9751

6 files changed

Lines changed: 138 additions & 32 deletions

File tree

‎crates/openshell-cli/src/main.rs‎

Lines changed: 55 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,7 +1188,7 @@ enum SandboxCommands {
11881188
/// `.gitignore` rules are applied by default; use `--no-git-ignore` to
11891189
/// upload everything.
11901190
#[arg(long, value_hint = ValueHint::AnyPath, help_heading = "UPLOAD FLAGS")]
1191-
upload: Option<String>,
1191+
upload: Vec<String>,
11921192

11931193
/// Disable `.gitignore` filtering for `--upload`.
11941194
#[arg(long, requires = "upload", help_heading = "UPLOAD FLAGS")]
@@ -2583,11 +2583,22 @@ async fn main() -> Result<()> {
25832583
labels_map.insert(parts[0].to_string(), parts[1].to_string());
25842584
}
25852585

2586-
// Parse --upload spec into (local_path, sandbox_path, git_ignore).
2587-
let upload_spec = upload.as_deref().map(|s| {
2588-
let (local, remote) = parse_upload_spec(s);
2589-
(local, remote, !no_git_ignore)
2590-
});
2586+
// Parse --upload specs into [(local_path, sandbox_path, git_ignore)].
2587+
let upload_specs: Vec<(String, Option<String>, bool)> = upload
2588+
.iter()
2589+
.map(|s| {
2590+
let (local, remote) = parse_upload_spec(s);
2591+
(local, remote, !no_git_ignore)
2592+
})
2593+
.collect();
2594+
2595+
// Validate all local paths before creating the sandbox so failures are
2596+
// fast and have no side effects.
2597+
for (local, _, _) in &upload_specs {
2598+
if std::fs::symlink_metadata(local).is_err() {
2599+
return Err(miette::miette!("local path does not exist: {}", local));
2600+
}
2601+
}
25912602

25922603
let editor = editor.map(Into::into);
25932604
let forward = forward
@@ -2604,7 +2615,7 @@ async fn main() -> Result<()> {
26042615
name.as_deref(),
26052616
from.as_deref(),
26062617
&ctx.name,
2607-
upload_spec.as_ref(),
2618+
&upload_specs,
26082619
keep,
26092620
gpu,
26102621
gpu_device.as_deref(),
@@ -3484,6 +3495,43 @@ mod tests {
34843495
assert_eq!(remote, None);
34853496
}
34863497

3498+
#[test]
3499+
fn sandbox_create_upload_flag_accepts_multiple_values() {
3500+
let result = Cli::try_parse_from([
3501+
"openshell",
3502+
"sandbox",
3503+
"create",
3504+
"--upload",
3505+
"./src:/workspace/src",
3506+
"--upload",
3507+
"./config:/workspace/config",
3508+
]);
3509+
assert!(
3510+
result.is_ok(),
3511+
"--upload should be repeatable, got: {:?}",
3512+
result.err()
3513+
);
3514+
}
3515+
3516+
#[test]
3517+
fn sandbox_create_upload_flag_accepts_zero_values() {
3518+
let result = Cli::try_parse_from(["openshell", "sandbox", "create"]);
3519+
assert!(
3520+
result.is_ok(),
3521+
"sandbox create with no --upload should succeed, got: {:?}",
3522+
result.err()
3523+
);
3524+
}
3525+
3526+
#[test]
3527+
fn sandbox_create_no_git_ignore_requires_upload() {
3528+
let result = Cli::try_parse_from(["openshell", "sandbox", "create", "--no-git-ignore"]);
3529+
assert!(
3530+
result.is_err(),
3531+
"--no-git-ignore without --upload should be rejected"
3532+
);
3533+
}
3534+
34873535
#[test]
34883536
fn resolve_sandbox_name_returns_explicit_name() {
34893537
// When a name is provided, it should be returned regardless of any

‎crates/openshell-cli/src/run.rs‎

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1710,7 +1710,7 @@ pub async fn sandbox_create(
17101710
name: Option<&str>,
17111711
from: Option<&str>,
17121712
gateway_name: &str,
1713-
upload: Option<&(String, Option<String>, bool)>,
1713+
uploads: &[(String, Option<String>, bool)],
17141714
keep: bool,
17151715
gpu: bool,
17161716
gpu_device: Option<&str>,
@@ -2076,13 +2076,23 @@ pub async fn sandbox_create(
20762076
drop(stream);
20772077
drop(client);
20782078

2079-
if let Some((local_path, sandbox_path, git_ignore)) = upload {
2079+
let upload_count = uploads.len();
2080+
for (idx, (local_path, sandbox_path, git_ignore)) in uploads.iter().enumerate() {
20802081
let dest = sandbox_path.as_deref();
20812082
let dest_display = dest.unwrap_or("~");
2082-
eprintln!(
2083-
" {} Uploading files to {dest_display}...",
2084-
"\u{2022}".dimmed(),
2085-
);
2083+
if upload_count > 1 {
2084+
eprintln!(
2085+
" {} Uploading [{}/{}] files to {dest_display}...",
2086+
"\u{2022}".dimmed(),
2087+
idx + 1,
2088+
upload_count,
2089+
);
2090+
} else {
2091+
eprintln!(
2092+
" {} Uploading files to {dest_display}...",
2093+
"\u{2022}".dimmed(),
2094+
);
2095+
}
20862096
let local = Path::new(local_path);
20872097
match sandbox_upload_plan(local, *git_ignore)? {
20882098
SandboxUploadPlan::GitAware { base_dir, files } => {

‎crates/openshell-cli/tests/sandbox_create_lifecycle_integration.rs‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,7 @@ async fn sandbox_create_keeps_command_sessions_by_default() {
780780
Some("default-command"),
781781
None,
782782
"openshell",
783-
None,
783+
&[],
784784
true,
785785
false,
786786
None,
@@ -822,7 +822,7 @@ async fn sandbox_create_sends_cpu_and_memory_limits_only() {
822822
Some("resources"),
823823
None,
824824
"openshell",
825-
None,
825+
&[],
826826
true,
827827
false,
828828
None,
@@ -899,7 +899,7 @@ async fn sandbox_create_does_not_infer_command_providers_when_v2_enabled() {
899899
Some("v2-no-inferred-provider"),
900900
None,
901901
"openshell",
902-
None,
902+
&[],
903903
true,
904904
false,
905905
None,
@@ -956,7 +956,7 @@ async fn sandbox_create_returns_vm_error_without_waiting_for_timeout() {
956956
Some("vm-error"),
957957
None,
958958
"openshell",
959-
None,
959+
&[],
960960
true,
961961
false,
962962
None,
@@ -1009,7 +1009,7 @@ async fn sandbox_create_keeps_waiting_while_vm_progress_arrives() {
10091009
Some("vm-slow-progress"),
10101010
None,
10111011
"openshell",
1012-
None,
1012+
&[],
10131013
true,
10141014
false,
10151015
None,
@@ -1054,7 +1054,7 @@ async fn sandbox_create_times_out_when_only_logs_arrive() {
10541054
Some("vm-log-churn"),
10551055
None,
10561056
"openshell",
1057-
None,
1057+
&[],
10581058
true,
10591059
false,
10601060
None,
@@ -1095,7 +1095,7 @@ async fn sandbox_create_deletes_command_sessions_with_no_keep() {
10951095
Some("ephemeral-command"),
10961096
None,
10971097
"openshell",
1098-
None,
1098+
&[],
10991099
false,
11001100
false,
11011101
None,
@@ -1140,7 +1140,7 @@ async fn sandbox_create_deletes_shell_sessions_with_no_keep() {
11401140
Some("ephemeral-shell"),
11411141
None,
11421142
"openshell",
1143-
None,
1143+
&[],
11441144
false,
11451145
false,
11461146
None,
@@ -1185,7 +1185,7 @@ async fn sandbox_create_keeps_sandbox_with_hidden_keep_flag() {
11851185
Some("persistent-keep"),
11861186
None,
11871187
"openshell",
1188-
None,
1188+
&[],
11891189
true,
11901190
false,
11911191
None,
@@ -1230,7 +1230,7 @@ async fn sandbox_create_keeps_sandbox_with_forwarding() {
12301230
Some("persistent-forward"),
12311231
None,
12321232
"openshell",
1233-
None,
1233+
&[],
12341234
false,
12351235
false,
12361236
None,

‎docs/sandboxes/manage-sandboxes.mdx‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,12 @@ The CLI only allows sandbox-side sources that resolve inside the writable worksp
309309
310310
<Note>
311311
You can also upload files at creation time with the `--upload` flag on
312-
`openshell sandbox create`.
312+
`openshell sandbox create`. Pass `--upload` multiple times to upload
313+
several paths in a single command:
314+
315+
```shell
316+
openshell sandbox create --upload ./src:/workspace/src --upload ./config:/workspace/config -- claude
317+
```
313318
314319
</Note>
315320

‎e2e/rust/src/harness/sandbox.rs‎

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -216,16 +216,23 @@ impl SandboxGuard {
216216
upload_dest: &str,
217217
command: &[&str],
218218
) -> Result<Self, String> {
219-
let upload_spec = format!("{upload_local}:{upload_dest}");
219+
Self::create_with_uploads(&[(upload_local, upload_dest)], command).await
220+
}
220221

222+
/// Create a sandbox with multiple `--upload` specs.
223+
///
224+
/// Each element of `uploads` is a `(local_path, sandbox_dest)` pair.
225+
/// `--no-git-ignore` is applied to all uploads.
226+
pub async fn create_with_uploads(
227+
uploads: &[(&str, &str)],
228+
command: &[&str],
229+
) -> Result<Self, String> {
221230
let mut cmd = openshell_cmd();
222-
cmd.arg("sandbox")
223-
.arg("create")
224-
.arg("--upload")
225-
.arg(&upload_spec)
226-
.arg("--no-git-ignore")
227-
.arg("--")
228-
.args(command);
231+
cmd.arg("sandbox").arg("create");
232+
for (local, dest) in uploads {
233+
cmd.arg("--upload").arg(format!("{local}:{dest}"));
234+
}
235+
cmd.arg("--no-git-ignore").arg("--").args(command);
229236
cmd.stdout(Stdio::piped()).stderr(Stdio::piped());
230237

231238
let output = timeout(SANDBOX_READY_TIMEOUT, cmd.output())

‎e2e/rust/tests/upload_create.rs‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,42 @@ async fn create_with_upload_directory_preserves_source_basename() {
5252
guard.cleanup().await;
5353
}
5454

55+
/// Two `--upload` specs in a single `sandbox create` call should both land in
56+
/// the sandbox before the command runs.
57+
#[tokio::test]
58+
async fn create_with_multiple_uploads() {
59+
let tmpdir = tempfile::tempdir().expect("create tmpdir");
60+
61+
let dir_a = tmpdir.path().join("alpha");
62+
let dir_b = tmpdir.path().join("beta");
63+
fs::create_dir_all(&dir_a).expect("create alpha");
64+
fs::create_dir_all(&dir_b).expect("create beta");
65+
fs::write(dir_a.join("a.txt"), "content-alpha").expect("write a.txt");
66+
fs::write(dir_b.join("b.txt"), "content-beta").expect("write b.txt");
67+
68+
let spec_a = dir_a.to_str().expect("alpha path is UTF-8");
69+
let spec_b = dir_b.to_str().expect("beta path is UTF-8");
70+
71+
let mut guard = SandboxGuard::create_with_uploads(
72+
&[(spec_a, "/sandbox/alpha"), (spec_b, "/sandbox/beta")],
73+
&["sh", "-c", "cat /sandbox/alpha/alpha/a.txt /sandbox/beta/beta/b.txt"],
74+
)
75+
.await
76+
.expect("sandbox create with multiple --upload flags");
77+
78+
let clean = strip_ansi(&guard.create_output);
79+
assert!(
80+
clean.contains("content-alpha"),
81+
"expected alpha content in output:\n{clean}"
82+
);
83+
assert!(
84+
clean.contains("content-beta"),
85+
"expected beta content in output:\n{clean}"
86+
);
87+
88+
guard.cleanup().await;
89+
}
90+
5591
/// `--upload` with a single file (not a directory) should work.
5692
#[tokio::test]
5793
async fn create_with_upload_single_file() {

0 commit comments

Comments
 (0)