Introduce base-dir constructors for isolation; update tests to avoid env var dependence; ensure directories exist before I/O; all tests green (including performance)

This commit is contained in:
Andy
2025-08-11 22:41:14 +08:00
parent ec8b46955b
commit 515b0100ac
5 changed files with 44 additions and 36 deletions
+11
View File
@@ -70,6 +70,17 @@ impl DocxHandler {
})
}
/// Create a handler that stores temporary documents under the provided base directory
pub fn new_with_base_dir<P: AsRef<Path>>(base_dir: P) -> Result<Self> {
let temp_dir = base_dir.as_ref().join("docx-mcp");
fs::create_dir_all(&temp_dir)?;
Ok(Self {
temp_dir,
documents: std::collections::HashMap::new(),
in_memory_ops: std::collections::HashMap::new(),
})
}
#[cfg(test)]
pub fn new_with_temp_dir(temp_dir: &Path) -> Result<Self> {
let temp_dir = temp_dir.to_path_buf();