fix ci: gate harness_dir-dependent tests behind a dummy env var
This commit is contained in:
parent
7ba492b965
commit
22f8805a77
2 changed files with 98 additions and 27 deletions
|
|
@ -289,6 +289,36 @@ pub async fn serve_http(addr: std::net::SocketAddr) -> anyhow::Result<()> {
|
|||
mod status_hint_tests {
|
||||
use super::{BASH_IDLE_WAIT_HINT, format_task};
|
||||
use crate::protocol::{TaskFile, TaskStatus};
|
||||
use std::sync::Mutex;
|
||||
|
||||
/// `format_task` unconditionally resolves `crate::paths::task_out`/
|
||||
/// `task_err` (to check captured-output length), which panics if
|
||||
/// `HYPERHIVE_HARNESS_DIR` is unset — exactly cargo's sandboxed test
|
||||
/// environment. Same helper shape as `runner::tests::with_harness_dir`
|
||||
/// (module-scope mutex to serialise against parallel test threads
|
||||
/// mutating the process-wide env var, save/restore on the way out);
|
||||
/// duplicated rather than shared because the two test modules live in
|
||||
/// separate files with no existing shared test-util module.
|
||||
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"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn task(status: TaskStatus) -> TaskFile {
|
||||
TaskFile {
|
||||
|
|
@ -307,16 +337,20 @@ mod status_hint_tests {
|
|||
|
||||
#[test]
|
||||
fn running_task_after_wait_appends_idle_hint() {
|
||||
let t = task(TaskStatus::Running);
|
||||
let mut out = format_task(&t);
|
||||
out.push_str(BASH_IDLE_WAIT_HINT);
|
||||
assert!(out.contains(BASH_IDLE_WAIT_HINT));
|
||||
with_harness_dir(|| {
|
||||
let t = task(TaskStatus::Running);
|
||||
let mut out = format_task(&t);
|
||||
out.push_str(BASH_IDLE_WAIT_HINT);
|
||||
assert!(out.contains(BASH_IDLE_WAIT_HINT));
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn done_task_formats_without_hint() {
|
||||
let out = format_task(&task(TaskStatus::Done));
|
||||
assert!(!out.contains(BASH_IDLE_WAIT_HINT));
|
||||
assert!(out.contains("status=done"));
|
||||
with_harness_dir(|| {
|
||||
let out = format_task(&task(TaskStatus::Done));
|
||||
assert!(!out.contains(BASH_IDLE_WAIT_HINT));
|
||||
assert!(out.contains("status=done"));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue