From 193bac1c6138ce102a6cecb4be52e8faac7abfa2 Mon Sep 17 00:00:00 2001 From: Zaz Brown Date: Sat, 11 Apr 2026 16:16:10 +0000 Subject: [PATCH 1/2] fix: don't close user's terminal on invalid platform Use `return 1` instead of `exit 1` so that sourcing the script with an invalid platform prints the error without killing the shell. Fixes #305 --- uv_env_setup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/uv_env_setup.sh b/uv_env_setup.sh index 820a2bc81..d49d86fac 100644 --- a/uv_env_setup.sh +++ b/uv_env_setup.sh @@ -30,7 +30,7 @@ elif [ "$PLATFORM" == "cu121" ]; then PYG_URL="https://data.pyg.org/whl/torch-${TORCH_VER}+cu121.html" else echo "❌ Error: Invalid platform '$PLATFORM'. Use: cpu, cu118, or cu121." - exit 1 + return 1 2>/dev/null || exit 1 fi echo "⚙️ Updating pyproject.toml..." From 02bcc2c5333748ede324625627eb5e9f025c4543 Mon Sep 17 00:00:00 2001 From: Zaz Brown Date: Sat, 11 Apr 2026 18:05:19 +0000 Subject: [PATCH 2/2] test: regression test for #305 Verify that `source uv_env_setup.sh INVALID` does not kill the user's shell (uses return instead of exit). --- test/test_uv_env_setup.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 test/test_uv_env_setup.py diff --git a/test/test_uv_env_setup.py b/test/test_uv_env_setup.py new file mode 100644 index 000000000..6ef79e1b9 --- /dev/null +++ b/test/test_uv_env_setup.py @@ -0,0 +1,26 @@ +"""Tests for uv_env_setup.sh error handling.""" + +import subprocess +from pathlib import Path + + +def test_source_invalid_platform_does_not_kill_shell(): + """Verify sourcing with invalid platform does not kill the shell. + + If the script uses bare `exit 1`, sourcing it kills the shell + (subshell exits). If it uses `return 1`, the subshell survives + and the sentinel `STILL_ALIVE` is printed. + """ + script = Path(__file__).parents[1] / "uv_env_setup.sh" + result = subprocess.run( + [ + "bash", + "-c", + f"source {script} INVALID 2>/dev/null; echo STILL_ALIVE", + ], + capture_output=True, + text=True, + ) + assert "STILL_ALIVE" in result.stdout, ( + "Shell was killed by `exit 1` instead of `return 1`" + )