use std::path::{Path, PathBuf};
pub(crate) fn stage_fixture(fixture: &Path) -> (tempfile::TempDir, PathBuf) {
let dir = tempfile::tempdir().expect("tempdir");
let dest = dir.path().to_path_buf();
copy_dir_all(fixture, &dest).expect("copy fixture");
(dir, dest)
}
fn copy_dir_all(src: &Path, dst: &Path) -> std::io::Result<()> {
std::fs::create_dir_all(dst)?;
for entry in std::fs::read_dir(src)? {
let entry = entry?;
let ft = entry.file_type()?;
let src_child = entry.path();
let dst_child = dst.join(entry.file_name());
if ft.is_dir() {
copy_dir_all(&src_child, &dst_child)?;
} else {
std::fs::copy(&src_child, &dst_child)?;
}
}
Ok(())
}
#[allow(dead_code)]
pub(crate) async fn two_agents_on_fixture(
fixture_rel: &str,
) -> (
crate::agent::Agent,
crate::agent::Agent,
PathBuf,
tempfile::TempDir,
) {
let fixture = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("tests/fixtures/lsp-mux")
.join(fixture_rel);
assert!(fixture.exists(), "fixture missing: {}", fixture.display());
let (tempdir, root) = stage_fixture(&fixture);
let a = crate::agent::Agent::new(Some(root.clone()))
.await
.expect("Agent A");
let b = crate::agent::Agent::new(Some(root.clone()))
.await
.expect("Agent B");
(a, b, root, tempdir)
}