|
| 1 | +#!/bin/bash |
| 2 | +# Run all Hornet tests. Exit code reflects overall pass/fail. |
| 3 | +# |
| 4 | +# Usage: |
| 5 | +# bin/test.sh # run all tests |
| 6 | +# bin/test.sh js # only JS/TS tests |
| 7 | +# bin/test.sh shell # only shell tests |
| 8 | +# |
| 9 | +# Add new test files here — don't scatter test invocations across CI/docs. |
| 10 | + |
| 11 | +set -uo pipefail |
| 12 | +cd "$(dirname "$0")/.." |
| 13 | + |
| 14 | +FILTER="${1:-all}" |
| 15 | +FAILED=0 |
| 16 | +PASSED=0 |
| 17 | +TOTAL=0 |
| 18 | + |
| 19 | +run() { |
| 20 | + local name="$1" |
| 21 | + shift |
| 22 | + TOTAL=$((TOTAL + 1)) |
| 23 | + printf " %-40s " "$name" |
| 24 | + local output="" |
| 25 | + local rc=0 |
| 26 | + output=$("$@" 2>&1) || rc=$? |
| 27 | + if [ "$rc" -eq 0 ]; then |
| 28 | + # Extract test count if available |
| 29 | + count=$(echo "$output" | awk '/ℹ pass [0-9]/ {for(i=1;i<=NF;i++) if($i=="pass") print $(i+1)}' | tail -1) |
| 30 | + if [ -z "$count" ]; then |
| 31 | + count=$(echo "$output" | awk '/[0-9]+ passed/ {for(i=1;i<=NF;i++) if($(i+1)=="passed," || $(i+1)=="passed") print $i}' | tail -1) |
| 32 | + fi |
| 33 | + if [ -n "$count" ]; then |
| 34 | + echo "✓ ($count tests)" |
| 35 | + else |
| 36 | + echo "✓" |
| 37 | + fi |
| 38 | + PASSED=$((PASSED + 1)) |
| 39 | + else |
| 40 | + echo "✗ FAILED (exit $rc)" |
| 41 | + echo "$output" | tail -20 | sed 's/^/ /' |
| 42 | + FAILED=$((FAILED + 1)) |
| 43 | + fi |
| 44 | +} |
| 45 | + |
| 46 | +echo "=== Hornet Tests ===" |
| 47 | +echo "" |
| 48 | + |
| 49 | +if [ "$FILTER" = "all" ] || [ "$FILTER" = "js" ]; then |
| 50 | + echo "JS/TS:" |
| 51 | + run "tool-guard" node --test pi/extensions/tool-guard.test.mjs |
| 52 | + run "bridge security" node --test slack-bridge/security.test.mjs |
| 53 | + run "extension scanner" node --test bin/scan-extensions.test.mjs |
| 54 | + echo "" |
| 55 | +fi |
| 56 | + |
| 57 | +if [ "$FILTER" = "all" ] || [ "$FILTER" = "shell" ]; then |
| 58 | + echo "Shell:" |
| 59 | + run "safe-bash wrapper" bash bin/hornet-safe-bash.test.sh |
| 60 | + run "log redaction" bash bin/redact-logs.test.sh |
| 61 | + echo "" |
| 62 | +fi |
| 63 | + |
| 64 | +echo "=== $PASSED/$TOTAL passed, $FAILED failed ===" |
| 65 | + |
| 66 | +if [ "$FAILED" -gt 0 ]; then |
| 67 | + exit 1 |
| 68 | +fi |
0 commit comments