From 53c4f18621f97e4fdeffac3c7d52940e981d9b65 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 13 Feb 2026 09:18:43 +0000 Subject: [PATCH] =?UTF-8?q?test:=20Cycle=2021=20=E2=80=94=20OOB=20call=5Fi?= =?UTF-8?q?ndirect,=20all-guest=20integration=20(100=20tests=20milestone)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Authored by Claude, lovingly guided by Zachery Aaron Shores-Chmielewski --- crates/wasm-actor/tests/wasm_actor.rs | 82 +++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/crates/wasm-actor/tests/wasm_actor.rs b/crates/wasm-actor/tests/wasm_actor.rs index c967876..89111ac 100644 --- a/crates/wasm-actor/tests/wasm_actor.rs +++ b/crates/wasm-actor/tests/wasm_actor.rs @@ -3586,3 +3586,85 @@ proptest! { } } } + +// ── OOB table access: call_indirect with bad index traps ──────────────────── + +#[test] +fn guest_oob_call_indirect_traps_actor_survives() { + // Guest uses call_indirect with index 99 on a table of size 1. + // This should trap. Actor should survive. + let wat = r#" + (module + (import "swactor" "send" (func $send (param i32 i32 i32))) + (memory (export "memory") 1) + (type $void (func)) + (func $noop) + (table 1 funcref) + (elem (i32.const 0) $noop) + + (func (export "alloc") (param i32) (result i32) i32.const 256) + (func (export "handle") (param i32 i32) + ;; call_indirect with index 99 — out of bounds + (call_indirect (type $void) (i32.const 99)) + ) + ) + "#; + let wasm = wat::parse_str(wat).unwrap(); + let engine = SharedEngine::new().unwrap(); + let actor = WasmActorBuilder::new(engine, wasm).build().unwrap(); + + let rt = Runtime::new(RuntimeConfig::default()); + let addr = rt.spawn(actor).unwrap(); + + rt.send_to(addr, ByteMessage(vec![1])).unwrap(); + rt.tick(); // OOB trap + + // Actor survives + rt.send_to(addr, ByteMessage(vec![2])).unwrap(); + rt.tick(); +} + +// ── 100th test: comprehensive round-trip through all guest modules ────────── + +#[test] +fn all_guest_modules_work_in_same_runtime() { + // Spawn one of each guest (echo, double, silent) in the same runtime. + // Send messages to all three and verify each behaves correctly. + // This is the 100th test — a comprehensive integration checkpoint. + let engine = SharedEngine::new().unwrap(); + + let echo = WasmActorBuilder::new(engine.clone(), guest_wasm("echo")) + .build().unwrap(); + let double = WasmActorBuilder::new(engine.clone(), guest_wasm("double")) + .build().unwrap(); + let silent = WasmActorBuilder::new(engine, guest_wasm("silent")) + .build().unwrap(); + + let rt = Runtime::new(RuntimeConfig::default()); + let inbox = rt.new_inbox::().unwrap(); + + let echo_addr = rt.spawn(echo).unwrap(); + let double_addr = rt.spawn(double).unwrap(); + let silent_addr = rt.spawn(silent).unwrap(); + + // Send to all three + rt.send_to(echo_addr, framed_msg(inbox.addr(), b"E")).unwrap(); + rt.send_to(double_addr, framed_msg(inbox.addr(), b"D")).unwrap(); + rt.send_to(silent_addr, ByteMessage(b"S".to_vec())).unwrap(); + rt.tick(); + + // Collect results + let mut messages = Vec::new(); + while let Some(msg) = inbox.try_recv() { + messages.push(msg.0); + } + + // Echo: 1 message, Double: 2 messages, Silent: 0 messages = 3 total + assert_eq!(messages.len(), 3, "echo(1) + double(2) + silent(0) = 3 messages"); + + // Verify content + let echo_count = messages.iter().filter(|m| m.as_slice() == b"E").count(); + let double_count = messages.iter().filter(|m| m.as_slice() == b"D").count(); + assert_eq!(echo_count, 1, "echo should send 1 copy"); + assert_eq!(double_count, 2, "double should send 2 copies"); +}