Skip to main content

wasm_runtime_smoke/
wasm_runtime_smoke.rs

1//! Runtime-level smoke test for the wasm32-wasi library surface.
2//! Build with:
3//! cargo build --example wasm_runtime_smoke --no-default-features --target wasm32-wasip1
4
5use omega_cognitive_kernel::Kernel;
6
7fn main() {
8    let mut source = Kernel::with_state_path("/tmp/omega-wasm-runtime-source.json");
9    source.autosave = false;
10    source.dump_trajectory = false;
11    source.auto_checkpoint_on_patch = false;
12
13    for _ in 0..4 {
14        source
15            .step("maintain coherent self-model omega dayan")
16            .expect("source step should execute under WASI");
17    }
18    let source_steps = source.status().total_steps;
19    let snapshot = source
20        .snapshot_json()
21        .expect("snapshot serialization should work under WASI");
22
23    let mut restored = Kernel::with_state_path("/tmp/omega-wasm-runtime-restored.json");
24    restored.autosave = false;
25    restored.dump_trajectory = false;
26    restored.auto_checkpoint_on_patch = false;
27    restored
28        .apply_snapshot_json(&snapshot)
29        .expect("snapshot restore should work under WASI");
30    assert_eq!(restored.status().total_steps, source_steps);
31
32    restored
33        .step("continue after wasm hot restore")
34        .expect("restored kernel should continue under WASI");
35    assert_eq!(restored.status().total_steps, source_steps + 1);
36
37    println!(
38        "wasm-runtime-smoke: ok steps_before={} steps_after={} snapshot_bytes={}",
39        source_steps,
40        restored.status().total_steps,
41        snapshot.len()
42    );
43}