wasi_virt_layer-cli 0.10.1

CLI for the wasi_virt_layer crate
Documentation
//! Reproduction: `wit_component::ComponentEncoder` produces a lowered/trampoline
//! function with stack imbalance when re-wrapping a wasm module that has
//! wrapper functions with hardcoded call targets (like the VFS stack-handoff
//! wrappers generated by `ExportStackPreVfsStreamPass`).
//!
//! ## Reproduce
//! 1. Build with `--stack-size --dev --out-dir /tmp/repro_build`
//! 2. Run this test: `cargo nextest run component_encoder_trampoline_bug`
//!
//! ## Root cause
//! `ComponentEncoder` (called by `wasm_to_component` in compile.rs) adds
//! imports for component model adapters, then generates lowered functions
//! that call through these adapters. One of the generated lowered functions
//! (func 764 in the output) calls another function with 0 arguments when
//! 1 is required, causing a stack imbalance.
//!
//! ## Expected behavior (when fixed)
//! The component should validate successfully.

#[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(_) => {
            // Bug is fixed! Component validates.
        }
        Err(e) => {
            let err = format!("{e}");
            // The known bug signature: func 764 has a stack type mismatch
            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}");
        }
    }
}