From 87fe7ec9b0852a98662e4c532d1e103871783c8c Mon Sep 17 00:00:00 2001 From: Prithvi Chandra Surya Date: Fri, 13 Nov 2026 12:03:57 +0000 Subject: [PATCH] fix: exit non-zero from makestudy and makedocker on failure makestudy and makedocker ended their error paths with a bare `exit`, which returns the status of the preceding `echo`, so they exited 0 when the graphml was missing, the study directory already existed, or no arguments were given. makedocker's "already exists" branch had no exit at all. They now exit 1 on these paths. --- makedocker | 5 +-- makestudy | 6 ++-- tests/test_makestudy_exit_codes.py | 50 ++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 5 deletions(-) create mode 100644 tests/test_makestudy_exit_codes.py diff --git a/makedocker b/makedocker index 049c51bb..9424fbb5 100755 --- a/makedocker +++ b/makedocker @@ -7,7 +7,7 @@ then echo "In the first case, the name of the study is the same as the name of the .graphml" echo "In either case, source files come from the same path as the .graphml" echo "The equivalent mkconcore.py is displayed" - exit + exit 1 fi graphml=$1 if [ -e $graphml ] @@ -20,7 +20,7 @@ else sourcedir=$(dirname "$graphml") else echo "$graphml does not exist" - exit + exit 1 fi fi if [ $# = 1 ] @@ -33,6 +33,7 @@ if [ -e $studydir ] then echo "cannot make $studydir because one already exists with that name" echo "either do ./destroy $studydir, or choose a unique name as 2nd arg" + exit 1 else echo "python3 mkconcore.py $graphml $sourcedir $studydir docker" python3 mkconcore.py $graphml $sourcedir $studydir docker diff --git a/makestudy b/makestudy index cc017507..f3ec5836 100755 --- a/makestudy +++ b/makestudy @@ -7,7 +7,7 @@ if [ "$#" -eq 0 ]; then echo "In the first case, the name of the study is the same as the name of the .graphml" echo "In either case, source files come from the same path as the .graphml" echo "The equivalent mkconcore.py is displayed" - exit + exit 1 fi graphml="$1" @@ -20,7 +20,7 @@ else sourcedir="$(dirname "$graphml")" else echo "$graphml does not exist" - exit + exit 1 fi fi @@ -34,7 +34,7 @@ fi if [ -e "$studydir" ]; then echo "Cannot make $studydir because one already exists with that name" echo "Either do ./destroy $studydir, or choose a unique name as 2nd arg" - exit + exit 1 else if command -v osascript >/dev/null; then echo "python3 mkconcore.py \"$graphml\" \"$sourcedir\" \"$studydir\" macos" diff --git a/tests/test_makestudy_exit_codes.py b/tests/test_makestudy_exit_codes.py new file mode 100644 index 00000000..6d44e53e --- /dev/null +++ b/tests/test_makestudy_exit_codes.py @@ -0,0 +1,50 @@ +"""makestudy and makedocker must exit non-zero when they fail. + +The FRI server (fri/server/main.py) runs them with subprocess.check_output and +only reports an error on a non-zero exit code, so exiting 0 after a failure +made the editor report "Directory successfully created". +""" + +import subprocess +import sys +from pathlib import Path + +import pytest + +REPO = Path(__file__).resolve().parents[1] +SCRIPTS = ["makestudy", "makedocker"] + +pytestmark = pytest.mark.skipif( + sys.platform == "win32", reason="makestudy and makedocker are bash scripts" +) + + +def _run(script, *args): + return subprocess.run( + ["bash", str(REPO / script), *args], + cwd=REPO, + capture_output=True, + text=True, + ) + + +@pytest.mark.parametrize("script", SCRIPTS) +def test_no_arguments_exits_nonzero(script): + result = _run(script) + assert result.returncode != 0 + assert "Make a concore study" in result.stdout + + +@pytest.mark.parametrize("script", SCRIPTS) +def test_missing_graphml_exits_nonzero(script): + result = _run(script, "demo/does_not_exist") + assert result.returncode != 0 + assert "does not exist" in result.stdout + + +@pytest.mark.parametrize("script", SCRIPTS) +def test_existing_study_dir_exits_nonzero(script, tmp_path): + result = _run(script, "demo/sample.graphml", str(tmp_path)) + assert result.returncode != 0 + assert "already exists" in result.stdout + assert list(tmp_path.iterdir()) == []