plugin/host/tests/common/mod.rs
//! Shared fixtures for this crate's integration tests: a scratch directory, and
//! a plugin directory holding REAL built modules.
//!
//! One copy, because both `router_cannot_tell_them_apart.rs` and
//! `config_names_the_reader.rs` need to stage the same modules the same way, and
//! two copies of "where is the module and what if it is missing" would be two
//! places for the skip-instead-of-fail behaviour to creep back in (LAW 5).
use std::path::PathBuf;
pub const BUILD_CMD: &str = "cargo xtask build-wasm-plugins";
/// A fresh, empty directory unique to this process and thread.
pub fn scratch(name: &str) -> PathBuf {
let p = std::env::temp_dir().join(format!(
"holger-plugin-{name}-{}-{:?}",
std::process::id(),
std::thread::current().id()
));
let _ = std::fs::remove_dir_all(&p);
std::fs::create_dir_all(&p).expect("scratch dir");
p
}
/// Copy the built modules into a fresh plugin directory, the way a deployment
/// ships them.
///
/// `HOLGER_PLUGIN_WASM_DIR` first — the same override `agreement::locate_module`
/// honours, so a directory of FORGE-built modules (`dwarves buildthing ./holger
/// --suite MVP --variant plugin-*`) can be pointed at without a host rebuild.
/// Otherwise each guest is built here on demand
/// (`traits::test_support::wasm_guest`, no container).
///
/// **Fails loudly — never skips — when a module is missing.** A test that
/// quietly passed because there was nothing to load would be the exact
/// `NOT RUN → true` shape this repo keeps finding.
pub fn plugin_dir_with_modules(modules: &[&str]) -> PathBuf {
let dir = scratch("plugins");
let forge = std::env::var_os("HOLGER_PLUGIN_WASM_DIR").map(PathBuf::from);
for m in modules {
let src = match &forge {
Some(d) => d.join(m),
None => {
traits::test_support::wasm_guest(&m.trim_end_matches(".wasm").replace('_', "-"))
}
};
assert!(
src.is_file(),
"{} has not been built. This test loads REAL modules; it does not skip.\n\
Build them with:\n {BUILD_CMD}",
src.display()
);
std::fs::copy(&src, dir.join(m))
.unwrap_or_else(|e| panic!("copying {} into the plugin dir: {e}", src.display()));
}
dir
}