Skip to content

Commit 7d181e5

Browse files
committed
test(conformance): migrate create-upload tests to file_transfer stories
Move the three `sandbox create --upload` tests from the legacy Podman e2e crate into the file_transfer conformance area as story modules. The behavior is not Podman-specific, so it belongs with the other file transfer stories and runs against any prepared gateway. Test names are unchanged so filters keep working: - create_with_upload_directory_preserves_source_basename - create_with_multiple_uploads - create_with_upload_single_file Changes from the originals: - Verify uploads by reading the files back with `sandbox exec` and comparing exact content, instead of matching the printed output of `sandbox create`. - Check the nested file in the directory story, and that the directory is not flattened into the destination. - Check each destination in the multiple-uploads story separately. - Use the default upload path. The originals passed `--no-git-ignore`, which is unnecessary outside a Git work tree and hid the default path. - Create the sandbox from the target's default image. The originals created it from the e2e test image. - Drop the claim that files arrive before the command runs. The CLI rejects `--upload` together with a command, and the docs say uploads finish after the main process starts, so each story checks the files once `create` returns and documents the limitation. Remove the now-unused `SandboxGuard::create_with_upload` and `create_with_uploads` from the legacy harness, and the old test file. Contributes to #3954 Signed-off-by: politerealism <burdcat17@gmail.com>
1 parent 092c9bb commit 7d181e5

5 files changed

Lines changed: 232 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
@@ -390,87 +390,6 @@ impl SandboxGuard {
390390
})
391391
}
392392

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

‎e2e/rust/tests/upload_create.rs‎

