#[test]
fn component_encoder_trampoline_bug() {
let component_path = "/tmp/repro_build/threads_vfs.component.wasm";
if !std::path::Path::new(component_path).exists() {
eprintln!("SKIP: {component_path} not found.");
eprintln!("Build first: cargo r -r -- build -p threads_vfs test_threads \\");
eprintln!(" -t single --threads true --dev --out-dir /tmp/repro_build \\");
eprintln!(" --stack-size vfs=1048576 --stack-size test_threads=1048576");
return;
}
let component_bytes = std::fs::read(component_path).expect("read component");
let mut validator = wasmparser::Validator::new_with_features(wasmparser::WasmFeatures::all());
let result = validator.validate_all(&component_bytes);
match result {
Ok(_) => {
}
Err(e) => {
let err = format!("{e}");
if err.contains("type mismatch") && err.contains("nothing on stack") {
panic!(
"BUG REPRODUCED: ComponentEncoder generated lowered function with stack imbalance.\n\
Error: {e}\n\
\n\
This confirms the wit_component::ComponentEncoder trampoline bug.\n\
The VFS refuge output (before ComponentEncoder) is VALID.\n\
ComponentEncoder output (after re-wrapping) is INVALID."
);
}
panic!("Unexpected validation error (different from known bug): {e}");
}
}
}