Skip to content

Test real non-JS WASM execution - #9816

Merged
youknowone merged 4 commits into
RustPython:mainfrom
youknowdot:test/non-js-wasm-runner-20261112
Nov 13, 2026
Merged

youknowone merged 4 commits into
RustPython:mainfrom
youknowdot:test/non-js-wasm-runner-20261112

Conversation

@youknowdot

@youknowdot youknowdot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Turn the non-JS wasm32-unknown-unknown example into a real execution test that fails when the guest fails.

  • Source ABI: the host copies -c CODE or a UTF-8 file into a buffer obtained from the guest's alloc_source; eval(ptr, len) takes ownership of that buffer, runs it, and reports the repr of the last expression or the Python exception through env.print.
  • Host-lent storage: the guest exposes a native kv module (kv.get(key) -> bytes | None, kv.put(key, value)) backed by the env.kv_get / env.kv_put host imports and an in-memory map owned by the host. kv_get returns -1 for a missing key or the full value length, copying only when the value fits so the guest can retry with a larger buffer. This wires up the kv_get/kv_put scaffold that was previously declared but never called.
  • Host CLI: wasm-runtime MODULE.wasm (-c CODE | FILE.py). Guest output goes to stdout. Exit status is 0 on success, 1 for a Python exception, 2 for invalid input or a host/runtime error (trap, missing export, bad arguments).
  • Import allowlist: the host rejects any import other than env.print, env.kv_get, env.kv_put before instantiation. This replaces the CI wasm-objdump check, which never failed the job; the wabt setup is removed.
  • No-OS guest: no stdlib, no JS, WASI, filesystem, clock or entropy. The hash seed is fixed to 0 and the custom getrandom backend reports unsupported instead of returning Ok without writing bytes.
  • Wasmer is bumped to 7.5.

Tests

test_runtime.py (run with host CPython in the existing WASM CI job) checks against the real guest: supplied source and no-OS identity (sys.platform, 32-bit maxsize, no posix/nt/js), file source, empty source, host storage round trip (missing key, overwrite, 16 KiB value through the retry path), Python exceptions (assertion, syntax error, failing __repr__), non-UTF-8 source, missing source, an unexpected import, and a guest trap.

Verification

Guest and host build, Clippy -D warnings, rustfmt, ruff, and all 9 contract tests pass locally.

AI assistance: initial implementation with OpenAI Codex; simplification and host storage with Grok (grok-4.7) and Claude (claude-opus-5-5).

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Caution

Review failed

The pull request is closed.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

youknowdot and others added 4 commits November 13, 2026 15:58
Pass source through a guest-owned allocation ABI, preserve the no-OS VM, and report explicit JSON results and process failures. Enforce bounded input, host deadlines, and an import allowlist. Exercise the execution and failure contract in the existing WASM CI job.

Assisted-by: Codex:unknown
Upgrade the native host to Wasmer 7.5 and cover valid, out-of-bounds and unaligned atomic operations. Preserve the no-OS guest import contract and existing CI resources.

Assisted-by: Codex:unknown
Let eval take ownership of the alloc_source buffer and drop free_source.
The host now prints guest output to stdout and exits 0/1/2 instead of
emitting JSON; remove the timeout watchdog, source size limit and the
serde_json dependency. Reduce the contract tests to guest execution,
Python errors, invalid input, the import allowlist and a trap, dropping
the host-protocol and Wasmer atomic-bounds fixtures.

Assisted-by: Grok:grok-4.7
Assisted-by: Claude:claude-opus-5-5
Add env.kv_get and env.kv_put host imports backed by an in-memory map,
and expose them to Python as a native kv module (kv.get / kv.put).
kv_get returns -1 for a missing key or the full value length, copying
the value only when it fits so the guest can retry with a larger buffer.
The host allows exactly these three imports.

Assisted-by: Grok:grok-4.7
Assisted-by: Claude:claude-opus-5-5
@youknowdot
youknowdot force-pushed the test/non-js-wasm-runner-20261112 branch from c180129 to d8b5490 Compare November 13, 2026 06:58
@youknowone
youknowone marked this pull request as ready for review November 13, 2026 08:15
@youknowone
youknowone merged commit af5ed15 into RustPython:main Nov 13, 2026
27 checks passed
@chatgpt-codex-connector

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-13T08:15:59.908711Z
We couldn’t complete this review. Comment @codex review to try again.
d8b5490 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants