Skip to content

Commit ced747a

Browse files
committed
test(conformance): migrate upload_create into file-transfer conformance
Port sandbox create --upload coverage from e2e/rust/tests/upload_create.rs into a new file-transfer/create-upload scenario in crates/openshell-conformance/src/scenarios/file_transfer.rs, grouped alongside the other file/template-transfer conformance scenarios rather than left scattered in the Podman-specific e2e suite. Wire it into the FILE_TRANSFER_SCENARIO chain and the conformance CLI test crate, and remove the old per-driver test file (picked up by Cargo's default test auto-discovery; it had no Cargo.toml or artifacts.nix entries to clean up). Verified against an ephemeral Podman gateway: the new create-upload scenario and the existing path-safety scenario pass. round-trip and git-filtering already fail against current main on code this change does not touch (the CLI doesn't warn/reject non-Git-tree uploads the way those scenarios assert) -- pre-existing, out of scope here. Signed-off-by: politerealism <burdcat17@gmail.com> (cherry picked from commit 398dfe3) Signed-off-by: politerealism <burdcat17@gmail.com>
1 parent 4a0738d commit ced747a

5 files changed

Lines changed: 238 additions & 121 deletions

File tree

‎crates/openshell-conformance/src/lib.rs‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@ use tokio::time::sleep;
2424
use self::executor::{CliExecutionError, CliExecutor, ProcessCli};
2525

2626
pub use scenarios::{
27-
FILE_TRANSFER_GIT_FILTERING_SCENARIO, FILE_TRANSFER_PATH_SAFETY_SCENARIO,
28-
FILE_TRANSFER_ROUND_TRIP_SCENARIO, MECHANISTIC_PROPOSAL_SCENARIO,
29-
NEW_HOSTNAME_PROPOSAL_SCENARIO, POLICY_LOCAL_SCENARIO, SANDBOX_LIFECYCLE_SCENARIO,
30-
SMOKE_SCENARIO, WORKSPACE_LIFECYCLE_SCENARIO, WORKSPACE_TERMINATING_SCENARIO,
27+
FILE_TRANSFER_CREATE_UPLOAD_DIRECTORY_SCENARIO, FILE_TRANSFER_CREATE_UPLOAD_FILE_SCENARIO,
28+
FILE_TRANSFER_CREATE_UPLOAD_MULTIPLE_SCENARIO, FILE_TRANSFER_GIT_FILTERING_SCENARIO,
29+
FILE_TRANSFER_PATH_SAFETY_SCENARIO, FILE_TRANSFER_ROUND_TRIP_SCENARIO,
30+
MECHANISTIC_PROPOSAL_SCENARIO, NEW_HOSTNAME_PROPOSAL_SCENARIO, POLICY_LOCAL_SCENARIO,
31+
SANDBOX_LIFECYCLE_SCENARIO, SMOKE_SCENARIO, WORKSPACE_LIFECYCLE_SCENARIO,
32+
WORKSPACE_TERMINATING_SCENARIO,
3133
};
3234

3335
/// A portable conformance scenario exercised by the Cargo test suite.

‎crates/openshell-conformance/src/scenarios/file_transfer.rs‎

Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,40 @@ pub const FILE_TRANSFER_PATH_SAFETY_SCENARIO: Scenario = Scenario {
3535
run: run_path_safety,
3636
};
3737

38+
/// Certify that `sandbox create --upload <dir>:<dest>` preserves the source
39+
/// directory's basename under the destination.
40+
///
41+
/// - **Behavior:** a directory passed to `sandbox create --upload <dir>:<dest>` is available in the sandbox under `<dest>/<directory name>`, keeping the source directory's basename. Verified by reading a file from inside the sandbox.
42+
/// - **Preconditions:** a reachable gateway whose compute driver can create sandboxes from the default image (supplied by target preparation). The test writes its upload sources to a local temporary directory.
43+
/// - **Permissions:** an identity allowed to create, execute in, and delete sandboxes.
44+
/// - **Side effects:** creates one sandbox named from the run id, which the runner removes on success and on failure (a cleanup failure fails the scenario), and a local temporary directory.
45+
pub const FILE_TRANSFER_CREATE_UPLOAD_DIRECTORY_SCENARIO: Scenario = Scenario {
46+
name: "file-transfer/create-upload-directory",
47+
run: run_create_upload_directory,
48+
};
49+
50+
/// Certify that `sandbox create` accepts several `--upload` flags at once.
51+
///
52+
/// - **Behavior:** several `--upload` flags on one `sandbox create` are all pre-loaded to their own destinations. Verified by reading a file from each destination inside the sandbox.
53+
/// - **Preconditions:** a reachable gateway whose compute driver can create sandboxes from the default image (supplied by target preparation). The test writes its upload sources to a local temporary directory.
54+
/// - **Permissions:** an identity allowed to create, execute in, and delete sandboxes.
55+
/// - **Side effects:** creates one sandbox named from the run id, which the runner removes on success and on failure (a cleanup failure fails the scenario), and a local temporary directory.
56+
pub const FILE_TRANSFER_CREATE_UPLOAD_MULTIPLE_SCENARIO: Scenario = Scenario {
57+
name: "file-transfer/create-upload-multiple",
58+
run: run_create_upload_multiple,
59+
};
60+
61+
/// Certify that `sandbox create --upload <file>` pre-loads a single file.
62+
///
63+
/// - **Behavior:** a single file passed to `sandbox create --upload` is available in the sandbox at the requested destination. Verified by reading it from inside the sandbox.
64+
/// - **Preconditions:** a reachable gateway whose compute driver can create sandboxes from the default image (supplied by target preparation). The test writes its upload sources to a local temporary directory.
65+
/// - **Permissions:** an identity allowed to create, execute in, and delete sandboxes.
66+
/// - **Side effects:** creates one sandbox named from the run id, which the runner removes on success and on failure (a cleanup failure fails the scenario), and a local temporary directory.
67+
pub const FILE_TRANSFER_CREATE_UPLOAD_FILE_SCENARIO: Scenario = Scenario {
68+
name: "file-transfer/create-upload-file",
69+
run: run_create_upload_file,
70+
};
71+
3872
fn run_round_trip(runner: &mut OpenShellRunner) -> ScenarioFuture<'_> {
3973
Box::pin(async move {
4074
let (sandbox_name, remote_root, local) = prepare_sandbox(runner, "round-trip").await?;
@@ -66,6 +100,178 @@ fn run_path_safety(runner: &mut OpenShellRunner) -> ScenarioFuture<'_> {
66100
})
67101
}
68102

