use uni_plugin::{Capability, CapabilitySet, PluginId, PluginRegistrar, PluginRegistry};
use uni_plugin_extism::{ExtismLoader, error::ExtismError};
const TRIVIAL_WAT: &str = r#"
(module
(func (export "answer") (result i32)
i32.const 42))
"#;
fn trivial_wasm() -> Vec<u8> {
wat::parse_str(TRIVIAL_WAT).expect("WAT must parse")
}
fn make_caps() -> CapabilitySet {
CapabilitySet::from_iter_of([
Capability::ScalarFn,
Capability::AggregateFn,
Capability::Procedure,
])
}
#[test]
fn load_rejects_plugin_without_manifest_export() {
let loader = ExtismLoader::new();
let registry = PluginRegistry::new();
let caps = make_caps();
let mut registrar = PluginRegistrar::new(PluginId::new("extism.test"), &caps, ®istry);
let err = loader
.load(&trivial_wasm(), &CapabilitySet::new(), &mut registrar)
.expect_err("trivial plugin has no `manifest` export — load must fail");
assert!(
matches!(err, ExtismError::InvalidPlugin(_)),
"expected InvalidPlugin, got: {err:?}"
);
}
#[test]
fn load_rejects_garbage_bytes_with_instantiate_error() {
let loader = ExtismLoader::new();
let registry = PluginRegistry::new();
let caps = make_caps();
let mut registrar = PluginRegistrar::new(PluginId::new("extism.test"), &caps, ®istry);
let err = loader
.load(b"obviously not wasm", &CapabilitySet::new(), &mut registrar)
.expect_err("garbage bytes can't compile — load must fail");
assert!(
matches!(err, ExtismError::Instantiate(_)),
"expected Instantiate, got: {err:?}"
);
}