From 063cd77281c821f8ea31bda43361cc4785010e6e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 30 Dec 2025 01:56:50 +0000 Subject: [PATCH] Add test for environment variable presence and absence in setup Co-authored-by: imjasonh <210737+imjasonh@users.noreply.github.com> --- tests/setup_hook.rs | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/tests/setup_hook.rs b/tests/setup_hook.rs index 517a3c7..09354f6 100644 --- a/tests/setup_hook.rs +++ b/tests/setup_hook.rs @@ -173,3 +173,48 @@ exec echo "Should not execute""#; .to_string() .contains("Setup deliberately failed")); } + +#[test] +fn test_setup_env_vars_presence_and_absence() { + let temp_dir = TempDir::new().unwrap(); + let script_path = temp_dir.path().join("env_presence_test.txt"); + + // Test that verifies: + // 1. Variables set in setup ARE available in the test + // 2. Variables NOT set in setup are NOT available in the test + let script_content = if cfg!(windows) { + r#"# Test environment variable presence and absence (Windows) +# Check that SET_VAR is available +exec cmd /c "echo SET_VAR=%SET_VAR%" +stdout "SET_VAR=value_from_setup" + +# Check that UNSET_VAR is not available (should be empty) +exec cmd /c "echo UNSET_VAR=%UNSET_VAR%" +stdout "UNSET_VAR=%UNSET_VAR%""# + } else { + r#"# Test environment variable presence and absence (Unix) +# Check that SET_VAR is available +exec sh -c "echo SET_VAR=$SET_VAR" +stdout "SET_VAR=value_from_setup" + +# Check that UNSET_VAR is not available (should be empty) +exec sh -c "echo UNSET_VAR=${UNSET_VAR:-empty}" +stdout "UNSET_VAR=empty"# + }; + + fs::write(&script_path, script_content).unwrap(); + + // Create RunParams with setup hook that only sets SET_VAR, not UNSET_VAR + let params = RunParams::new().setup(|env| { + env.set_env_var("SET_VAR", "value_from_setup"); + // Deliberately NOT setting UNSET_VAR to verify it's not available + Ok(()) + }); + + let result = run_script(&script_path, ¶ms); + assert!( + result.is_ok(), + "Environment presence/absence test should pass: {:?}", + result + ); +}