Skip to content

Commit 7b5461e

Browse files
committed
test(conformance): port sandbox create --upload e2e tests to testkit
Move the three create_with_upload tests from e2e/rust into the conformance suite. They read each uploaded file back and compare exact content, check the nested file and that the directory is not flattened, and use the default upload path and the target's default image. Remove the legacy test and its now-unused SandboxGuard helpers. Signed-off-by: Evan Lezar <elezar@nvidia.com>
1 parent b4a6541 commit 7b5461e

5 files changed

Lines changed: 121 additions & 194 deletions

File tree

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

Lines changed: 0 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -386,87 +386,6 @@ impl SandboxGuard {
386386
})
387387
}
388388

389-
/// Create a detached scratch sandbox with pre-loaded files, then exec a
390-
/// command in it.
391-
///
392-
/// Equivalent to:
393-
/// ```text
394-
/// openshell sandbox create --detach --upload <local>:<dest> [extra_args...]
395-
/// openshell sandbox exec <name> -- <command>
396-
/// ```
397-
///
398-
/// The `--no-git-ignore` flag is passed to avoid needing a git repository.
399-
///
400-
/// # Errors
401-
///
402-
/// Returns an error if the CLI exits with a non-zero status or the sandbox
403-
/// name cannot be parsed.
404-
pub async fn create_with_upload(
405-
upload_local: &str,
406-
upload_dest: &str,
407-
command: &[&str],
408-
) -> Result<Self, String> {
409-
Self::create_with_uploads(&[(upload_local, upload_dest)], command).await
410-
}
411-
412-
/// Create a sandbox with multiple `--upload` specs.
413-
///
414-
/// Each element of `uploads` is a `(local_path, sandbox_dest)` pair.
415-
/// `--no-git-ignore` is applied to all uploads.
416-
pub async fn create_with_uploads(
417-
uploads: &[(&str, &str)],
418-
command: &[&str],
419-
) -> Result<Self, String> {
420-
let mut cmd = openshell_cmd();
421-
cmd.arg("sandbox").arg("create").arg("--detach");
422-
add_unique_name_if_missing(&mut cmd, &[]);
423-
add_test_image_if_missing(&mut cmd, &[]);
424-
for (local, dest) in uploads {
425-
cmd.arg("--upload").arg(format!("{local}:{dest}"));
426-
}
427-
cmd.arg("--no-git-ignore");
428-
cmd.stdout(Stdio::piped()).stderr(Stdio::piped());
429-
430-
let output = timeout(SANDBOX_READY_TIMEOUT, cmd.output())
431-
.await
432-
.map_err(|_| {
433-
format!("sandbox create --upload timed out after {SANDBOX_READY_TIMEOUT:?}")
434-
})?
435-
.map_err(|e| format!("failed to spawn openshell: {e}"))?;
436-
437-
let stdout = String::from_utf8_lossy(&output.stdout).to_string();
438-
let stderr = String::from_utf8_lossy(&output.stderr).to_string();
439-
let combined = format!("{stdout}{stderr}");
440-
441-
if !output.status.success() {
442-
return Err(format!(
443-
"sandbox create --upload failed (exit {:?}):\n{combined}",
444-
output.status.code()
445-
));
446-
}
447-
448-
let name = extract_sandbox_name(&combined).ok_or_else(|| {
449-
format!("could not parse sandbox name from create output:\n{combined}")
450-
})?;
451-
452-
let mut guard = Self {
453-
name,
454-
create_output: combined,
455-
child: None,
456-
cleaned_up: false,
457-
};
458-
459-
match guard.exec(command).await {
460-
Ok(exec_output) => guard.create_output.push_str(&exec_output),
461-
Err(err) => {
462-
guard.cleanup().await;
463-
return Err(err);
464-
}
465-
}
466-
467-
Ok(guard)
468-
}
469-
470389
/// Upload local files to the sandbox via `openshell sandbox upload`.
471390
///
472391
/// # Arguments

‎e2e/rust/tests/upload_create.rs‎

Lines changed: 0 additions & 113 deletions
This file was deleted.