Lines changed: 0 additions & 113 deletions
This file was deleted.
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
// SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
//! Stories for `sandbox create --upload`.
5+
//!
6+
//! Preconditions: the target supplies the default sandbox image. Each story
7+
//! writes its upload sources to a local temporary directory.
8+
//!
9+
//! Permissions: an identity allowed to create, execute in, and delete sandboxes.
10+
//!
11+
//! Side effects: each story creates one sandbox named from the run id and
12+
//! deletes it.
13+
//!
14+
//! Known limitation: `--upload` cannot be combined with a command, so stories
15+
//! check the files once `create` returns, not that they arrived before a main
16+
//! process started.
17+
18+
use super::helpers::{create_with_uploads, delete_sandbox, expect_stdout, fs_error};
19+
use openshell_e2e_support::OpenShellRunner;
20+
use std::fs;
21+
22+
/// Verify `sandbox create --upload <directory>:<destination>` keeps the
23+
/// directory's basename under the destination.
24+
#[tokio::test]
25+
async fn create_with_upload_directory_preserves_source_basename() {
26+
let mut runner = OpenShellRunner::from_env("file-transfer/create-upload-directory")
27+
.expect("candidate openshell CLI is available");
28+
let result = async {
29+
runner.check_gateway_status().await?;
30+
let runner = &mut runner;
31+
let local = tempfile::tempdir().map_err(fs_error("create temporary directory"))?;
32+
let source = local.path().join("project");
33+
fs::create_dir_all(source.join("src")).map_err(fs_error("create project/src"))?;
34+
fs::write(source.join("marker.txt"), "upload-create-marker")
35+
.map_err(fs_error("write marker.txt"))?;
36+
fs::write(source.join("src/main.py"), "print('hello')")
37+
.map_err(fs_error("write main.py"))?;
38+
39+
let sandbox_name = format!("ct-{}-cu1", runner.id());
40+
create_with_uploads(
41+
runner,
42+
"create-upload-directory/create",
43+
&sandbox_name,
44+
&[(&source, "/sandbox/data")],
45+
)
46+
.await?;
47+
48+
expect_stdout(
49+
runner,
50+
&sandbox_name,
51+
"create-upload-directory/marker",
52+
"cat /sandbox/data/project/marker.txt",
53+
"upload-create-marker",
54+
)
55+
.await?;
56+
expect_stdout(
57+
runner,
58+
&sandbox_name,
59+
"create-upload-directory/nested",
60+
"cat /sandbox/data/project/src/main.py",
61+
"print('hello')",
62+
)
63+
.await?;
64+
expect_stdout(
65+
runner,
66+
&sandbox_name,
67+
"create-upload-directory/not-flattened",
68+
"test ! -e /sandbox/data/marker.txt && echo absent",
69+
"absent\n",
70+
)
71+
.await?;
72+
delete_sandbox(runner, &sandbox_name).await
73+
}
74+
.await;
75+
if let Err(error) = runner.finish(result).await {
76+
panic!("file-transfer/create-upload-directory conformance story failed:\n{error}");
77+
}
78+
}
79+
80+
/// Verify several `--upload` flags on one `sandbox create` all place their
81+
/// files at their own destinations.
82+
#[tokio::test]
83+
async fn create_with_multiple_uploads() {
84+
let mut runner = OpenShellRunner::from_env("file-transfer/create-upload-multiple")
85+
.expect("candidate openshell CLI is available");
86+
let result = async {
87+
runner.check_gateway_status().await?;
88+
let runner = &mut runner;
89+
let local = tempfile::tempdir().map_err(fs_error("create temporary directory"))?;
90+
let alpha = local.path().join("alpha");
91+
let beta = local.path().join("beta");
92+
fs::create_dir_all(&alpha).map_err(fs_error("create alpha"))?;
93+
fs::create_dir_all(&beta).map_err(fs_error("create beta"))?;
94+
fs::write(alpha.join("a.txt"), "content-alpha").map_err(fs_error("write a.txt"))?;
95+
fs::write(beta.join("b.txt"), "content-beta").map_err(fs_error("write b.txt"))?;
96+
97+
let sandbox_name = format!("ct-{}-cu2", runner.id());
98+
create_with_uploads(
99+
runner,
100+
"create-upload-multiple/create",
101+
&sandbox_name,
102+
&[(&alpha, "/sandbox/alpha"), (&beta, "/sandbox/beta")],
103+
)
104+
.await?;
105+
106+
expect_stdout(
107+
runner,
108+
&sandbox_name,
109+
"create-upload-multiple/alpha",
110+
"cat /sandbox/alpha/alpha/a.txt",
111+
"content-alpha",
112+
)
113+
.await?;
114+
expect_stdout(
115+
runner,
116+
&sandbox_name,
117+
"create-upload-multiple/beta",
118+
"cat /sandbox/beta/beta/b.txt",
119+
"content-beta",
120+
)
121+
.await?;
122+
delete_sandbox(runner, &sandbox_name).await
123+
}
124+
.await;
125+
if let Err(error) = runner.finish(result).await {
126+
panic!("file-transfer/create-upload-multiple conformance story failed:\n{error}");
127+
}
128+
}
129+
130+
/// Verify `sandbox create --upload <file>:<destination>` places a single file
131+
/// at the destination.
132+
#[tokio::test]
133+
async fn create_with_upload_single_file() {
134+
let mut runner = OpenShellRunner::from_env("file-transfer/create-upload-file")
135+
.expect("candidate openshell CLI is available");
136+
let result = async {
137+
runner.check_gateway_status().await?;
138+
let runner = &mut runner;
139+
let local = tempfile::tempdir().map_err(fs_error("create temporary directory"))?;
140+
let source = local.path().join("config.txt");
141+
fs::write(&source, "single-file-upload-test").map_err(fs_error("write config.txt"))?;
142+
143+
let sandbox_name = format!("ct-{}-cu3", runner.id());
144+
create_with_uploads(
145+
runner,
146+
"create-upload-file/create",
147+
&sandbox_name,
148+
&[(&source, "/sandbox")],
149+
)
150+
.await?;
151+
152+
expect_stdout(
153+
runner,
154+
&sandbox_name,
155+
"create-upload-file/read",
156+
"cat /sandbox/config.txt",
157+
"single-file-upload-test",
158+
)
159+
.await?;
160+
delete_sandbox(runner, &sandbox_name).await
161+
}
162+
.await;
163+
if let Err(error) = runner.finish(result).await {
164+
panic!("file-transfer/create-upload-file conformance story failed:\n{error}");
165+
}
166+
}

0 commit comments

Comments
 (0)