//! Sanity check: 1-vCPU bake + restore + exec still works after
//! the SNAPSHOT_VERSION 9 ICH-register addition. Multi-vCPU is
//! the target of the ICH fix; this example verifies we didn't
//! regress the common-case 1-vCPU path.

use supermachine::Image;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    eprintln!("[sanity] baking 1-vCPU rust:1-slim...");
    let img = Image::builder("rust:1-slim")
        .with_name("_sanity_1v_v9")
        .build()?;
    eprintln!("[sanity] bake OK; acquire + exec...");
    let pool = img.pool().min(0).max(1).build()?;
    let vm = pool.acquire()?;
    let out = vm.exec_builder().argv(["sh", "-c", "echo OK"]).output()?;
    let s = String::from_utf8_lossy(&out.stdout);
    let trimmed = s.trim();
    println!("[sanity] 1vcpu output: {trimmed:?}");
    if !trimmed.contains("OK") {
        std::process::exit(1);
    }
    eprintln!("[sanity] PASS");
    Ok(())
}
