|
2 | 2 | # Run all Baudbot tests. Exit code reflects overall pass/fail. |
3 | 3 | # |
4 | 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 |
| 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 | +# bin/test.sh coverage # JS tests with coverage report + thresholds |
8 | 9 | # |
9 | 10 | # Add new test files here — don't scatter test invocations across CI/docs. |
10 | 11 |
|
@@ -43,25 +44,64 @@ run() { |
43 | 44 | fi |
44 | 45 | } |
45 | 46 |
|
46 | | -echo "=== Baudbot Tests ===" |
47 | | -echo "" |
| 47 | +# ── JS test file list (used for both normal runs and coverage) ─────────── |
| 48 | +JS_TEST_FILES=( |
| 49 | + pi/extensions/tool-guard.test.mjs |
| 50 | + pi/extensions/heartbeat.test.mjs |
| 51 | + pi/extensions/memory.test.mjs |
| 52 | + slack-bridge/security.test.mjs |
| 53 | + bin/scan-extensions.test.mjs |
| 54 | + control-plane/server.test.mjs |
| 55 | +) |
48 | 56 |
|
49 | | -if [ "$FILTER" = "all" ] || [ "$FILTER" = "js" ]; then |
| 57 | +JS_TEST_NAMES=( |
| 58 | + "tool-guard" |
| 59 | + "heartbeat" |
| 60 | + "memory" |
| 61 | + "bridge security" |
| 62 | + "extension scanner" |
| 63 | + "control-plane" |
| 64 | +) |
| 65 | + |
| 66 | +run_js_tests() { |
50 | 67 | echo "JS/TS:" |
51 | | - run "tool-guard" node --test pi/extensions/tool-guard.test.mjs |
52 | | - run "heartbeat" node --test pi/extensions/heartbeat.test.mjs |
53 | | - run "memory" node --test pi/extensions/memory.test.mjs |
54 | | - run "bridge security" node --test slack-bridge/security.test.mjs |
55 | | - run "extension scanner" node --test bin/scan-extensions.test.mjs |
56 | | - run "control-plane" node --test control-plane/server.test.mjs |
| 68 | + for i in "${!JS_TEST_FILES[@]}"; do |
| 69 | + run "${JS_TEST_NAMES[$i]}" node --test "${JS_TEST_FILES[$i]}" |
| 70 | + done |
57 | 71 | echo "" |
58 | | -fi |
| 72 | +} |
59 | 73 |
|
60 | | -if [ "$FILTER" = "all" ] || [ "$FILTER" = "shell" ]; then |
| 74 | +run_shell_tests() { |
61 | 75 | echo "Shell:" |
62 | 76 | run "safe-bash wrapper" bash bin/baudbot-safe-bash.test.sh |
63 | 77 | run "log redaction" bash bin/redact-logs.test.sh |
64 | 78 | echo "" |
| 79 | +} |
| 80 | + |
| 81 | +# ── Coverage mode ──────────────────────────────────────────────────────── |
| 82 | +if [ "$FILTER" = "coverage" ]; then |
| 83 | + echo "=== Baudbot Tests (with coverage) ===" |
| 84 | + echo "" |
| 85 | + |
| 86 | + if ! command -v npx &>/dev/null; then |
| 87 | + echo "Error: npx not found — install Node.js" >&2 |
| 88 | + exit 1 |
| 89 | + fi |
| 90 | + |
| 91 | + npx c8 node --test "${JS_TEST_FILES[@]}" |
| 92 | + exit $? |
| 93 | +fi |
| 94 | + |
| 95 | +# ── Normal mode ────────────────────────────────────────────────────────── |
| 96 | +echo "=== Baudbot Tests ===" |
| 97 | +echo "" |
| 98 | + |
| 99 | +if [ "$FILTER" = "all" ] || [ "$FILTER" = "js" ]; then |
| 100 | + run_js_tests |
| 101 | +fi |
| 102 | + |
| 103 | +if [ "$FILTER" = "all" ] || [ "$FILTER" = "shell" ]; then |
| 104 | + run_shell_tests |
65 | 105 | fi |
66 | 106 |
|
67 | 107 | echo "=== $PASSED/$TOTAL passed, $FAILED failed ===" |
|
0 commit comments