fix(tests): repair framework paths, assertions, and arithmetic

The test suite referenced a Framework-Includes/ directory that does not
exist at the repo root (it is vendored under vendor/.../KNELShellFramework),
and asserted against functions the framework does not export.

- Point all tests at the vendored framework includes via a resolved
  FRAMEWORK_INCLUDES path
- Add print_success/print_warning/print_header shims where the vendored
  PrettyPrint only defines print_info/print_error
- Replace log_info/handle_error assertions with the real API:
  CURRENT_TIMESTAMP/LOGFILENAME variables and error_out/handle_failure
- Fix ((var++)) under set -e (returns 1 when var is 0) by using ((++var))
  across system-requirements, https-enforcement, 2fa-validation, and
  safe-download
- Fix infinite recursion in safe-download test_network_connectivity
  (was calling itself instead of the framework function)
- Make syntax validation shebang-aware so PHP agents (mysql.sh) are
  skipped instead of flagged as bash syntax errors

Framework unit test now passes (exit 0).

🤖 Generated with [Crush](https://github.com/charmassociates/crush)

Assisted-by: GLM-5 via Crush <crush@charm.land>
This commit is contained in:
Charles N Wyble
2026-07-25 13:49:47 -05:00
parent 688b7190e6
commit 5928d96aec
6 changed files with 117 additions and 97 deletions
+26 -19
View File
@@ -5,15 +5,22 @@
set -euo pipefail
PROJECT_ROOT="$(dirname "$(realpath "${BASH_SOURCE[0]}")")/../.."
PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
# Source framework functions
source "$PROJECT_ROOT/Framework-Includes/SafeDownload.sh"
# Source framework functions from the vendored KNELShellFramework
FRAMEWORK_INCLUDES="$PROJECT_ROOT/vendor/git@git.knownelement.com/29418/KNEL/KNELShellFramework/Framework-Includes"
# The vendored PrettyPrint only defines print_info/print_error, but SafeDownload.sh
# calls print_success/print_warning; define lightweight shims before sourcing.
function print_success() { echo "$1"; }
function print_warning() { echo "⚠️ $1"; }
source "$FRAMEWORK_INCLUDES/SafeDownload.sh"
function test_network_connectivity() {
echo "🔍 Testing network connectivity..."
if test_network_connectivity; then
if check_url_accessibility "https://github.com"; then
echo "✅ Network connectivity test passed"
return 0
else
@@ -37,7 +44,7 @@ function test_url_accessibility() {
echo "✅ URL accessible: $url"
else
echo "❌ URL not accessible: $url"
((failed++))
((++failed))
fi
done
@@ -60,20 +67,20 @@ function test_safe_download() {
echo "✅ Downloaded file exists and has content"
else
echo "❌ Downloaded file is missing or empty"
((failed++))
((++failed))
fi
# Cleanup
rm -f "$test_dest"
else
echo "❌ Safe download failed"
((failed++))
((++failed))
fi
# Test download with invalid URL
if safe_download "https://invalid.example.com/nonexistent" "/tmp/test-invalid-$$" 2>/dev/null; then
echo "❌ Invalid URL download should have failed"
((failed++))
((++failed))
else
echo "✅ Invalid URL download failed as expected"
fi
@@ -97,13 +104,13 @@ function test_checksum_verification() {
echo "✅ Correct checksum verification passed"
else
echo "❌ Correct checksum verification failed"
((failed++))
((++failed))
fi
# Test incorrect checksum
if verify_checksum "$test_file" "invalid_checksum" 2>/dev/null; then
echo "❌ Incorrect checksum should have failed"
((failed++))
((++failed))
else
echo "✅ Incorrect checksum verification failed as expected"
fi
@@ -111,7 +118,7 @@ function test_checksum_verification() {
# Test missing file
if verify_checksum "/tmp/nonexistent-file-$$" "$expected_checksum" 2>/dev/null; then
echo "❌ Missing file checksum should have failed"
((failed++))
((++failed))
else
echo "✅ Missing file checksum verification failed as expected"
fi
@@ -143,7 +150,7 @@ function test_batch_download() {
echo "✅ Batch file downloaded: $(basename "$file")"
else
echo "❌ Batch file missing: $(basename "$file")"
((failed++))
((++failed))
fi
done
@@ -153,7 +160,7 @@ function test_batch_download() {
done
else
echo "❌ Batch download failed"
((failed++))
((++failed))
fi
return $failed
@@ -172,7 +179,7 @@ function test_config_backup_and_restore() {
# Test safe config download (this will fail with invalid URL, triggering restore)
if safe_config_download "https://invalid.example.com/config" "$test_config" ".test-backup" 2>/dev/null; then
echo "❌ Invalid config download should have failed"
((failed++))
((++failed))
else
echo "✅ Invalid config download failed as expected"
@@ -181,7 +188,7 @@ function test_config_backup_and_restore() {
echo "✅ Original config was restored after failed download"
else
echo "❌ Original config was not restored properly"
((failed++))
((++failed))
fi
fi
@@ -199,14 +206,14 @@ function test_download_error_handling() {
# Test download with missing parameters
if safe_download "" "/tmp/test" 2>/dev/null; then
echo "❌ Download with empty URL should have failed"
((failed++))
((++failed))
else
echo "✅ Download with empty URL failed as expected"
fi
if safe_download "https://example.com" "" 2>/dev/null; then
echo "❌ Download with empty destination should have failed"
((failed++))
((++failed))
else
echo "✅ Download with empty destination failed as expected"
fi
@@ -214,7 +221,7 @@ function test_download_error_handling() {
# Test download to read-only location (should fail)
if safe_download "https://github.com" "/test-readonly-$$" 2>/dev/null; then
echo "❌ Download to read-only location should have failed"
((failed++))
((++failed))
else
echo "✅ Download to read-only location failed as expected"
fi