hive-bash-mcp: share one HARNESS_DIR_ENV_LOCK across test modules
This commit is contained in:
parent
80f16094f1
commit
4fd25b7f45
4 changed files with 54 additions and 61 deletions
|
|
@ -796,38 +796,8 @@ fn done_summary(id: &str, summary: &str, output: Option<(bool, bool)>) -> String
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::validate_task_name;
|
||||
use crate::test_util::with_harness_dir;
|
||||
use hive_types::Ident;
|
||||
use std::sync::Mutex;
|
||||
|
||||
/// `done_summary`'s stderr/stdout-pointer tests format real paths via
|
||||
/// `crate::paths::task_out`/`task_err`, which resolve through
|
||||
/// `hive_agent_sock::paths::harness_dir` — that panics if
|
||||
/// `HYPERHIVE_HARNESS_DIR` is unset (see its doc comment), which is
|
||||
/// exactly cargo's sandboxed test environment (no real container, no
|
||||
/// meta-flake-injected env). Set a dummy value for the duration of
|
||||
/// those tests, serialised on a module mutex so parallel test threads
|
||||
/// don't race the process-wide env var, and restore whatever was there
|
||||
/// before on the way out.
|
||||
static HARNESS_DIR_ENV_LOCK: Mutex<()> = Mutex::new(());
|
||||
|
||||
fn with_harness_dir<F: FnOnce()>(f: F) {
|
||||
let _guard = HARNESS_DIR_ENV_LOCK
|
||||
.lock()
|
||||
.unwrap_or_else(std::sync::PoisonError::into_inner);
|
||||
let prev = std::env::var("HYPERHIVE_HARNESS_DIR").ok();
|
||||
// SAFETY: serialised by HARNESS_DIR_ENV_LOCK above; restored below
|
||||
// in the same scope before the guard drops.
|
||||
unsafe {
|
||||
std::env::set_var("HYPERHIVE_HARNESS_DIR", "/tmp/hive-bash-mcp-test-harness");
|
||||
}
|
||||
f();
|
||||
unsafe {
|
||||
match prev {
|
||||
Some(v) => std::env::set_var("HYPERHIVE_HARNESS_DIR", v),
|
||||
None => std::env::remove_var("HYPERHIVE_HARNESS_DIR"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn accepts_ident_names() {
|
||||
|
|
|
|||
Loading…
Reference in a new issue