test: serialize CONFIRM/HANDOFF env mutations across crates
Avoid parallel cargo test flakes when multiple tests set process env.
This commit is contained in:
parent
15d271b656
commit
44b0d7c038
|
|
@ -743,6 +743,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn handoff_auto_resume_and_abort() {
|
fn handoff_auto_resume_and_abort() {
|
||||||
|
let _env_lock = crate::test_env::lock();
|
||||||
// SAFETY: tests run serially for this env in practice; restore after.
|
// SAFETY: tests run serially for this env in practice; restore after.
|
||||||
let prev = std::env::var("GROKBOY_HANDOFF_AUTO").ok();
|
let prev = std::env::var("GROKBOY_HANDOFF_AUTO").ok();
|
||||||
unsafe { std::env::set_var("GROKBOY_HANDOFF_AUTO", "1") };
|
unsafe { std::env::set_var("GROKBOY_HANDOFF_AUTO", "1") };
|
||||||
|
|
|
||||||
|
|
@ -267,6 +267,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn confirm_auto_approve_via_confirm_env() {
|
fn confirm_auto_approve_via_confirm_env() {
|
||||||
|
let _env_lock = crate::test_env::lock();
|
||||||
let prev_c = std::env::var("GROKBOY_CONFIRM_AUTO").ok();
|
let prev_c = std::env::var("GROKBOY_CONFIRM_AUTO").ok();
|
||||||
let prev_h = std::env::var("GROKBOY_HANDOFF_AUTO").ok();
|
let prev_h = std::env::var("GROKBOY_HANDOFF_AUTO").ok();
|
||||||
unsafe {
|
unsafe {
|
||||||
|
|
@ -288,6 +289,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn confirm_auto_falls_back_to_handoff_env() {
|
fn confirm_auto_falls_back_to_handoff_env() {
|
||||||
|
let _env_lock = crate::test_env::lock();
|
||||||
let prev_c = std::env::var("GROKBOY_CONFIRM_AUTO").ok();
|
let prev_c = std::env::var("GROKBOY_CONFIRM_AUTO").ok();
|
||||||
let prev_h = std::env::var("GROKBOY_HANDOFF_AUTO").ok();
|
let prev_h = std::env::var("GROKBOY_HANDOFF_AUTO").ok();
|
||||||
unsafe {
|
unsafe {
|
||||||
|
|
@ -308,6 +310,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn execute_approve_and_deny_offline() {
|
fn execute_approve_and_deny_offline() {
|
||||||
|
let _env_lock = crate::test_env::lock();
|
||||||
let prev_c = std::env::var("GROKBOY_CONFIRM_AUTO").ok();
|
let prev_c = std::env::var("GROKBOY_CONFIRM_AUTO").ok();
|
||||||
let prev_h = std::env::var("GROKBOY_HANDOFF_AUTO").ok();
|
let prev_h = std::env::var("GROKBOY_HANDOFF_AUTO").ok();
|
||||||
unsafe {
|
unsafe {
|
||||||
|
|
|
||||||
|
|
@ -19,3 +19,17 @@ pub use config::Config;
|
||||||
pub use model::{ChatMessage, FunctionCall, Role, ToolCall, chat_completion, stream_chat};
|
pub use model::{ChatMessage, FunctionCall, Role, ToolCall, chat_completion, stream_chat};
|
||||||
pub use session::{Session, load_or_create, load_session, save_session, sessions_dir};
|
pub use session::{Session, load_or_create, load_session, save_session, sessions_dir};
|
||||||
pub use tools::{ToolContext, execute_tool, is_completion_tool, tool_definitions};
|
pub use tools::{ToolContext, execute_tool, is_completion_tool, tool_definitions};
|
||||||
|
|
||||||
|
/// Serialize tests that mutate process env (CONFIRM_AUTO / HANDOFF_AUTO).
|
||||||
|
#[cfg(test)]
|
||||||
|
pub(crate) mod test_env {
|
||||||
|
use std::sync::{Mutex, MutexGuard, OnceLock};
|
||||||
|
|
||||||
|
pub(crate) fn lock() -> MutexGuard<'static, ()> {
|
||||||
|
static M: OnceLock<Mutex<()>> = OnceLock::new();
|
||||||
|
M.get_or_init(|| Mutex::new(()))
|
||||||
|
.lock()
|
||||||
|
.unwrap_or_else(|e| e.into_inner())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -522,6 +522,7 @@ mod tests {
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn browser_handoff_auto_resume_protocol() {
|
async fn browser_handoff_auto_resume_protocol() {
|
||||||
|
let _env_lock = crate::test_env::lock();
|
||||||
// Offline: with GROKBOY_HANDOFF_AUTO=1, missing Chromium still fail-closes
|
// Offline: with GROKBOY_HANDOFF_AUTO=1, missing Chromium still fail-closes
|
||||||
// OR (if Chromium present) resumes and returns snapshot/error JSON — never hangs.
|
// OR (if Chromium present) resumes and returns snapshot/error JSON — never hangs.
|
||||||
let prev = std::env::var("GROKBOY_HANDOFF_AUTO").ok();
|
let prev = std::env::var("GROKBOY_HANDOFF_AUTO").ok();
|
||||||
|
|
@ -553,6 +554,7 @@ mod tests {
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn request_user_confirm_auto_approve_and_deny() {
|
async fn request_user_confirm_auto_approve_and_deny() {
|
||||||
|
let _env_lock = crate::test_env::lock();
|
||||||
let prev_c = std::env::var("GROKBOY_CONFIRM_AUTO").ok();
|
let prev_c = std::env::var("GROKBOY_CONFIRM_AUTO").ok();
|
||||||
let prev_h = std::env::var("GROKBOY_HANDOFF_AUTO").ok();
|
let prev_h = std::env::var("GROKBOY_HANDOFF_AUTO").ok();
|
||||||
unsafe {
|
unsafe {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue