Skip to content

test(wasm): run the engine's Rust tests inside the crate#1277

Merged
Goldziher merged 3 commits into
mainfrom
test/wasm-engine-crate-tests
Jul 20, 2026
Merged

test(wasm): run the engine's Rust tests inside the crate#1277
Goldziher merged 3 commits into
mainfrom
test/wasm-engine-crate-tests

Conversation

@tobocop2

@tobocop2 tobocop2 commented Jul 19, 2026

Copy link
Copy Markdown
Member

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 inside xberg-wasm covering the Rust side of the bridge contract: constructor validation, OCR/NER dispatch through injected JS stubs, wire-shape deserialization (line geometry, missing lines/bbox degradation, 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.toml declares wasm-bindgen-test under [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 a cdylib, which tests/ integration tests cannot link against.

Runner

scripts/ci/wasm/run-crate-tests.sh runs 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 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. test-shims/ supplies those modules via NODE_PATH with the same stub semantics. Nothing in the tests needs a DOM.

@tobocop2
tobocop2 requested a review from Goldziher as a code owner July 19, 2026 18:27

@tobocop2 tobocop2 Jul 19, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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.

tobocop2 added 3 commits July 19, 2026 22:19
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
tobocop2 force-pushed the test/wasm-engine-crate-tests branch from 464bd32 to df00b1a Compare July 20, 2026 02:20
@Goldziher
Goldziher merged commit 6c2aff0 into main Jul 20, 2026
5 of 10 checks passed
@Goldziher
Goldziher deleted the test/wasm-engine-crate-tests branch July 20, 2026 04:30
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.

test: run the wasm engine's Rust tests in the crate once alef supports test-only dependencies

2 participants