8000 feat(browser): add BrowserDb async WASM façade with IndexedDB persistence by adityamukho · Pull Request #149 · project-minigraf/minigraf · GitHub
[go: up one dir, main page]

Skip to content

feat(browser): add BrowserDb async WASM façade with IndexedDB persistence - #149

Merged
adityamukho merged 20 commits into
mainfrom
feature/phase-8-1a-browser-wasm
Apr 17, 2026
Merged

adityamukho merged 20 commits into
mainfrom
feature/phase-8-1a-browser-wasm

Conversation

@adityamukho
Copy link
Copy Markdown
Collaborator

Closes #129

Summary

  • Adds a browser cargo feature compiling Minigraf for wasm32-unknown-unknown with a new BrowserDb async façade exposed via wasm-bindgen
  • Persistence via two-layer design: BrowserBufferBackend (sync HashMap-backed StorageBackend) absorbs PersistentFactStorage::save() writes; IndexedDbBackend flushes dirty pages to IndexedDB in a single batched readwrite transaction per execute() call
  • Public JS API: BrowserDb.open(dbName), BrowserDb.openInMemory(), execute(datalog), checkpoint(), exportGraph(), importGraph(bytes) — all returning Promises
  • Export/import produces byte-for-bit compatible .graph blobs (MGRF magic, ascending page order); round-trip verified by integration test
  • wasm-bindgen-test integration tests run in headless Chrome and Firefox via new .github/workflows/wasm-browser.yml CI matrix
  • All existing 792 native tests continue to pass; no public API changes; file format unchanged

Test plan

  • cargo test — all 792 native tests pass
  • cargo check --target wasm32-unknown-unknown --features browser — clean
  • cargo clippy and cargo clippy --target wasm32-unknown-unknown --features browser — clean
  • cargo fmt --check — clean
  • CI wasm-browser workflow passes on Chrome and Firefox headless

🤖 Generated with Claude Code

adityamukho and others added 18 commits April 17, 2026 12:36
Synchronous in-memory StorageBackend implementation for WASM browser
environments. Tracks written page IDs in a dirty set for subsequent
flush to IndexedDB via take_dirty(). Includes load_pages/load_pages_all_dirty
constructors and 10 passing unit tests.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds IndexedDbBackend with async open() and load_all_pages() backed by
browser IndexedDB, plus the cfg-gates needed to make the whole crate
compile cleanly under wasm32-unknown-unknown --features browser.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…tructors

Replaces the stub src/browser/mod.rs with BrowserDbInner/BrowserDb,
open_in_memory() (pure buffer, no IDB), and open() (loads all pages
from IndexedDB then wraps in PersistentFactStorage). Imports for
DatalogExecutor and QueryResult are included ahead of Task 8.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Implements the core execute() async method on BrowserDb, dispatching
Datalog commands to query/rule (read) or transact/retract (write) paths,
with dirty-page flushing to IndexedDB after writes. Also adds
read_page_raw() on BrowserBufferBackend and with_backend/with_backend_mut
closure accessors on PersistentFactStorage to safely access the inner
Arc<Mutex<B>> without exposing raw lock guards.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Add 5 wasm-bindgen-test integration tests in src/browser/mod.rs covering
  transact/query, empty query, export-import round-trip, page-alignment, and
  IndexedDB persistence across open/close cycles
- Add wasm-bindgen-test = "0.3" as a wasm32-only dev-dependency; move
  criterion and tempfile to not(wasm32) dev-dependencies to prevent
  rayon/tempfile link errors when building for WASM
- Gate file-backed test modules with #[cfg(all(test, not(target_arch = "wasm32")))]
  in persistent_facts.rs, wal.rs, db.rs, and backend/file.rs
- Gate 5 file-backed integration test files with #![cfg(not(target_arch = "wasm32"))]
- Fix tx_id_now() to use js_sys::Date::now() on wasm32+browser targets
  (std::time::SystemTime::now() panics in the browser WASM runtime)
- Fix apply_write() missing pfs.mark_dirty() call before pfs.save(),
  which caused export_graph() to return empty/unheadered blobs and
  IDB persistence to silently drop written facts
- Fix memory_profile.rs example and Minigraf doc example to compile on wasm32

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@codecov
codecov Bot commented Apr 17, 2026 •
Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 28.57143% with 15 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.41%. Comparing base (07b3e9a) to head (0f1a10a).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/main.rs 0.00% 11 Missing ⚠️
src/storage/persistent_facts.rs 0.00% 4 Missing ⚠️

❌ Your patch status has failed because the patch coverage (28.57%) is below the target coverage (75.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #149   +/-   ##
=======================================
  Coverage   83.41%   83.41%           
=======================================
  Files          26       26           
  Lines        4811     4837   +26     
=======================================
+ Hits         4013     4035   +22     
- Misses        798      802    +4     
Files with missing lines Coverage Δ
src/db.rs 90.03% <100.00%> (ø)
src/graph/types.rs 75.60% <100.00%> (ø)
src/storage/backend/file.rs 88.57% <ø> (ø)
src/wal.rs 88.79% <ø> (+0.40%) ⬆️
src/storage/persistent_facts.rs 75.69% <0.00%> (+0.24%) ⬆️
src/main.rs 0.00% <0.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

adityamukho and others added 2 commits April 18, 2026 00:03
wasm-pack's bundled wasm-opt does not honour the package.metadata
wasm-opt flags, causing bulk-memory validation failure. Disable the
bundled wasm-opt (wasm-opt = false) and instead install binaryen via
apt in CI, then invoke wasm-opt manually with --enable-bulk-memory.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…imised

The standalone binaryen 108 (Ubuntu Noble) rejects the WASM binary
because it uses multiple non-MVP features (bulk-memory, mutable-globals,
sign-ext, etc.) that all need individual --enable-* flags.
Rather than enumerate every feature, skip post-build wasm-opt in CI;
the build already succeeds with wasm-opt = false in Cargo.toml metadata,
producing a correct if unoptimised binary. The size check is informational
only. Correctness is validated by the headless browser test job.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@adityamukho
adityamukho merged commit cab350f into main Apr 17, 2026
24 of 25 checks passed
@adityamukho
adityamukho deleted the feature/phase-8-1a-browser-wasm branch April 17, 2026 18:49
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.

Phase 8.1a: Browser WASM support (wasm32-unknown-unknown + wasm-bindgen)

1 participant

0