103+
fn run_create_upload_directory(runner: &mut OpenShellRunner) -> ScenarioFuture<'_> {
104+
Box::pin(async move { create_upload_directory_preserves_source_basename(runner).await })
105+
}
106+
107+
fn run_create_upload_multiple(runner: &mut OpenShellRunner) -> ScenarioFuture<'_> {
108+
Box::pin(async move { create_with_multiple_uploads(runner).await })
109+
}
110+
111+
fn run_create_upload_file(runner: &mut OpenShellRunner) -> ScenarioFuture<'_> {
112+
Box::pin(async move { create_upload_single_file(runner).await })
113+
}
114+
115+
/// A sandbox created with `--upload <dir>:<dest>` preserves the source
116+
/// directory's basename under `<dest>`.
117+
async fn create_upload_directory_preserves_source_basename(
118+
runner: &mut OpenShellRunner,
119+
) -> Result<(), String> {
120+
let local =
121+
tempfile::tempdir().map_err(fs_error("create create-upload/directory temporary dir"))?;
122+
let source = local.path().join("project");
123+
fs::create_dir_all(source.join("src")).map_err(fs_error("create project/src"))?;
124+
fs::write(source.join("marker.txt"), "upload-create-marker")
125+
.map_err(fs_error("write marker.txt"))?;
126+
fs::write(source.join("src/main.py"), "print('hello')").map_err(fs_error("write main.py"))?;
127+
128+
let sandbox_name = format!("ct-{}-cu1", runner.id());
129+
create_with_uploads(
130+
runner,
131+
"create-upload/directory",
132+
&sandbox_name,
133+
&[(&source, "/sandbox/data")],
134+
)
135+
.await?;
136+
137+
let output = exec_capture(
138+
runner,
139+
&sandbox_name,
140+
"create-upload/directory/verify",
141+
"cat /sandbox/data/project/marker.txt",
142+
)
143+
.await?;
144+
if !output.contains("upload-create-marker") {
145+
return Err(format!(
146+
"expected uploaded marker content in sandbox output:\n{output}"
147+
));
148+
}
149+
150+
delete_sandbox(runner, &sandbox_name).await
151+
}
152+
153+
/// Two `--upload` specs in a single `sandbox create` call both land in the
154+
/// sandbox before the command runs.
155+
async fn create_with_multiple_uploads(runner: &mut OpenShellRunner) -> Result<(), String> {
156+
let local = tempfile::tempdir().map_err(fs_error("create multiple-uploads temporary dir"))?;
157+
let dir_a = local.path().join("alpha");
158+
let dir_b = local.path().join("beta");
159+
fs::create_dir_all(&dir_a).map_err(fs_error("create alpha"))?;
160+
fs::create_dir_all(&dir_b).map_err(fs_error("create beta"))?;
161+
fs::write(dir_a.join("a.txt"), "content-alpha").map_err(fs_error("write a.txt"))?;
162+
fs::write(dir_b.join("b.txt"), "content-beta").map_err(fs_error("write b.txt"))?;
163+
164+
let sandbox_name = format!("ct-{}-cu2", runner.id());
165+
create_with_uploads(
166+
runner,
167+
"create-upload/multiple",
168+
&sandbox_name,
169+
&[(&dir_a, "/sandbox/alpha"), (&dir_b, "/sandbox/beta")],
170+
)
171+
.await?;
172+
173+
let output = exec_capture(
174+
runner,
175+
&sandbox_name,
176+
"create-upload/multiple/verify",
177+
"cat /sandbox/alpha/alpha/a.txt /sandbox/beta/beta/b.txt",
178+
)
179+
.await?;
180+
if !output.contains("content-alpha") || !output.contains("content-beta") {
181+
return Err(format!(
182+
"expected both uploaded contents in sandbox output:\n{output}"
183+
));
184+
}
185+
186+
delete_sandbox(runner, &sandbox_name).await
187+
}
188+
189+
/// `--upload` with a single file (not a directory) works.
190+
async fn create_upload_single_file(runner: &mut OpenShellRunner) -> Result<(), String> {
191+
let local = tempfile::tempdir().map_err(fs_error("create single-file temporary dir"))?;
192+
let file_path = local.path().join("config.txt");
193+
fs::write(&file_path, "single-file-upload-test").map_err(fs_error("write config.txt"))?;
194+
195+
let sandbox_name = format!("ct-{}-cu3", runner.id());
196+
create_with_uploads(
197+
runner,
198+
"create-upload/single-file",
199+
&sandbox_name,
200+
&[(&file_path, "/sandbox")],
201+
)
202+
.await?;
203+
204+
let output = exec_capture(
205+
runner,
206+
&sandbox_name,
207+
"create-upload/single-file/verify",
208+
"cat /sandbox/config.txt",
209+
)
210+
.await?;
211+
if !output.contains("single-file-upload-test") {
212+
return Err(format!(
213+
"expected single-file content in sandbox output:\n{output}"
214+
));
215+
}
216+
217+
delete_sandbox(runner, &sandbox_name).await
218+
}
219+
220+
/// Run `sandbox create --detach --upload <local>:<dest>... --no-git-ignore`.
221+
async fn create_with_uploads(
222+
runner: &mut OpenShellRunner,
223+
step: &str,
224+
sandbox_name: &str,
225+
uploads: &[(&Path, &str)],
226+
) -> Result<(), String> {
227+
runner.track_sandbox(sandbox_name);
228+
let mut args = vec![
229+
"sandbox".to_string(),
230+
"create".to_string(),
231+
"--name".to_string(),
232+
sandbox_name.to_string(),
233+
"--detach".to_string(),
234+
];
235+
for (local, dest) in uploads {
236+
let local = local
237+
.to_str()
238+
.ok_or_else(|| format!("local upload path is not UTF-8: {}", local.display()))?;
239+
args.push("--upload".to_string());
240+
args.push(format!("{local}:{dest}"));
241+
}
242+
args.push("--no-git-ignore".to_string());
243+
let args: Vec<&str> = args.iter().map(String::as_str).collect();
244+
245+
let result = runner
246+
.step(step)
247+
.description(format!("sandbox '{sandbox_name}' is created with uploads"))
248+
.with_timeout(CREATE_TIMEOUT)
249+
.run(&args)
250+
.await
251+
.map_err(|error| error.to_string())?;
252+
result.require_success()
253+
}
254+
255+
/// Exec a command in the sandbox and return its combined stdout+stderr.
256+
async fn exec_capture(
257+
runner: &OpenShellRunner,
258+
sandbox: &str,
259+
step: &str,
260+
script: &str,
261+
) -> Result<String, String> {
262+
let result = runner
263+
.step(step)
264+
.description(format!("sandbox '{sandbox}' exec for {step} succeeds"))
265+
.with_timeout(COMMAND_TIMEOUT)
266+
.run(&[
267+
"sandbox", "exec", "--name", sandbox, "--no-tty", "--", "sh", "-c", script,
268+
])
269+
.await
270+
.map_err(|error| error.to_string())?;
271+
result.require_success()?;
272+
Ok(format!("{}{}", result.stdout(), result.stderr()))
273+
}
274+
69275
async fn prepare_sandbox(
70276
runner: &mut OpenShellRunner,
71277
group: &str,

‎crates/openshell-conformance/src/scenarios/mod.rs‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ mod smoke;
1010
mod workspace_lifecycle;
1111

1212
pub use file_transfer::{
13-
FILE_TRANSFER_GIT_FILTERING_SCENARIO, FILE_TRANSFER_PATH_SAFETY_SCENARIO,
14-
FILE_TRANSFER_ROUND_TRIP_SCENARIO,
13+
FILE_TRANSFER_CREATE_UPLOAD_DIRECTORY_SCENARIO, FILE_TRANSFER_CREATE_UPLOAD_FILE_SCENARIO,
14+
FILE_TRANSFER_CREATE_UPLOAD_MULTIPLE_SCENARIO, FILE_TRANSFER_GIT_FILTERING_SCENARIO,
15+
FILE_TRANSFER_PATH_SAFETY_SCENARIO, FILE_TRANSFER_ROUND_TRIP_SCENARIO,
1516
};
1617
pub use policy_behavior::{
1718
MECHANISTIC_PROPOSAL_SCENARIO, NEW_HOSTNAME_PROPOSAL_SCENARIO, POLICY_LOCAL_SCENARIO,

‎e2e/rust/tests/upload_create.rs‎

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

0 commit comments

Comments
 (0)