Spaces:
Runtime error
Runtime error
File size: 3,184 Bytes
6aa6081 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | #!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
detect_os() {
case "$(uname -s)" in
MINGW*|MSYS*|CYGWIN*) echo "windows" ;;
Darwin|Linux|*BSD*) echo "unix" ;;
*) echo "unix" ;;
esac
}
OS=$(detect_os)
echo "============================================"
echo " Talos Access — init.sh"
echo " OS: $OS"
echo "============================================"
check_dep() {
local dep="$1"
if ! command -v "$dep" &> /dev/null 2>&1; then
echo "ERROR: Required dependency '$dep' is not installed or not in PATH."
return 1
fi
}
validate_deps() {
local failed=0
echo "[init.sh] Validating dependencies..."
PYTHON=""
for candidate in python3 python; do
if command -v "$candidate" &> /dev/null && "$candidate" --version &> /dev/null; then
PYTHON="$candidate"
break
fi
done
if [ -z "$PYTHON" ]; then
echo "ERROR: A working Python runtime is required."
failed=1
fi
check_dep node || failed=1
check_dep docker || failed=1
if [ "$failed" -ne 0 ]; then
echo "[init.sh] Dependency validation FAILED."
return 1
fi
echo " Python: $($PYTHON --version 2>&1)"
echo " Node: $(node --version 2>&1)"
echo " Docker: $(docker --version 2>&1)"
echo "[init.sh] All dependencies OK."
return 0
}
run_tests() {
local tests_dir="$SCRIPT_DIR/tests"
local overall_exit=0
if [ ! -d "$tests_dir" ]; then
echo "[init.sh] WARNING: tests/ directory not found at $tests_dir"
return 0
fi
echo "[init.sh] Running test suites..."
if [ -n "$PYTHON" ]; then
if "$PYTHON" -m pytest --version &> /dev/null; then
echo "[init.sh] Running pytest..."
"$PYTHON" -m pytest "$tests_dir" -v --tb=short || overall_exit=$?
else
echo "[init.sh] Running Python test scripts (pytest not available)..."
for test_file in "$tests_dir"/*.py; do
if [ -f "$test_file" ]; then
echo " Running: $(basename "$test_file")"
"$PYTHON" "$test_file" || overall_exit=$?
fi
done
fi
fi
for test_script in "$tests_dir"/*.sh; do
if [ -f "$test_script" ] && [ "$(basename "$test_script")" != "init.sh" ]; then
echo " Running: $(basename "$test_script")"
bash "$test_script" || overall_exit=$?
fi
done
if [ "$overall_exit" -eq 0 ]; then
echo "[init.sh] All tests PASSED."
else
echo "[init.sh] Some tests FAILED (exit code: $overall_exit)."
fi
return $overall_exit
}
validate_deps || exit 1
run_tests
exit_code=$?
if [ "$exit_code" -eq 0 ]; then
echo "============================================"
echo " STATUS: ALL TESTS GREEN (exit 0)"
echo "============================================"
else
echo "============================================"
echo " STATUS: TESTS FAILED (exit $exit_code)"
echo "============================================"
fi
exit $exit_code
|