Skip to content

Implement WASI initial cwd configuration#13468

Merged
alexcrichton merged 2 commits into
bytecodealliance:mainfrom
angelnereira:wasi-initial-cwd
May 25, 2026
Merged

Implement WASI initial cwd configuration#13468
alexcrichton merged 2 commits into
bytecodealliance:mainfrom
angelnereira:wasi-initial-cwd

Conversation

@angelnereira

Copy link
Copy Markdown
Contributor

This implements the missing configuration path for wasi:cli/environment.initial-cwd discussed in #9695.

Summary:

  • add WasiCtxBuilder::initial_cwd to configure the value reported by wasi:cli/environment.initial-cwd
  • add -Scwd= and wire it into the CLI's WASIp2 context setup
  • add an end-to-end CLI test component that verifies the guest observes the configured cwd

Tests:

  • cargo fmt --all -- --check
  • cargo test -p wasmtime-cli-flags from_toml
  • cargo test -p wasmtime-wasi --lib initial_cwd
  • cargo test -p test-programs --target=wasm32-wasip1 --no-run --bin p2_cli_initial_cwd
  • cargo test -p wasmtime-cli --test all p2_cli_initial_cwd
  • cargo check -p wasmtime-cli
  • cargo clippy -p wasmtime-cli-flags -p wasmtime-wasi --lib

@angelnereira
angelnereira requested review from a team as code owners May 24, 2026 03:48
@angelnereira
angelnereira requested review from pchickey and removed request for a team May 24, 2026 03:48
@github-actions github-actions Bot added the wasi Issues pertaining to WASI label May 24, 2026

@alexcrichton alexcrichton left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!

Comment thread crates/cli-flags/src/lib.rs Outdated
Comment on lines +1384 to +1386
let mut common_options = CommonOptions::try_parse_from(["test", "-Scwd=/sandbox"]).unwrap();
common_options.configure().unwrap();
assert_eq!(common_options.wasi.cwd.as_deref(), Some("/sandbox"));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

For this it's best to skip the test here and rely on testing in cli_tests.rs instead. Given that, can you remove this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Makes sense, thanks for the guidance. I’ll remove these low-level checks and keep the coverage at the CLI/end-to-end level.

Comment thread crates/wasi/src/ctx.rs Outdated
let ctx = WasiCtxBuilder::new().initial_cwd("/sandbox").build();
assert_eq!(ctx.cli.initial_cwd.as_deref(), Some("/sandbox"));
}
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

There's no need to add these tests, we don't typically test at this micro-level of granularity. The end-to-end tests are fine. (it becomes extremely onerous to refactor if tests are there for every possible behavior and implementation detail of a function)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

thanks. I’ll remove these micro-level tests and keep the behavior covered at the end-to-end level.

@alexcrichton
alexcrichton added this pull request to the merge queue May 25, 2026
Merged via the queue into bytecodealliance:main with commit 78676bc May 25, 2026
51 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

wasi Issues pertaining to WASI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants