Skip to content

wasi: fix os.environb byte handling - #8476

Merged
youknowone merged 1 commit into
RustPython:mainfrom
jiwahn:wasm-enable-test-module
Aug 9, 2026
Merged

wasi: fix os.environb byte handling#8476
youknowone merged 1 commit into
RustPython:mainfrom
jiwahn:wasm-enable-test-module

Conversation

@jiwahn

@jiwahn jiwahn commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Part of: #4583

Summary

RustPython WASIp1 did not preserve raw bytes in os.environb, causing python -m test to fail during setup.

This will enable -m test for wasi preview 1

Below is the example of running test_support on wasmer

╰─$ wasmer run \                                                                                                                                                                          
  --volume "$(pwd):$(pwd)" \
  --volume "/tmp:/tmp" \
  target/wasm32-wasip1/wasm-release/rustpython.wasm \
  -- -m test test_support
Using random seed: 1848393816
0:00:00 Run 1 test sequentially in a single process
0:00:00 [1/1] test_support
test test_support crashed -- Traceback (most recent call last):
  File "test.libregrtest.single", line 210, in _runtest_env_changed_exc
  File "test.libregrtest.single", line 155, in _load_run_test
  File "importlib", line 88, in import_module
  File "_frozen_importlib", line 1406, in _gcd_import
  File "_frozen_importlib", line 1371, in _find_and_load
  File "_frozen_importlib", line 1342, in _find_and_load_unlocked
  File "_frozen_importlib", line 938, in _load_unlocked
  File "_frozen_importlib", line 1179, in exec_module
  File "test.test_support", line 9, in <module>
  File "socket", line 52, in <module>
ModuleNotFoundError: No module named '_socket'

0:00:00 [1/1/1] test_support failed (uncaught exception)

== Tests result: FAILURE ==

1 test failed:
    test_support

Total duration: 75 ms
Total tests: run=0
Total test files: run=1/1 failed=1
Result: FAILURE

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of operating-system strings on WASI Preview 1.
    • Preserved UTF-8 conversion behavior for WASI Preview 2 and other supported targets.

Part of: RustPython#4583

This will enable -m test for wasi preview 1

Signed-off-by: Jiwoo Ahn <ikwydls1314@gmail.com>
@coderabbitai

coderabbitai Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro Plus

Run ID: 8b1d7b52-20b0-45cf-9286-8b2b25bd078e

📥 Commits

Reviewing files that changed from the base of the PR and between 557bec1 and 80d8221.

📒 Files selected for processing (1)
  • crates/host_env/src/os.rs

📝 Walkthrough

Walkthrough

bytes_as_os_str now preserves arbitrary bytes on Unix and WASI Preview 1. Other targets, including WASI Preview 2, continue to use UTF-8 conversion.

Changes

OS string conversion

Layer / File(s) Summary
Target-specific conversion
crates/host_env/src/os.rs
The byte-preserving bytes_as_os_str implementation now covers Unix and WASI Preview 1. Other targets use the UTF-8 fallback.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Suggested reviewers: joshuamegnauth54, youknowone

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: fixing byte handling for os.environb on WASI.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@youknowone youknowone added the z-ca-2026 Tag to track Contribution Academy 2026 label Aug 9, 2026
@jiwahn

jiwahn commented Aug 9, 2026

Copy link
Copy Markdown
Contributor Author

Now that test module is enable, I have ran the 466 test files in the Lib/test. I wanted to briefly share the results here. Looks like we have quite a bit to work on now 🦦

Result Files
PASS 132
Entire file skipped for the platform 98
Python-level failure 121
WASM unreachable trap 109
No tests / resource denied 5
Environment changed 1
Host timeout 0
Total 466

@youknowone youknowone 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.

👍 Thank you so much for catching this

@youknowone
youknowone merged commit 689c8b5 into RustPython:main Aug 9, 2026
27 checks passed
kyokuping pushed a commit to kyokuping/RustPython that referenced this pull request Aug 9, 2026
Part of: RustPython#4583

This will enable -m test for wasi preview 1

Signed-off-by: Jiwoo Ahn <ikwydls1314@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

z-ca-2026 Tag to track Contribution Academy 2026

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants