Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🔨 Populate the guest cli args #393

Merged
merged 5 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions cli/tests/integration/args.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use crate::common::{Test, TestResult};
use hyper::{body::to_bytes, StatusCode};
/// Run a program that tests its args. This checks that we're populating the argument list with the
/// singleton "compute-app" value.
/// Check that an empty response is sent downstream by default.
///
/// `args.wasm` is a guest program checks its cli args.
#[tokio::test(flavor = "multi_thread")]
async fn empty_ok_response_by_default_after_args() -> TestResult {
let resp = Test::using_fixture("args.wasm").against_empty().await?;

assert_eq!(resp.status(), StatusCode::OK);
assert!(to_bytes(resp.into_body())
.await
.expect("can read body")
.to_vec()
.is_empty());

Ok(())
}
1 change: 1 addition & 0 deletions cli/tests/integration/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
mod args;
mod async_io;
mod body;
mod client_certs;
Expand Down
6 changes: 4 additions & 2 deletions lib/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -511,8 +511,10 @@ impl ExecuteCtx {
// due to wasmtime limitations, in particular the fact that `Instance` is not `Send`.
// However, the fact that the module itself is created within `ExecuteCtx::new`
// means that the heavy lifting happens only once.
let mut store = create_store(&self, session, profiler, |_| {})
.map_err(ExecutionError::Context)?;
let mut store = create_store(&self, session, profiler, |ctx| {
ctx.arg("compute-app");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you also want to add this for the ComponentCtx::create_store case as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added this for components and enabled testing for it, but the adapter will need some changes to get the test passing. I'll put that on my TODO list for component parity, but don't think the adapter changes should block this PR.

})
.map_err(ExecutionError::Context)?;

let instance = instance_pre
.instantiate_async(&mut store)
Expand Down
6 changes: 6 additions & 0 deletions test-fixtures/src/bin/args.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
fn main() {
let args = Vec::from_iter(std::env::args());

assert_eq!(args.len(), 1);
assert_eq!(args[0], "compute-app");
}
Loading