make tests pass cleanly in sandbox (#4067)
This changes the reqwest client used in tests to be sandbox-friendly, and skips a bunch of other tests that don't work inside the sandbox/without network.
This commit is contained in:
@@ -128,20 +128,56 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
pub fn sandbox_env_var() -> &'static str {
|
||||
codex_core::spawn::CODEX_SANDBOX_ENV_VAR
|
||||
}
|
||||
|
||||
pub fn sandbox_network_env_var() -> &'static str {
|
||||
codex_core::spawn::CODEX_SANDBOX_NETWORK_DISABLED_ENV_VAR
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! non_sandbox_test {
|
||||
// For tests that return ()
|
||||
macro_rules! skip_if_sandbox {
|
||||
() => {{
|
||||
if ::std::env::var("CODEX_SANDBOX_NETWORK_DISABLED").is_ok() {
|
||||
println!("Skipping test because it cannot execute when network is disabled in a Codex sandbox.");
|
||||
if ::std::env::var($crate::sandbox_env_var())
|
||||
== ::core::result::Result::Ok("seatbelt".to_string())
|
||||
{
|
||||
eprintln!(
|
||||
"{} is set to 'seatbelt', skipping test.",
|
||||
$crate::sandbox_env_var()
|
||||
);
|
||||
return;
|
||||
}
|
||||
}};
|
||||
// For tests that return Result<(), _>
|
||||
(result $(,)?) => {{
|
||||
if ::std::env::var("CODEX_SANDBOX_NETWORK_DISABLED").is_ok() {
|
||||
println!("Skipping test because it cannot execute when network is disabled in a Codex sandbox.");
|
||||
return ::core::result::Result::Ok(());
|
||||
($return_value:expr $(,)?) => {{
|
||||
if ::std::env::var($crate::sandbox_env_var())
|
||||
== ::core::result::Result::Ok("seatbelt".to_string())
|
||||
{
|
||||
eprintln!(
|
||||
"{} is set to 'seatbelt', skipping test.",
|
||||
$crate::sandbox_env_var()
|
||||
);
|
||||
return $return_value;
|
||||
}
|
||||
}};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! skip_if_no_network {
|
||||
() => {{
|
||||
if ::std::env::var($crate::sandbox_network_env_var()).is_ok() {
|
||||
println!(
|
||||
"Skipping test because it cannot execute when network is disabled in a Codex sandbox."
|
||||
);
|
||||
return;
|
||||
}
|
||||
}};
|
||||
($return_value:expr $(,)?) => {{
|
||||
if ::std::env::var($crate::sandbox_network_env_var()).is_ok() {
|
||||
println!(
|
||||
"Skipping test because it cannot execute when network is disabled in a Codex sandbox."
|
||||
);
|
||||
return $return_value;
|
||||
}
|
||||
}};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user