From 04709fad585dc9e8023b3b4042693632e4760614 Mon Sep 17 00:00:00 2001 From: Michael-F-Bryan Date: Fri, 21 Apr 2023 15:04:03 +0800 Subject: [PATCH 1/4] Make sure integration tests use an up-to-date build of the wasmer CLI --- tests/integration/cli/tests/run_unstable.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/integration/cli/tests/run_unstable.rs b/tests/integration/cli/tests/run_unstable.rs index a1da778bc23..c4b989989d5 100644 --- a/tests/integration/cli/tests/run_unstable.rs +++ b/tests/integration/cli/tests/run_unstable.rs @@ -17,8 +17,14 @@ use wasmer_integration_tests_cli::get_wasmer_path; const RUST_LOG: &str = "info,wasmer_wasi::runners=debug,virtual_fs::trace_fs=trace"; fn wasmer_run_unstable() -> std::process::Command { - let mut cmd = std::process::Command::new(get_wasmer_path()); - cmd.env("RUST_LOG", RUST_LOG).arg("run-unstable"); + let mut cmd = std::process::Command::new("cargo"); + cmd.arg("run") + .arg("--quiet") + .arg("--package=wasmer-cli") + .arg("--features=singlepass") + .arg("--") + .arg("run-unstable"); + cmd.env("RUST_LOG", RUST_LOG); cmd } From c0389f9f74838765d82c17147512d9f8b2277f9a Mon Sep 17 00:00:00 2001 From: Michael-F-Bryan Date: Fri, 21 Apr 2023 15:19:58 +0800 Subject: [PATCH 2/4] Added some regression tests --- lib/wasi/src/runners/wasi_common.rs | 61 +++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/lib/wasi/src/runners/wasi_common.rs b/lib/wasi/src/runners/wasi_common.rs index 132bdeabc2e..6fa3b3b6428 100644 --- a/lib/wasi/src/runners/wasi_common.rs +++ b/lib/wasi/src/runners/wasi_common.rs @@ -218,6 +218,67 @@ mod tests { const PYTHON: &[u8] = include_bytes!("../../../c-api/examples/assets/python-0.1.0.wasmer"); + /// Fixes + #[test] + fn mix_args_from_the_webc_and_user() { + let args = CommonWasiOptions { + args: vec!["extra".to_string(), "args".to_string()], + ..Default::default() + }; + let mut builder = WasiEnvBuilder::new("program-name"); + let fs = Arc::new(virtual_fs::EmptyFileSystem::default()); + let mut annotations = WasiAnnotation::new("some-atom"); + annotations.main_args = Some(vec![ + "hard".to_string(), + "coded".to_string(), + "args".to_string(), + ]); + + args.prepare_webc_env(&mut builder, fs, &annotations) + .unwrap(); + + assert_eq!( + builder.get_args(), + [ + // the program name from + "program-name", + // from the WEBC's annotations + "hard", + "coded", + "args", + // from the user + "extra", + "args", + ] + ); + } + + /// Fixes + #[test] + fn mix_env_vars_from_the_webc_and_user() { + let args = CommonWasiOptions { + env: vec![("EXTRA".to_string(), "envs".to_string())] + .into_iter() + .collect(), + ..Default::default() + }; + let mut builder = WasiEnvBuilder::new("python"); + let fs = Arc::new(virtual_fs::EmptyFileSystem::default()); + let mut annotations = WasiAnnotation::new("python"); + annotations.env = Some(vec!["HARD_CODED=env-vars".to_string()]); + + args.prepare_webc_env(&mut builder, fs, &annotations) + .unwrap(); + + assert_eq!( + builder.get_env(), + [ + ("HARD_CODED".to_string(), b"env-vars".to_vec()), + ("EXTRA".to_string(), b"envs".to_vec()), + ] + ); + } + #[test] fn python_use_case() { let temp = TempDir::new().unwrap(); From 0c46265c0d38595ce799d3ad4f785811a03edeca Mon Sep 17 00:00:00 2001 From: Michael-F-Bryan Date: Fri, 21 Apr 2023 15:20:03 +0800 Subject: [PATCH 3/4] Fixed the bug --- lib/wasi/src/runners/wasi_common.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/wasi/src/runners/wasi_common.rs b/lib/wasi/src/runners/wasi_common.rs index 6fa3b3b6428..c2ac67ba240 100644 --- a/lib/wasi/src/runners/wasi_common.rs +++ b/lib/wasi/src/runners/wasi_common.rs @@ -25,8 +25,6 @@ impl CommonWasiOptions { container_fs: Arc, wasi: &WasiAnnotation, ) -> Result<(), anyhow::Error> { - builder.add_args(&self.args); - let fs = prepare_filesystem(&self.mapped_dirs, container_fs, |path| { builder.add_preopen_dir(path).map_err(Error::from) })?; From fa69ad434b357b4cc7c9f1092f85eeb8a41fa401 Mon Sep 17 00:00:00 2001 From: Michael-F-Bryan Date: Fri, 21 Apr 2023 15:23:41 +0800 Subject: [PATCH 4/4] Removed an accidental copy/paste comment --- lib/wasi/src/runners/wasi_common.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/wasi/src/runners/wasi_common.rs b/lib/wasi/src/runners/wasi_common.rs index c2ac67ba240..c41696f233e 100644 --- a/lib/wasi/src/runners/wasi_common.rs +++ b/lib/wasi/src/runners/wasi_common.rs @@ -251,7 +251,6 @@ mod tests { ); } - /// Fixes #[test] fn mix_env_vars_from_the_webc_and_user() { let args = CommonWasiOptions {