From e6344677fe8e370974c47cc96e75b632e0099097 Mon Sep 17 00:00:00 2001 From: bill fumerola Date: Thu, 26 Jun 2025 12:48:36 -0700 Subject: [PATCH] chore(test): add test for duplicate package insert --- Cargo.lock | 1 + Cargo.toml | 4 ++++ src/graph.rs | 44 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index ee9bde1..6548026 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1044,6 +1044,7 @@ dependencies = [ "snafu", "wac-types", "wasmtime", + "wat", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 89bcd8d..28e807b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -39,6 +39,7 @@ anyhow = "1" derivative = "2" semver = "1" wasmtime = { version = "34", default-features = false } +wat = { version = "1.233.0", default-features = false } wit-bindgen = { version = "0.43", default-features = false, features = [ "macros", ]} @@ -57,3 +58,6 @@ wasmtime = { workspace = true, features = [ "cranelift", "wat", ]} + +[dev-dependencies] +wat.workspace = true diff --git a/src/graph.rs b/src/graph.rs index 8f84f14..33ce52c 100644 --- a/src/graph.rs +++ b/src/graph.rs @@ -779,3 +779,47 @@ pub enum InstantiatePackageError { #[snafu(display("Missing interface export {}", path))] MissingInterfaceExport { path: ForeignInterfacePath }, } + +#[cfg(test)] +mod tests { + // Simple async trampoline that just passes calls through + + use std::sync::Arc; + + struct PassthroughTrampoline; + impl crate::Trampoline<(), ()> for PassthroughTrampoline { + fn bounce<'c>( + &self, + mut _call: crate::GuestCall<'c, (), ()>, + ) -> Result, anyhow::Error> { + todo!() + } + } + + #[test] + fn test_add_duplicate_package() { + const VERSION: semver::Version = semver::Version::new(1, 0, 0); + let pkg = || { + let trampoline: Arc> = Arc::new(PassthroughTrampoline {}); + crate::PackageTrampoline::with_default_context(trampoline, ()) + }; + let mut graph = crate::CompositionGraph::<()>::new(); + let test_component = wat::parse_str( + r#" +(component + (core module (;0;) + (memory (;0;) 16) + (export "memory" (memory 0)) + ) +)"#, + ) + .unwrap(); + + graph + .add_package("test".to_string(), VERSION, test_component.clone(), pkg()) + .expect("Failed to add package"); + graph + .add_package("test".to_string(), VERSION, test_component, pkg()) + .expect_err("Expected to fail adding duplicate package"); + } +}