‎tests/suites/conformance/README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ nextest run the tests as the library's unit tests. The crate also builds the
1414
| `persistent-workspace` | Files in `/sandbox` survive stop and start |
1515
| `policy-advisor` | `policy.local` accepts a proposed rule; a denied address or hostname yields one draft rule |
1616
| `file-transfer` | `sandbox upload` and `download`: round trips, file modes and symlinks outside the workspace, `.gitignore` filtering, workspace-escape and option-looking names, a large upload |
17+
| `create-upload` | `sandbox create --upload`: directory basename and nested files, multiple uploads, a single file |
1718
| `credential-gating` | Provider credentials: admission of credentialed endpoints, REST body placeholders and rewriting, WebSocket binary frames, live policy binding |
1819
| `image` | A sandbox runs the default image or the one it is created from |
1920
| `labels` | Labels are stored and select sandboxes in `sandbox list` |
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
// SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
//! `sandbox create --upload`.
5+
//!
6+
//! Ported from `e2e/rust/tests/upload_create.rs`, reworked in
7+
//! NVIDIA/OpenShell#4606 by politerealism. The behavior is not driver-specific.
8+
//!
9+
//! `--upload` cannot be combined with a command, so these tests create the
10+
//! sandbox with the target's default image and workload and check the files
11+
//! once `create` returns.
12+
13+
use std::fs;
14+
use std::path::Path;
15+
16+
use tempfile::TempDir;
17+
use testkit::{Context, ResultExt as _, Sandbox};
18+
19+
/// `--upload <directory>:<destination>` keeps the directory's basename under
20+
/// the destination, preserves nested files, and does not flatten the directory.
21+
#[testkit::test]
22+
async fn create_with_upload_directory_preserves_source_basename(
23+
cx: &mut Context,
24+
) -> testkit::Result {
25+
let local = scratch()?;
26+
let source = local.path().join("project");
27+
write(&source.join("marker.txt"), "upload-create-marker")?;
28+
write(&source.join("src/main.py"), "print('hello')")?;
29+
30+
let sandbox = create_with_uploads(cx, "cu1", &[(&source, "/sandbox/data")]).await?;
31+
expect_file(
32+
&sandbox,
33+
"/sandbox/data/project/marker.txt",
34+
"upload-create-marker",
35+
)
36+
.await?;
37+
expect_file(
38+
&sandbox,
39+
"/sandbox/data/project/src/main.py",
40+
"print('hello')",
41+
)
42+
.await?;
43+
sandbox
44+
.exec(["sh", "-c", "test ! -e /sandbox/data/marker.txt"])
45+
.await?
46+
.success()?;
47+
sandbox.delete().await
48+
}
49+
50+
/// Several `--upload` flags on one `sandbox create` each place their files at
51+
/// their own destination.
52+
#[testkit::test]
53+
async fn create_with_multiple_uploads(cx: &mut Context) -> testkit::Result {
54+
let local = scratch()?;
55+
let alpha = local.path().join("alpha");
56+
let beta = local.path().join("beta");
57+
write(&alpha.join("a.txt"), "content-alpha")?;
58+
write(&beta.join("b.txt"), "content-beta")?;
59+
60+
let sandbox = create_with_uploads(
61+
cx,
62+
"cu2",
63+
&[(&alpha, "/sandbox/alpha"), (&beta, "/sandbox/beta")],
64+
)
65+
.await?;
66+
expect_file(&sandbox, "/sandbox/alpha/alpha/a.txt", "content-alpha").await?;
67+
expect_file(&sandbox, "/sandbox/beta/beta/b.txt", "content-beta").await?;
68+
sandbox.delete().await
69+
}
70+
71+
/// `--upload <file>:<destination>` places a single file at the destination.
72+
#[testkit::test]
73+
async fn create_with_upload_single_file(cx: &mut Context) -> testkit::Result {
74+
let local = scratch()?;
75+
let source = local.path().join("config.txt");
76+
write(&source, "single-file-upload-test")?;
77+
78+
let sandbox = create_with_uploads(cx, "cu3", &[(&source, "/sandbox")]).await?;
79+
expect_file(&sandbox, "/sandbox/config.txt", "single-file-upload-test").await?;
80+
sandbox.delete().await
81+
}
82+
83+
fn scratch() -> testkit::Result<TempDir> {
84+
tempfile::tempdir().context("create a local scratch directory")
85+
}
86+
87+
fn write(path: &Path, content: &str) -> testkit::Result {
88+
if let Some(parent) = path.parent() {
89+
fs::create_dir_all(parent).context(format!("create {}", parent.display()))?;
90+
}
91+
fs::write(path, content).context(format!("write {}", path.display()))
92+
}
93+
94+
/// Create a detached sandbox with one `--upload <source>:<destination>` flag
95+
/// per entry and wait until it is Ready.
96+
async fn create_with_uploads(
97+
cx: &Context,
98+
suffix: &str,
99+
uploads: &[(&Path, &str)],
100+
) -> testkit::Result<Sandbox> {
101+
let args = uploads.iter().flat_map(|(source, destination)| {
102+
[
103+
"--upload".to_string(),
104+
format!("{}:{destination}", source.display()),
105+
]
106+
});
107+
cx.cli_sandbox(suffix).args(args).create_ready().await
108+
}
109+
110+
/// Require the sandbox file at `path` to contain exactly `expected`.
111+
async fn expect_file(sandbox: &Sandbox, path: &str, expected: &str) -> testkit::Result {
112+
let output = sandbox.exec(["cat", path]).await?.success()?;
113+
testkit::ensure!(
114+
output.stdout == expected,
115+
"{path} contains {:?}; expected {expected:?}",
116+
output.stdout
117+
);
118+
Ok(())
119+
}

‎tests/suites/conformance/src/lib.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
//! program in `src/main.rs` runs them by linking this library.
1010
1111
mod cli;
12+
mod create_upload;
1213
mod credential_gating;
1314
mod file_transfer;
1415
mod filesystem_policy;

0 commit comments

Comments
 (0)