Repository navigation
wasi: fix working directories and test filesystem access - #5874
Draft
jakebailey wants to merge 3 commits into
Draft
jakebailey wants to merge 3 commits into
jakebailey wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
WASIp1 transfers an incompatible allocation to libc ownership, and Windows host paths are not mapped to valid WASI guest paths.
2 open findings
What changed in this PR
Fixes WASI working-directory initialization and filesystem access for tests.
Changes:
- Initializes WASIp1/WASIp2 working directories from PWD and preopens.
- Revises Wasmtime filesystem mounts and test working directories.
- Adds WASI filesystem and preopen coverage.
| File | Description |
|---|---|
tests/testing/pass/pass_wasm_test.go |
Tests WASIp1 startup directory access. |
testdata/wasip2_cwd.go |
Adds WASIp2 CWD scenarios. |
testdata/filesystem.go |
Tests relative access after Chdir. |
testdata/env.go |
Tests PWD and relative access. |
targets/wasm-unknown.json |
Removes default temporary mount. |
targets/wasip2.json |
Removes default temporary mount. |
targets/wasip1.json |
Links CWD support and removes default mount. |
src/syscall/libc_wasip2.go |
Resolves nested and normalized CWDs. |
src/syscall/file_hosted.go |
Narrows hosted Getwd targets. |
src/syscall/cwd_wasip1.go |
Implements WASIp1 CWD initialization. |
main.go |
Configures Wasmtime mounts and PWD. |
main_test.go |
Adds runner and CWD integration tests. |
compileopts/target_test.go |
Tests emulator template expansion. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| } | ||
|
|
||
| emuArgs = append(emuArgs, "--dir="+wd) | ||
| emuArgs = append(emuArgs, "--env=PWD="+wd) |
Comment on lines
+32
to
+33
| initialWorkingDirBuffer = cstring(cwd) | ||
| libcCwd = unsafe.SliceData(initialWorkingDirBuffer) |
Member
Author
There was a problem hiding this comment.
I don't think this is true?
jakebailey
marked this pull request as draft
October 13, 2026 17:16
Go initializes the WASI working directory from PWD or the first preopen. TinyGo leaves wasi-libc at its virtual root, so filesystem calls can resolve relative paths against a different directory than callers expect. Use the same initial directory without changing filesystem permissions.
A working directory can be inside a preopened directory without matching its root. Requiring an exact match leaves relative file access rooted at the wrong directory, including when a WASI host exposes only its root.
jakebailey
force-pushed
the
wasi-test-root
branch
from
October 13, 2026 19:42
ae722f7 to
2adf008
Compare
Upstream Go runs WASI tests with the host root preopened. Restricting TinyGo tests to package directories and temporary files makes portable filesystem tests fail even when the runtime supports their operations. Match upstream test access without changing normal program execution. Tests have host-root filesystem access and must be trusted.
jakebailey
force-pushed
the
wasi-test-root
branch
from
October 13, 2026 21:20
2adf008 to
776d292
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

The WASI working directory handling wasn't quite right. WASIp1 wasn't using PWD or the first preopen like upstream Go, and WASIp2 only worked when the working directory exactly matched a preopen.
Fix those, then let the test runner mount the host root like upstream Go's does. The old directory mounts got in the way of stdlib filesystem tests. Tests also need the physical package directory rather than a path through the synthetic GOROOT.
This will enable more stdlib tests, though they can't get enabled in this PR quite yet. There are new tests for some stuff, anyway.
This also does mean that a tinygo test can access more files, but... upstream
go testis the same, so I don't really think it matters?