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
+45 -42
View File
@@ -5,37 +5,31 @@
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/Logging.sh" 2>/dev/null || echo "Warning: Logging.sh not found"
source "$PROJECT_ROOT/Framework-Includes/PrettyPrint.sh" 2>/dev/null || echo "Warning: PrettyPrint.sh not found"
source "$PROJECT_ROOT/Framework-Includes/ErrorHandling.sh" 2>/dev/null || echo "Warning: ErrorHandling.sh not found"
# Source framework functions from the vendored KNELShellFramework
FRAMEWORK_INCLUDES="$PROJECT_ROOT/vendor/git@git.knownelement.com/29418/KNEL/KNELShellFramework/Framework-Includes"
source "$FRAMEWORK_INCLUDES/Logging.sh" 2>/dev/null || echo "Warning: Logging.sh not found"
source "$FRAMEWORK_INCLUDES/PrettyPrint.sh" 2>/dev/null || echo "Warning: PrettyPrint.sh not found"
source "$FRAMEWORK_INCLUDES/ErrorHandling.sh" 2>/dev/null || echo "Warning: ErrorHandling.sh not found"
function test_logging_functions() {
echo "🔍 Testing logging functions..."
local test_log="/tmp/test-log-$$"
# Test if logging functions exist and work
if command -v log_info >/dev/null 2>&1; then
log_info "Test info message" 2>/dev/null || true
echo "✅ log_info function exists"
function test_logging_variables() {
echo "🔍 Testing logging variables..."
if [[ -n "${CURRENT_TIMESTAMP:-}" ]]; then
echo "✅ CURRENT_TIMESTAMP is set"
else
echo "❌ log_info function missing"
echo "❌ CURRENT_TIMESTAMP is not set"
return 1
fi
if command -v log_error >/dev/null 2>&1; then
log_error "Test error message" 2>/dev/null || true
echo "✅ log_error function exists"
if [[ -n "${LOGFILENAME:-}" ]]; then
echo "✅ LOGFILENAME is set"
else
echo "❌ log_error function missing"
echo "❌ LOGFILENAME is not set"
return 1
fi
# Cleanup
rm -f "$test_log"
return 0
}
@@ -59,14 +53,6 @@ function test_pretty_print_functions() {
return 1
fi
if command -v print_success >/dev/null 2>&1; then
print_success "Test success message" >/dev/null 2>&1 || true
echo "✅ print_success function exists"
else
echo "❌ print_success function missing"
return 1
fi
return 0
}
@@ -74,10 +60,17 @@ function test_error_handling() {
echo "🔍 Testing error handling..."
# Test if error handling functions exist
if command -v handle_error >/dev/null 2>&1; then
echo "✅ handle_error function exists"
if command -v error_out >/dev/null 2>&1; then
echo "✅ error_out function exists"
else
echo "❌ handle_error function missing"
echo "❌ error_out function missing"
return 1
fi
if command -v handle_failure >/dev/null 2>&1; then
echo "✅ handle_failure function exists"
else
echo "❌ handle_failure function missing"
return 1
fi
@@ -112,11 +105,11 @@ function test_framework_includes_exist() {
local missing_files=0
for include_file in "${required_includes[@]}"; do
if [[ -f "$PROJECT_ROOT/Framework-Includes/$include_file" ]]; then
if [[ -f "$FRAMEWORK_INCLUDES/$include_file" ]]; then
echo "✅ Framework include exists: $include_file"
else
echo "❌ Framework include missing: $include_file"
((missing_files++))
((++missing_files))
fi
done
@@ -127,18 +120,28 @@ function test_syntax_validation() {
echo "🔍 Testing script syntax validation..."
local syntax_errors=0
local script_dirs=("Framework-Includes" "Project-Includes" "ProjectCode")
local script_dirs=(
"$FRAMEWORK_INCLUDES"
"$PROJECT_ROOT/Project-Includes"
"$PROJECT_ROOT/ProjectCode"
)
for dir in "${script_dirs[@]}"; do
if [[ -d "$PROJECT_ROOT/$dir" ]]; then
if [[ -d "$dir" ]]; then
while IFS= read -r -d '' file; do
# Skip files that aren't bash scripts despite a .sh extension (e.g. PHP agents)
local shebang
shebang="$(head -c 32 "$file" 2>/dev/null)"
case "$shebang" in
*php*|*python*|*perl*) continue ;;
esac
if bash -n "$file" 2>/dev/null; then
echo "✅ Syntax valid: $(basename "$file")"
else
echo "❌ Syntax error in: $(basename "$file")"
((syntax_errors++))
((++syntax_errors))
fi
done < <(find "$PROJECT_ROOT/$dir" -name "*.sh" -type f -print0)
done < <(find "$dir" -name "*.sh" -type f -print0)
fi
done
@@ -154,7 +157,7 @@ function main() {
# Run all unit tests
test_framework_includes_exist || ((total_failures++))
test_logging_functions || ((total_failures++))
test_logging_variables || ((total_failures++))
test_pretty_print_functions || ((total_failures++))
test_error_handling || ((total_failures++))
test_syntax_validation || ((total_failures++))