mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-14 19:22:03 +00:00
automation_roots.rs and protocol_props.rs wrote their files into folders made by vectorcraft_testkit::temp_dir (vectorcraft-testkit-roots-<tag>-<pid>, mcp-junk, mcp-confined), and nothing removed them after the run. A shared tests/common module adds TempFolder, which takes the folder from temp_dir, with its checks against a folder made by another user, and removes it with everything in it when dropped, also when the test panics, as the findfiles tests' Tree guard does (crates/engine/src/cmd/findfiles/tests.rs:49). Each proptest case of a_confined_server_writes_only_inside_its_root now gets a new folder. A new test checks that the folder is removed on drop and after a panic.
29 lines
772 B
Rust
29 lines
772 B
Rust
//! Shared helpers for the MCP integration tests.
|
|
|
|
use std::path::{Path, PathBuf};
|
|
|
|
/// A test's own folder, made by [`vectorcraft_testkit::temp_dir`] (with its checks against a
|
|
/// folder made by someone else) and removed with everything in it when dropped, also when the
|
|
/// test panics. A removal that fails (a file still open) is ignored. Tests that run at the same
|
|
/// time use different tags.
|
|
pub struct TempFolder(PathBuf);
|
|
|
|
impl TempFolder {
|
|
pub fn new(tag: &str) -> Self {
|
|
Self(vectorcraft_testkit::temp_dir(tag))
|
|
}
|
|
}
|
|
|
|
impl std::ops::Deref for TempFolder {
|
|
type Target = Path;
|
|
fn deref(&self) -> &Path {
|
|
&self.0
|
|
}
|
|
}
|
|
|
|
impl Drop for TempFolder {
|
|
fn drop(&mut self) {
|
|
let _ = std::fs::remove_dir_all(&self.0);
|
|
}
|
|
}
|