use std::sync::Arc;
use tensor_wasm_core::error::TensorWasmError;
use tensor_wasm_core::types::TenantId;
use tensor_wasm_exec::engine::TensorWasmEngine;
use tensor_wasm_exec::executor::{ExecError, SpawnConfig, TensorWasmExecutor};
#[tokio::test]
async fn invalid_wasm_returns_wasmtime_variant() {
let engine = Arc::new(TensorWasmEngine::new().expect("engine"));
let exec = TensorWasmExecutor::new(engine);
let garbage: Vec<u8> = b"not-a-wasm-module-at-all".to_vec();
let err = exec
.spawn_instance(SpawnConfig::for_tenant(TenantId(1)), &garbage)
.await
.expect_err("garbage bytes must fail to compile");
match err {
ExecError::Wasmtime(_) => {}
other => panic!("expected ExecError::Wasmtime, got {other:?}"),
}
}
#[tokio::test]
async fn invalid_wasm_converts_to_tensor_wasm_compile_error() {
let engine = Arc::new(TensorWasmEngine::new().expect("engine"));
let exec = TensorWasmExecutor::new(engine);
let bad_version: Vec<u8> = b"\0asm\xff\xff\xff\xff".to_vec();
let err = exec
.spawn_instance(SpawnConfig::for_tenant(TenantId(1)), &bad_version)
.await
.expect_err("bad wasm version must fail");
let tensor_wasm_err: TensorWasmError = err.into();
match tensor_wasm_err {
TensorWasmError::WasmCompile(_) => {}
other => panic!("expected TensorWasmError::WasmCompile, got {other:?}"),
}
}