Skip to content

Commit 398dfe3

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 <[email protected]>
1 parent b3b16f0 commit 398dfe3

5 files changed

Lines changed: 194 additions & 122 deletions

File tree

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@ 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, FILE_TRANSFER_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_SCENARIO, FILE_TRANSFER_GIT_FILTERING_SCENARIO,
28+
FILE_TRANSFER_PATH_SAFETY_SCENARIO, FILE_TRANSFER_ROUND_TRIP_SCENARIO, FILE_TRANSFER_SCENARIO,
29+
MECHANISTIC_PROPOSAL_SCENARIO, NEW_HOSTNAME_PROPOSAL_SCENARIO, POLICY_LOCAL_SCENARIO,
30+
SANDBOX_LIFECYCLE_SCENARIO, SMOKE_SCENARIO, WORKSPACE_LIFECYCLE_SCENARIO,
31+
WORKSPACE_TERMINATING_SCENARIO,
3132
};
3233

3334
/// An installed conformance scenario.

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

Lines changed: 178 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,20 @@ pub const FILE_TRANSFER_PATH_SAFETY_SCENARIO: Scenario = Scenario {
4545
run: run_path_safety,
4646
};
4747

48+
/// Certify that `sandbox create --upload` pre-loads files before the
49+
/// sandbox's command runs.
50+
pub const FILE_TRANSFER_CREATE_UPLOAD_SCENARIO: Scenario = Scenario {
51+
name: "file-transfer/create-upload",
52+
description: "Verify `sandbox create --upload` pre-loads files before the command runs.",
53+
run: run_create_upload,
54+
};
55+
4856
fn run_file_transfer(runner: &mut OpenShellRunner) -> ScenarioFuture<'_> {
4957
Box::pin(async move {
5058
FILE_TRANSFER_ROUND_TRIP_SCENARIO.run(runner).await?;
5159
FILE_TRANSFER_GIT_FILTERING_SCENARIO.run(runner).await?;
52-
FILE_TRANSFER_PATH_SAFETY_SCENARIO.run(runner).await
60+
FILE_TRANSFER_PATH_SAFETY_SCENARIO.run(runner).await?;
61+
FILE_TRANSFER_CREATE_UPLOAD_SCENARIO.run(runner).await
5362
})
5463
}
5564

@@ -83,6 +92,174 @@ fn run_path_safety(runner: &mut OpenShellRunner) -> ScenarioFuture<'_> {
8392
})
8493
}
8594

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

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ 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, FILE_TRANSFER_SCENARIO,
13+
FILE_TRANSFER_CREATE_UPLOAD_SCENARIO, FILE_TRANSFER_GIT_FILTERING_SCENARIO,
14+
FILE_TRANSFER_PATH_SAFETY_SCENARIO, FILE_TRANSFER_ROUND_TRIP_SCENARIO, FILE_TRANSFER_SCENARIO,
1515
};
1616
pub use policy_behavior::{
1717
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.

‎tests/suites/conformance/cli/tests/file_transfer.rs‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
//! Driver-agnostic sandbox file-transfer conformance tests.
55
66
use openshell_conformance::{
7-
FILE_TRANSFER_GIT_FILTERING_SCENARIO, FILE_TRANSFER_PATH_SAFETY_SCENARIO,
8-
FILE_TRANSFER_ROUND_TRIP_SCENARIO, OpenShellRunner, Scenario,
7+
FILE_TRANSFER_CREATE_UPLOAD_SCENARIO, FILE_TRANSFER_GIT_FILTERING_SCENARIO,
8+
FILE_TRANSFER_PATH_SAFETY_SCENARIO, FILE_TRANSFER_ROUND_TRIP_SCENARIO, OpenShellRunner,
9+
Scenario,
910
};
1011

1112
/// Exercise file and directory round trips through the candidate CLI.
@@ -26,6 +27,12 @@ async fn path_safety() {
2627
run(FILE_TRANSFER_PATH_SAFETY_SCENARIO).await;
2728
}
2829

30+
/// Exercise `sandbox create --upload` pre-loading through the candidate CLI.
31+
#[tokio::test]
32+
async fn create_upload() {
33+
run(FILE_TRANSFER_CREATE_UPLOAD_SCENARIO).await;
34+
}
35+
2936
async fn run(scenario: Scenario) {
3037
let mut runner = OpenShellRunner::from_env(scenario.name)
3138
.expect("candidate openshell CLI is available");

0 commit comments

Comments
 (0)