test(wasm): run the engine's Rust tests inside the crate#1277
Merged
Conversation
tobocop2
commented
Jul 19, 2026
Member
Author
There was a problem hiding this comment.
alef generate is normally run outside of feature PRs, but the tests in this PR can't compile without the committed [dev-dependencies] section, so this is a worthy exception.
The XbergEngine bridge surface was only tested from JavaScript, against the built npm package. This adds #[wasm_bindgen_test] suites inside xberg-wasm covering the Rust side of the contract: constructor validation, OCR/NER dispatch through injected JS backends, wire-shape deserialization (line geometry, entity fields, category wire names), degraded shapes, this-binding preservation, and the bridge timeout. The generated manifest carries wasm-bindgen-test as a dev-dependency via alef's extra_dev_dependencies, declared in alef.toml; only the wasm manifest is regenerated here, since the rest of the tree already matches the pinned alef version. The suites live in the hand-written src/engine.rs module because the generated manifest builds only a cdylib, which tests/ integration tests cannot link. They run under Node via scripts/ci/wasm/run-crate-tests.sh: the test glue carries the same unresolvable env / wasi_snapshot_preview1 imports that fix-wasi-imports.mjs patches out of the published package, and the test runner has no post-build hook, so test-shims/ supplies those modules at require time through NODE_PATH. The wasm e2e job runs the script after the vitest suites, which keep covering the JS side. The suites derive from the wasm-bindgen tests contributed in #1253, ported to the merged engine surface. Closes #1269
The e2e job exports RUSTFLAGS for the native builds (onnxruntime -L paths, -Wl,-rpath,$ORIGIN), and the env var overrides the [target.wasm32-unknown-unknown] rustflags in .cargo/config.toml entirely: rust-lld rejects the rpath argument and the wasm-required flags (getrandom_backend, bulk-memory, --allow-multiple-definition) are dropped. Unset it in run-crate-tests.sh so the config-file flags govern, matching the local environment where the suites pass. Verified by reproducing the CI env locally: the script fails before and passes after.
The wasm leg now runs scripts/ci/wasm/run-crate-tests.sh, but the workflow's paths filters did not cover scripts/, so a change to the runner script alone triggered no run and went untested. Add scripts/ci/wasm/** to both triggers, matching ci-rust.yaml's existing scripts/ci/rust/** entry.
tobocop2
force-pushed
the
test/wasm-engine-crate-tests
branch
from
July 20, 2026 02:20
464bd32 to
df00b1a
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.
Closes #1269. Follows up on #1259, which shipped the engine's OCR/NER bridge with JS-side coverage only. The in-crate suites derive from @jamon8888's work in #1253; xberg-io/alef#182 (alef 0.37) removed the blocker that kept them out.
What this adds
Fifteen
#[wasm_bindgen_test]suites insidexberg-wasmcovering the Rust side of the bridge contract: constructor validation, OCR/NER dispatch through injected JS stubs, wire-shape deserialization (line geometry, missinglines/bboxdegradation, entity fields, category wire names), language-option forwarding,this-binding preservation, and the bridge timeout on a hung backend. These paths need stub, broken, or hung backends, which the vitest e2e suites (which test the JS side against the built npm package) cannot express.Manifest
The alef pin moves to 0.37.2 and
alef.tomldeclareswasm-bindgen-testunder[crates.wasm.extra_dev_dependencies], so the generated manifest carries the harness as a dev-dependency — never in the published package's dependency graph. Only the wasm manifest section is regenerated; broader 0.37 drift is left for a dedicated regen pass.Test placement
The suites live as a unit-test module in the hand-written
src/engine.rs(custom_rust_modules), because the generated manifest builds only acdylib, whichtests/integration tests cannot link against.Runner
scripts/ci/wasm/run-crate-tests.shruns the suites under Node (wasm-pack test --node), wired into the wasm e2e job. Node instead of a browser: the test glue carries the same unresolvableenv/wasi_snapshot_preview1imports thatfix-wasi-imports.mjspatches out of the published package, and the test runner has no post-build hook.test-shims/supplies those modules viaNODE_PATHwith the same stub semantics. Nothing in the tests needs a DOM.