Skip to content

Commit 92d569b

Browse files
test(conformance): migrate create-upload tests to testkit (#4606)
* 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> * test(conformance): use expect_stdout for create-upload file checks Signed-off-by: Matthew Grossman <mgrossman@nvidia.com> --------- Signed-off-by: Evan Lezar <elezar@nvidia.com> Signed-off-by: Matthew Grossman <mgrossman@nvidia.com> Co-authored-by: Matthew Grossman <mgrossman@nvidia.com>
1 parent bf9f55c commit 92d569b

5 files changed

Lines changed: 115 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: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
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+
sandbox
32+
.exec(["cat", "/sandbox/data/project/marker.txt"])
33+
.await?
34+
.expect_stdout("upload-create-marker")?;
35+
sandbox
36+
.exec(["cat", "/sandbox/data/project/src/main.py"])
37+
.await?
38+
.expect_stdout("print('hello')")?;
39+
sandbox
40+
.exec(["sh", "-c", "test ! -e /sandbox/data/marker.txt"])
41+
.await?
42+
.success()?;
43+
sandbox.delete().await
44+
}
45+
46+
/// Several `--upload` flags on one `sandbox create` each place their files at
47+
/// their own destination.
48+
#[testkit::test]
49+
async fn create_with_multiple_uploads(cx: &mut Context) -> testkit::Result {
50+
let local = scratch()?;
51+
let alpha = local.path().join("alpha");
52+
let beta = local.path().join("beta");
53+
write(&alpha.join("a.txt"), "content-alpha")?;
54+
write(&beta.join("b.txt"), "content-beta")?;
55+
56+
let sandbox = create_with_uploads(
57+
cx,
58+
"cu2",
59+
&[(&alpha, "/sandbox/alpha"), (&beta, "/sandbox/beta")],
60+
)
61+
.await?;
62+
sandbox
63+
.exec(["cat", "/sandbox/alpha/alpha/a.txt"])
64+
.await?
65+
.expect_stdout("content-alpha")?;
66+
sandbox
67+
.exec(["cat", "/sandbox/beta/beta/b.txt"])
68+
.await?
69+
.expect_stdout("content-beta")?;
70+
sandbox.delete().await
71+
}
72+
73+
/// `--upload <file>:<destination>` places a single file at the destination.
74+
#[testkit::test]
75+
async fn create_with_upload_single_file(cx: &mut Context) -> testkit::Result {
76+
let local = scratch()?;
77+
let source = local.path().join("config.txt");
78+
write(&source, "single-file-upload-test")?;
79+
80+
let sandbox = create_with_uploads(cx, "cu3", &[(&source, "/sandbox")]).await?;
81+
sandbox
82+
.exec(["cat", "/sandbox/config.txt"])
83+
.await?
84+
.expect_stdout("single-file-upload-test")?;
85+
sandbox.delete().await
86+
}
87+
88+
fn scratch() -> testkit::Result<TempDir> {
89+
tempfile::tempdir().context("create a local scratch directory")
90+
}
91+
92+
fn write(path: &Path, content: &str) -> testkit::Result {
93+
if let Some(parent) = path.parent() {
94+
fs::create_dir_all(parent).context(format!("create {}", parent.display()))?;
95+
}
96+
fs::write(path, content).context(format!("write {}", path.display()))
97+
}
98+
99+
/// Create a detached sandbox with one `--upload <source>:<destination>` flag
100+
/// per entry and wait until it is Ready.
101+
async fn create_with_uploads(
102+
cx: &Context,
103+
suffix: &str,
104+
uploads: &[(&Path, &str)],
105+
) -> testkit::Result<Sandbox> {
106+
let args = uploads.iter().flat_map(|(source, destination)| {
107+
[
108+
"--upload".to_string(),
109+
format!("{}:{destination}", source.display()),
110+
]
111+
});
112+
cx.cli_sandbox(suffix).args(args).create_ready().await
113+
}

‎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)