From 4993bb4b80bccc4ecc3f6c370526c7fda1f819fe Mon Sep 17 00:00:00 2001 From: Aditya Mukhopadhyay Date: Sat, 18 Apr 2026 10:07:57 +0530 Subject: [PATCH 1/9] fix(deps): restrict uuid js feature and wasm-bindgen-test to browser wasm only wasm32-wasip1 (WASI) has no JavaScript engine. The previous cfg gate 'target_arch = wasm32' applied to WASI too, pulling in wasm-bindgen and getrandom's JS path. Narrowed to 'all(target_arch = wasm32, not(target_os = wasi))'. Co-Authored-By: Claude Sonnet 4.6 --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2260c52ca1..1fc47f73c7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,7 +31,7 @@ uuid = { version = "1.0", features = ["v4", "v5", "serde"] } regex-lite = "0.1.9" serde_json = { version = "1.0", optional = true } -[target.'cfg(target_arch = "wasm32")'.dependencies] +[target.'cfg(all(target_arch = "wasm32", not(target_os = "wasi")))'.dependencies] uuid = { version = "1.0", features = ["v4", "v5", "serde", "js"] } wasm-bindgen = { version = "0.2", optional = true } wasm-bindgen-futures = { version = "0.4", optional = true } @@ -57,7 +57,7 @@ serde_json = "1.0" tempfile = "3" criterion = { version = "0.8", features = ["html_reports"] } -[target.'cfg(target_arch = "wasm32")'.dev-dependencies] +[target.'cfg(all(target_arch = "wasm32", not(target_os = "wasi")))'.dev-dependencies] wasm-bindgen-test = "0.3" [[bench]] From 2902ae702b90545936ce71da4fce977121dda0f3 Mon Sep 17 00:00:00 2001 From: Aditya Mukhopadhyay Date: Sat, 18 Apr 2026 10:14:00 +0530 Subject: [PATCH 2/9] feat(wasi): enable in-memory REPL for wasm32-wasip1 targets The previous wasm32 branch returned Ok(()) immediately, making the binary a no-op under WASI. Add a target_os = wasi branch that opens an in-memory Minigraf database and runs the REPL via stdin/stdout. File-backed storage is out of scope for WASI (in-memory only). Co-Authored-By: Claude Sonnet 4.6 --- src/main.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 0229552ba6..eb266a9427 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,12 +1,18 @@ -#[cfg(not(target_arch = "wasm32"))] +#[cfg(any(not(target_arch = "wasm32"), target_os = "wasi"))] use minigraf::Minigraf; #[cfg(not(target_arch = "wasm32"))] use minigraf::OpenOptions; fn main() -> anyhow::Result<()> { - #[cfg(target_arch = "wasm32")] + #[cfg(target_os = "wasi")] + { + let db = Minigraf::in_memory()?; + db.repl().run(); + Ok(()) + } + #[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))] { - // The REPL binary is not applicable to WASM targets. + // Browser WASM — entry point is the BrowserDb JS/WASM API, not a REPL binary. Ok(()) } #[cfg(not(target_arch = "wasm32"))] From 91b2634f3c934f81ce0666d0fed211b34711150d Mon Sep 17 00:00:00 2001 From: Aditya Mukhopadhyay Date: Sat, 18 Apr 2026 10:18:25 +0530 Subject: [PATCH 3/9] test(wasi): add WASI-gated in-memory smoke test Uses #[cfg(all(target_os = "wasi", test))] to avoid firing in the browser WASM environment where wasm-pack requires #[wasm_bindgen_test] instead. Run via: CARGO_TARGET_WASM32_WASIP1_RUNNER='wasmtime run --dir /tmp' cargo test --target wasm32-wasip1 Co-Authored-By: Claude Sonnet 4.6 --- src/db.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/db.rs b/src/db.rs index cc554190b5..6079a6d367 100644 --- a/src/db.rs +++ b/src/db.rs @@ -1728,3 +1728,31 @@ mod tests { assert!(result.is_ok(), "Query should succeed with higher limit"); } } + +// ─── WASI smoke test ───────────────────────────────────────────────────────── +// Gated to target_os = "wasi" only. Regular #[test] works here because +// cargo test --target wasm32-wasip1 uses Wasmtime as the runner +// (CARGO_TARGET_WASM32_WASIP1_RUNNER). Not gated on target_arch = "wasm32" +// because the browser target (wasm32-unknown-unknown) requires +// #[wasm_bindgen_test] instead, which is a separate harness. +#[cfg(all(target_os = "wasi", test))] +mod wasi_tests { + use crate::db::Minigraf; + use crate::query::datalog::executor::QueryResult; + + #[test] + fn in_memory_smoke() { + let db = Minigraf::in_memory().expect("open in-memory db"); + db.execute(r#"(transact [{:db/id "e1" :name "hello"}])"#) + .expect("transact"); + let r = db + .execute("(query [:find ?e :where [?e :name _]])") + .expect("query"); + match r { + QueryResult::QueryResults { results, .. } => { + assert!(!results.is_empty()); + } + _ => panic!("expected QueryResults"), + } + } +} From eca72c87e965c9fd0b6dd3cfcc397e628e1ad33c Mon Sep 17 00:00:00 2001 From: Aditya Mukhopadhyay Date: Sat, 18 Apr 2026 10:26:31 +0530 Subject: [PATCH 4/9] ci(wasi): rewrite wasm-wasi workflow as single job with Wasmtime + Wasmer Previous workflow had a fragile two-job split with artifact upload/download and no Wasmer step. New workflow: build -> WASI unit tests (via CARGO_TARGET_WASM32_WASIP1_RUNNER) -> Wasmtime smoke -> Wasmer smoke, all in one job. Co-Authored-By: Claude Sonnet 4.6 --- .github/workflows/wasm-wasi.yml | 66 +++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 .github/workflows/wasm-wasi.yml diff --git a/.github/workflows/wasm-wasi.yml b/.github/workflows/wasm-wasi.yml new file mode 100644 index 0000000000..2052cf8f04 --- /dev/null +++ b/.github/workflows/wasm-wasi.yml @@ -0,0 +1,66 @@ +name: WASM WASI + +on: + push: + branches: ["main"] + pull_request: + branches: ["main"] + +env: + CARGO_TERM_COLOR: always + WASMTIME_VERSION: v33.0.0 + WASMER_VERSION: v5.0.4 + +permissions: + contents: read + +jobs: + wasm-wasi: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: dtolnay/rust-toolchain@stable + with: + targets: wasm32-wasip1 + + - name: Build (release) + run: cargo build --target wasm32-wasip1 --release --bin minigraf + + - name: Install Wasmtime + run: | + curl -sSfL \ + "https://github.com/bytecodealliance/wasmtime/releases/download/${WASMTIME_VERSION}/wasmtime-${WASMTIME_VERSION}-x86_64-linux.tar.xz" \ + -o /tmp/wasmtime.tar.xz + tar -xf /tmp/wasmtime.tar.xz -C /tmp + echo "/tmp/wasmtime-${WASMTIME_VERSION}-x86_64-linux" >> "$GITHUB_PATH" + + - name: Run WASI tests (Wasmtime runner) + run: cargo test --target wasm32-wasip1 --lib + env: + CARGO_TARGET_WASM32_WASIP1_RUNNER: wasmtime run --dir /tmp + + - name: Smoke test — Wasmtime transact + query + run: | + out=$(printf '(transact [{:db/id "eid-1" :name "Alice"}])\n(query [:find ?e :where [?e :name _]])\n' | \ + wasmtime run --dir /tmp \ + target/wasm32-wasip1/release/minigraf.wasm) + echo "$out" + echo "$out" | grep -q "result(s) found" || { echo "SMOKE TEST FAILED: no results in output"; exit 1; } + + - name: Install Wasmer + run: | + curl -sSfL \ + "https://github.com/wasmerio/wasmer/releases/download/${WASMER_VERSION}/wasmer-linux-amd64.tar.gz" \ + -o /tmp/wasmer.tar.gz + mkdir -p /tmp/wasmer-install + tar -xf /tmp/wasmer.tar.gz -C /tmp/wasmer-install bin/wasmer + echo "/tmp/wasmer-install/bin" >> "$GITHUB_PATH" + + - name: Smoke test — Wasmer transact + query + run: | + out=$(printf '(transact [{:db/id "eid-1" :name "Alice"}])\n(query [:find ?e :where [?e :name _]])\n' | \ + wasmer run --dir /tmp \ + target/wasm32-wasip1/release/minigraf.wasm) + echo "$out" + echo "$out" | grep -q "result(s) found" || { echo "SMOKE TEST FAILED: no results in output"; exit 1; } From 183e297784a90c08f07c9260b9e340e1321d84a6 Mon Sep 17 00:00:00 2001 From: Aditya Mukhopadhyay Date: Sat, 18 Apr 2026 14:46:02 +0530 Subject: [PATCH 5/9] docs: update README to reflect Phase 8.1b WASI complete Co-Authored-By: Claude Sonnet 4.6 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ce3ffdd222..0f44132b2b 100644 --- a/README.md +++ b/README.md @@ -131,7 +131,7 @@ Offline-first storage with retroactive corrections — the bi-temporal model let ### For WASM / Browser -Phase 8 target: page-granular IndexedDB backend, `wasm-pack` packaging, npm release as `@minigraf/core`. Also supports server-side WASM via WASI. +Phase 8.1a complete: IndexedDB backend, `wasm-pack` packaging. Phase 8.1b complete: server-side WASM via `wasm32-wasip1` / WASI (Wasmtime, Wasmer). npm release as `@minigraf/core` planned for Phase 8.2. See the [Use Cases](https://github.com/adityamukho/minigraf/wiki/Use-Cases) wiki page for detailed guides on all three targets. From 4d524e595c5756be0db94d0ef10b6b2191dc4d68 Mon Sep 17 00:00:00 2001 From: Aditya Mukhopadhyay Date: Sat, 18 Apr 2026 14:53:37 +0530 Subject: [PATCH 6/9] docs: fix stale Phase 8 status markers in README Co-Authored-By: Claude Sonnet 4.6 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0f44132b2b..258c6e0582 100644 --- a/README.md +++ b/README.md @@ -113,7 +113,7 @@ No other database offers this combination: | **Embedded** | ✅ Yes | ✅ Yes | ✅ Yes | ❌ No | ✅ Yes | | **Graph Native** | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ❌ No | | **Rust** | ✅ Yes | ❌ Clojure | ✅ Yes | ❌ Java | ❌ C | -| **WASM Ready** | 🎯 Phase 8 | ❌ No | ⚠️ Limited | ❌ No | ✅ Yes | +| **WASM Ready** | ✅ Phase 8.1a/b | ❌ No | ⚠️ Limited | ❌ No | ✅ Yes | **Embedded graph memory for agents, mobile, and the browser — SQLite's simplicity + Datomic's temporal model.** @@ -140,7 +140,7 @@ See the [Use Cases](https://github.com/adityamukho/minigraf/wiki/Use-Cases) wiki Minigraf runs as: - ✅ An embedded library - ✅ A standalone binary (interactive REPL) -- 🎯 A WebAssembly module (Phase 8) +- ✅ A WebAssembly module — browser (`wasm32-unknown-unknown`) and server-side WASI (`wasm32-wasip1`) (Phase 8.1a/b complete) Minigraf will **not** be (by design): - **Distributed** — no clustering, no sharding, no replication; each agent instance owns its own `.graph` file From ec37b57e8a1462e42f9e192e68a3d3621c9ef905 Mon Sep 17 00:00:00 2001 From: Aditya Mukhopadhyay Date: Sat, 18 Apr 2026 15:10:53 +0530 Subject: [PATCH 7/9] fix(wasi): use keyword entity id in in_memory_smoke test Triple form [:e1 :name "hello"] with keyword :e1 is a valid entity id. Map form with bare string "e1" is not accepted by edn_to_entity_id. Under WASI p1, a panic aborts the process (no unwind), so the expect("transact") on the failing execute() killed the entire test run. Co-Authored-By: Claude Sonnet 4.6 --- src/db.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/db.rs b/src/db.rs index 6079a6d367..b20399da87 100644 --- a/src/db.rs +++ b/src/db.rs @@ -1743,7 +1743,7 @@ mod wasi_tests { #[test] fn in_memory_smoke() { let db = Minigraf::in_memory().expect("open in-memory db"); - db.execute(r#"(transact [{:db/id "e1" :name "hello"}])"#) + db.execute("(transact [[:e1 :name \"hello\"]])") .expect("transact"); let r = db .execute("(query [:find ?e :where [?e :name _]])") From 2a9fb428a09a30d29d8d40e38c1279272b2d8cb1 Mon Sep 17 00:00:00 2001 From: Aditya Mukhopadhyay Date: Sat, 18 Apr 2026 15:13:41 +0530 Subject: [PATCH 8/9] fix(wasi): gate thread::spawn tests with cfg(not(target_os = wasi)) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit WASI p1 has no thread support — thread::spawn panics immediately, which under WASI p1 (no unwind) aborts the entire test process. Gate test_concurrent_range_scans_correctness in btree_v6.rs and test_concurrent_reads in cache.rs so they are excluded from the wasm32-wasip1 test binary. Co-Authored-By: Claude Sonnet 4.6 --- src/storage/btree_v6.rs | 1 + src/storage/cache.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/src/storage/btree_v6.rs b/src/storage/btree_v6.rs index a234b900ef..d367f66ccb 100644 --- a/src/storage/btree_v6.rs +++ b/src/storage/btree_v6.rs @@ -1049,6 +1049,7 @@ mod tests { } #[test] + #[cfg(not(target_os = "wasi"))] fn test_concurrent_range_scans_correctness() { use crate::storage::CommittedIndexReader; use std::sync::{Arc, Barrier}; diff --git a/src/storage/cache.rs b/src/storage/cache.rs index 7331a51791..8a4c19e37a 100644 --- a/src/storage/cache.rs +++ b/src/storage/cache.rs @@ -228,6 +228,7 @@ mod tests { } #[test] + #[cfg(not(target_os = "wasi"))] fn test_concurrent_reads() { use std::sync::Arc; use std::thread; From 2ca5405f5dd390da65ab56d5afa4b70df5dddd0d Mon Sep 17 00:00:00 2001 From: Aditya Mukhopadhyay Date: Sat, 18 Apr 2026 15:15:58 +0530 Subject: [PATCH 9/9] fix(ci): use triple form in WASI smoke tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Map form {:db/id "eid-1" :name "Alice"} is invalid — edn_to_entity_id only accepts keywords or UUID strings. Triple form [:alice :name "Alice"] uses a keyword entity id which is always valid. Co-Authored-By: Claude Sonnet 4.6 --- .github/workflows/wasm-wasi.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/wasm-wasi.yml b/.github/workflows/wasm-wasi.yml index 2052cf8f04..87da788ce4 100644 --- a/.github/workflows/wasm-wasi.yml +++ b/.github/workflows/wasm-wasi.yml @@ -42,7 +42,7 @@ jobs: - name: Smoke test — Wasmtime transact + query run: | - out=$(printf '(transact [{:db/id "eid-1" :name "Alice"}])\n(query [:find ?e :where [?e :name _]])\n' | \ + out=$(printf '(transact [[:alice :name "Alice"]])\n(query [:find ?e :where [?e :name _]])\n' | \ wasmtime run --dir /tmp \ target/wasm32-wasip1/release/minigraf.wasm) echo "$out" @@ -59,7 +59,7 @@ jobs: - name: Smoke test — Wasmer transact + query run: | - out=$(printf '(transact [{:db/id "eid-1" :name "Alice"}])\n(query [:find ?e :where [?e :name _]])\n' | \ + out=$(printf '(transact [[:alice :name "Alice"]])\n(query [:find ?e :where [?e :name _]])\n' | \ wasmer run --dir /tmp \ target/wasm32-wasip1/release/minigraf.wasm) echo "$out"