#![allow(dead_code)]
use std::io::Write;
use std::path::{Path, PathBuf};
pub fn perf_plugin_wasm() -> PathBuf {
let p = Path::new(env!("CARGO_MANIFEST_DIR"))
.join("target/wasm32-wasip2/release/perf_plugin.wasm");
assert!(
p.exists(),
"perf_plugin.wasm not found at {}; build it first with \
`cargo component build -p perf_plugin --target wasm32-wasip2 --release`",
p.display()
);
p
}
pub fn stage_home_with_plugin(count: usize) -> tempfile::TempDir {
let tmp = tempfile::tempdir().expect("tempdir");
let dir = tmp.path().join(".config/yosh");
std::fs::create_dir_all(&dir).expect("create cfg dir");
let lock = dir.join("plugins.lock");
let mut f = std::fs::File::create(&lock).expect("create lock");
if count > 0 {
let wasm = perf_plugin_wasm();
for i in 0..count {
writeln!(
f,
r#"
[[plugin]]
name = "perf_{i}"
path = "{wasm}"
enabled = true
capabilities = ["variables:read", "hooks:pre_prompt", "hooks:pre_exec", "hooks:post_exec"]
"#,
i = i,
wasm = wasm.display()
)
.expect("write entry");
}
}
drop(f);
tmp
}