diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 2d9efd1490..b7b5ea0ab5 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -4,7 +4,7 @@ name: Lint # is installed. Clippy lints the library and binary with every feature; tests, # examples and benches are not linted (the panic-prevention lints in Cargo.toml # would need thousands of changes there). A separate job lints the browser -# library on wasm32, including code that native builds do not compile. +# library on wasm32; wasm.yml runs the browser tests. on: push: diff --git a/.github/workflows/wasm.yml b/.github/workflows/wasm.yml new file mode 100644 index 0000000000..68f6ab79b6 --- /dev/null +++ b/.github/workflows/wasm.yml @@ -0,0 +1,68 @@ +name: WASM + +# Core's BrowserDb and IndexedDB tests only compile with the browser feature +# on wasm32, so native CI never runs them. v2 supports main-thread tests only. + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +env: + CARGO_TERM_COLOR: always + +permissions: + contents: read + +jobs: + browser: + name: Browser tests (headless ${{ matrix.browser }}) + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + # Both browsers and their WebDriver binaries are preinstalled on + # ubuntu-latest; wasm-pack finds them on PATH. + browser: [firefox, chrome] + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable + with: + targets: wasm32-unknown-unknown + - name: Install wasm-pack + run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh + - name: wasm-bindgen tests (lib, incl. BrowserDb and IndexedDB) + run: wasm-pack test --headless --${{ matrix.browser }} --features browser + + safari: + name: Safari tests (main thread) + # Real Safari through safaridriver. Safari has no headless mode; the + # hosted runner's GUI session runs it. Private windows cannot be opened + # over WebDriver, so Safari private browsing is not covered here. + runs-on: macos-15 + env: + WASM_BINDGEN_TEST_TIMEOUT: 180 + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable + with: + targets: wasm32-unknown-unknown + - name: Install wasm-pack + run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh + # The test runner's own safaridriver launch times out on hosted runners + # ("driver failed to bind port"), so start it here and point the runner + # at it with SAFARIDRIVER_REMOTE. + - name: Start safaridriver + run: | + sudo safaridriver --enable + safaridriver -p 4444 & + for _ in $(seq 1 60); do + curl -sf http://127.0.0.1:4444/status >/dev/null && exit 0 + sleep 1 + done + echo "::error::safaridriver did not start"; exit 1 + - name: wasm-bindgen tests in Safari + env: + SAFARIDRIVER_REMOTE: http://127.0.0.1:4444 + run: wasm-pack test --headless --safari --features browser diff --git a/docs/TEST_COVERAGE.md b/docs/TEST_COVERAGE.md index 2444cd14f0..8889e75aa7 100644 --- a/docs/TEST_COVERAGE.md +++ b/docs/TEST_COVERAGE.md @@ -159,6 +159,32 @@ The **26 `BrowserDb` wasm-bindgen tests** (12 existing, 14 added for #894) run only on wasm32 in a browser and are not in the native counts above. All 26 passed in headless Firefox on 2026-11-18. +`.github/workflows/wasm.yml` runs these tests on pushes and pull requests to +`main`: headless Firefox and Chrome on Ubuntu, and real Safari through +`safaridriver` on `macos-15`. All three lanes run on the main thread. v2 has no +`minigraf_browser_worker` cfg or OPFS/worker mode, so there are no worker lanes. +Safari uses the hosted runner's GUI session; private browsing is not covered. + +Run locally with Rust's `wasm32-unknown-unknown` target, `wasm-pack`, and the +chosen browser installed (with its WebDriver on `PATH` or installed by wasm-pack): + +```bash +wasm-pack test --headless --firefox --features browser +wasm-pack test --headless --chrome --features browser +# macOS: enable Safari remote automation first. +sudo safaridriver --enable +wasm-pack test --headless --safari --features browser +``` + +The Safari `--headless` flag selects wasm-bindgen's automated WebDriver runner; +Safari itself opens a visible window. CI starts `safaridriver` separately and +sets `SAFARIDRIVER_REMOTE` to avoid the hosted runner's driver startup timeout. +Native-only file and WAL tests are cfg-gated off wasm32, so the standard +wasm-pack command can compile all test targets without the native `tempfile` +dev-dependency. Native `cargo test` still runs those tests. +The PID-namespace example helper also compiles with an empty main on wasm32, +as the other native-only examples do. + - The IndexedDB flush returns every page a write dirtied. - A dirty page that cannot be read is an error rather than left out. - A parse, query and transact error reject with their codes (`PRS-011`, `QRY-007`, `PRS-046`), as on the native API (#673). @@ -189,9 +215,8 @@ cargo build python3 scripts/check_browser_exports.py target/browser-exports.log target/debug/minigraf ``` -`wasm-pack test --headless --firefox --features browser` currently also compiles -native-only integration tests that call `Minigraf::open`, unavailable on wasm. -The direct library runner above exercises the browser suite without those tests. +The direct library runner above is for opt-in recovery-export verification; +the standard browser test run uses wasm-pack as shown above. Before the production fix, the abort-only regression failed at its 1.5-second deadline (`deadline: flush did not settle`), and the multi-page regression failed diff --git a/examples/pid_ns_helper.rs b/examples/pid_ns_helper.rs index 567b3aaa73..95550023fa 100644 --- a/examples/pid_ns_helper.rs +++ b/examples/pid_ns_helper.rs @@ -34,6 +34,10 @@ //! release by the library, nothing but whatever the kernel does on its own. //! That is the exact state #317 is about. +#[cfg(target_arch = "wasm32")] +fn main() {} + +#[cfg(not(target_arch = "wasm32"))] fn main() { let args: Vec = std::env::args().collect(); let path = &args[1]; diff --git a/tests/error_codes_foundation_test.rs b/tests/error_codes_foundation_test.rs index 60aa786737..841adc0ff8 100644 --- a/tests/error_codes_foundation_test.rs +++ b/tests/error_codes_foundation_test.rs @@ -7,6 +7,7 @@ fn in_memory_open_returns_ok() { } #[test] +#[cfg(not(target_arch = "wasm32"))] fn open_nonexistent_directory_returns_coded_error() { let bad_path = "/nonexistent-dir-for-minigraf-test-277/db.graph"; let result = Minigraf::open(bad_path); diff --git a/tests/error_codes_storage_test.rs b/tests/error_codes_storage_test.rs index 9920ac06bc..6acfe7cfa2 100644 --- a/tests/error_codes_storage_test.rs +++ b/tests/error_codes_storage_test.rs @@ -9,6 +9,8 @@ //! directly — see the unit tests inside `src/storage/*.rs` for codes that //! are only reachable at that lower level). +#![cfg(not(target_arch = "wasm32"))] // Minigraf::open requires the native file backend. + use minigraf::{ErrorCategory, Minigraf}; use std::io::Write; diff --git a/tests/error_codes_wal_test.rs b/tests/error_codes_wal_test.rs index f42f95848b..ec7296520d 100644 --- a/tests/error_codes_wal_test.rs +++ b/tests/error_codes_wal_test.rs @@ -12,6 +12,8 @@ //! no way to trigger them from the public API without an unrealistic (multi-GB) //! fixture, so they are intentionally not exercised here. +#![cfg(not(target_arch = "wasm32"))] // File-backed WAL tests use native-only tempfile. + use minigraf::{ErrorCategory, Minigraf, OpenOptions}; use std::io::Write;