diff --git a/scripts/ci/infrastructure/health-check.sh b/scripts/ci/infrastructure/health-check.sh index 68aaaca3..d5079896 100755 --- a/scripts/ci/infrastructure/health-check.sh +++ b/scripts/ci/infrastructure/health-check.sh @@ -53,18 +53,7 @@ fi log_info "Checking database connectivity..." cd "$PROJECT_ROOT/api/callcentersite" -DJANGO_READY=true -if ! python3 -c "import django" >/dev/null 2>&1; then - DJANGO_READY=false - log_warn "Skipping Django checks: Django is not installed in the current environment" - CHECKS_SKIPPED=$((CHECKS_SKIPPED + 1)) -elif [ ! -f "manage.py" ]; then - DJANGO_READY=false - log_warn "Skipping Django checks: manage.py not found" - CHECKS_SKIPPED=$((CHECKS_SKIPPED + 1)) -fi - -if [ "$DJANGO_READY" = true ]; then +if [ -f "manage.py" ]; then if DB_CHECK_OUTPUT=$(python3 manage.py check --database default 2>&1); then log_info "Database connectivity: OK" CHECKS_PASSED=$((CHECKS_PASSED + 1)) @@ -76,19 +65,17 @@ if [ "$DJANGO_READY" = true ]; then CHECKS_FAILED=$((CHECKS_FAILED + 1)) fi - log_info "Checking Django configuration..." - if DJANGO_CHECK_OUTPUT=$(python3 manage.py check 2>&1); then - log_info "Django configuration: OK" - CHECKS_PASSED=$((CHECKS_PASSED + 1)) - else - log_error "Django configuration check failed" - echo "$DJANGO_CHECK_OUTPUT" | tail -n 20 | while IFS= read -r line; do - log_error " $line" - done - CHECKS_FAILED=$((CHECKS_FAILED + 1)) - fi +# Check 4: Django configuration +log_info "Checking Django configuration..." +if DJANGO_CHECK_OUTPUT=$(python3 manage.py check 2>&1); then + log_info "Django configuration: OK" + CHECKS_PASSED=$((CHECKS_PASSED + 1)) else - log_warn "Skipping Django checks due to missing prerequisites" + log_error "Django configuration check failed" + echo "$DJANGO_CHECK_OUTPUT" | tail -n 20 | while IFS= read -r line; do + log_error " $line" + done + CHECKS_FAILED=$((CHECKS_FAILED + 1)) fi # Check 5: Required directories exist diff --git a/scripts/ci/run-all-checks.sh b/scripts/ci/run-all-checks.sh index c0bc4b50..9099a5ba 100755 --- a/scripts/ci/run-all-checks.sh +++ b/scripts/ci/run-all-checks.sh @@ -11,7 +11,8 @@ # 0 - All checks passed # 1 - One or more checks failed -set -euo pipefail +set -u +set -o pipefail RED='\033[0;31m' GREEN='\033[0;32m' diff --git a/scripts/tests/test_ci_shell_scripts.py b/scripts/tests/test_ci_shell_scripts.py index 6c6bd5a2..14d966d1 100644 --- a/scripts/tests/test_ci_shell_scripts.py +++ b/scripts/tests/test_ci_shell_scripts.py @@ -16,25 +16,17 @@ def _run_script(script_path, *args): ) -def test_run_all_checks_reports_summary_with_skips(): +def test_run_all_checks_reports_summary_even_on_failure(): result = _run_script(RUN_ALL_CHECKS) - assert result.returncode == 0, "Aggregated checks should degrade to success with skips locally" + assert result.returncode != 0, "Expected the aggregated checks to fail in the default dev environment" combined_output = f"{result.stdout}\\n{result.stderr}" assert "FINAL CI/CD REPORT" in combined_output - assert "Skipped:" in combined_output - assert "[SKIP]" in combined_output or "Skipped: 0" in combined_output -def test_health_check_degrades_gracefully_when_django_missing(): +def test_health_check_surfaces_underlying_error_details(): result = _run_script(HEALTH_CHECK) - assert result.returncode in (0, 2), "Health check should pass or skip when Django is unavailable" + assert result.returncode != 0, "The health check should fail when dependencies are missing" combined_output = f"{result.stdout}\\n{result.stderr}" - assert "Skipping Django checks" in combined_output - - -def test_run_all_checks_sets_strict_shell_flags(): - contents = RUN_ALL_CHECKS.read_text() - - assert "set -euo pipefail" in contents, "run-all-checks.sh must opt into strict shell error handling" + assert "ModuleNotFoundError" in combined_output or "No module named" in combined_output