feat(wasm): finish route C — bridge package, smoke, site embed L1

Canonical marqdo-bridge.js ships with wasm build, Node ABI smoke covers
boot/call, and ext/web gains client_embed for head/static mounting.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
cflmyandCursor committed 2026-09-01 11:05:43 +08:00
1 parent 04890e0c73
commit 2445c290c9
11 files changed
+459 -38

No files matched your search

+80
View File
@@ -0,0 +1,80 @@
#!/usr/bin/env node
/**
* WASM ABI smoke (C1/C3): boot counter.mq.md, call bump twice.
* Usage: node tests/wasm/smoke.mjs [path/to/marqdo_wasm.wasm]
*/
import fs from "fs";
import path from "path";
import { fileURLToPath } from "url";
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const root = path.resolve(__dirname, "../..");
const wasmPath =
process.argv[2] ||
path.join(root, "examples/browser-hello/marqdo_wasm.wasm");
const srcPath = path.join(root, "examples/browser-hello/counter.mq.md");
if (!fs.existsSync(wasmPath)) {
console.error("missing wasm:", wasmPath);
console.error("build: marqdo wasm build -o examples/browser-hello");
process.exit(2);
}
const buf = fs.readFileSync(wasmPath);
const { instance } = await WebAssembly.instantiate(buf, {});
const e = instance.exports;
const enc = new TextEncoder();
const dec = new TextDecoder();
function pack(ptr) {
const len = new DataView(e.memory.buffer).getUint32(ptr, true);
const j = JSON.parse(dec.decode(new Uint8Array(e.memory.buffer, ptr + 4, len)));
e.mq_dealloc(ptr, 4 + len);
return j;
}
function write(s) {
const b = enc.encode(s);
const p = e.mq_alloc(b.length || 1);
new Uint8Array(e.memory.buffer, p, b.length).set(b);
return { p, n: b.length };
}
function boot(source) {
const { p, n } = write(source);
const o = e.mq_boot(p, n);
e.mq_dealloc(p, n || 1);
return pack(o);
}
function call(name, args) {
const a = write(name);
const b = write(JSON.stringify(args || {}));
const o = e.mq_call(a.p, a.n, b.p, b.n);
e.mq_dealloc(a.p, a.n || 1);
e.mq_dealloc(b.p, b.n || 1);
return pack(o);
}
const source = fs.readFileSync(srcPath, "utf8");
const b = boot(source);
if (!b.ok) {
console.error("boot failed", b.error);
process.exit(1);
}
if (!Array.isArray(b.value) || b.value.length < 1) {
console.error("expected wire list", b.value);
process.exit(1);
}
const c1 = call("bump", {});
const c2 = call("bump", {});
if (!c1.ok || !c2.ok) {
console.error("call failed", c1, c2);
process.exit(1);
}
if (c2.value?.set_text?.["#count"] !== "2") {
console.error("expected count 2, got", c2.value);
process.exit(1);
}
console.log("wasm smoke ok");
+54
View File
@@ -0,0 +1,54 @@
//! Browser WASM integration smoke (Node + wasm artifact).
use std::path::PathBuf;
use std::process::Command;
fn wasm_artifact() -> Option<PathBuf> {
let mut cands = Vec::new();
if let Ok(td) = std::env::var("CARGO_TARGET_DIR") {
cands.push(PathBuf::from(td).join("wasm32-unknown-unknown/release-wasm/marqdo_wasm.wasm"));
}
cands.push(PathBuf::from(
"target/wasm32-unknown-unknown/release-wasm/marqdo_wasm.wasm",
));
cands.push(PathBuf::from("examples/browser-hello/marqdo_wasm.wasm"));
cands.into_iter().find(|p| p.is_file())
}
#[test]
fn wasm_node_abi_smoke() {
if Command::new("node").arg("--version").output().is_err() {
eprintln!("skip: node not installed");
return;
}
let wasm = match wasm_artifact() {
Some(p) => p,
None => {
if std::env::var("MARQDO_WASM_SMOKE").ok().as_deref() != Some("1") {
eprintln!("skip: no wasm artifact (run `marqdo wasm build` or set MARQDO_WASM_SMOKE=1)");
return;
}
let status = Command::new(env!("CARGO_BIN_EXE_marqdo"))
.args(["wasm", "build", "-o", "examples/browser-hello"])
.status()
.expect("marqdo wasm build");
assert!(status.success(), "marqdo wasm build failed");
PathBuf::from("examples/browser-hello/marqdo_wasm.wasm")
}
};
assert!(wasm.is_file(), "missing {}", wasm.display());
let out = Command::new("node")
.args(["tests/wasm/smoke.mjs", wasm.to_str().unwrap()])
.output()
.expect("node smoke");
let stdout = String::from_utf8_lossy(&out.stdout);
let stderr = String::from_utf8_lossy(&out.stderr);
assert!(
out.status.success(),
"smoke failed: status={} stdout={} stderr={}",
out.status,
stdout,
stderr
);
assert!(stdout.contains("wasm smoke ok"), "stdout={stdout}");
}