Skip to content

Commit 79fa0ac

Browse files
authored
tests: add c8 coverage thresholds for JS tests (#47)
1 parent 27c05ef commit 79fa0ac

File tree

6 files changed

+617
-18
lines changed

6 files changed

+617
-18
lines changed

.c8rc.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"all": false,
3+
"include": [
4+
"slack-bridge/security.mjs",
5+
"control-plane/server.mjs",
6+
"bin/scan-extensions.mjs"
7+
],
8+
"exclude": [
9+
"**/*.test.mjs",
10+
"**/node_modules/**"
11+
],
12+
"reporter": ["text", "lcov"],
13+
"check-coverage": true,
14+
"lines": 50,
15+
"functions": 50,
16+
"branches": 40,
17+
"statements": 50
18+
}

.github/workflows/ci.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,15 @@ jobs:
4141

4242
- name: Install dependencies
4343
run: |
44+
npm ci
4445
cd slack-bridge && npm ci
4546
cd ../control-plane && npm ci
4647
47-
- name: Run all tests
48-
run: bin/test.sh
48+
- name: Run JS tests with coverage
49+
run: npm run test:coverage
50+
51+
- name: Run shell tests
52+
run: bin/test.sh shell
4953

5054
# security-audit.sh checks live system state (running services, firewall,
5155
# /proc mounts) that doesn't exist in CI. Run it locally instead:

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
*.key
33
*.pem
44
node_modules/
5-
node_modules/
65
# Slack bridge
76
slack-bridge/node_modules/
87
slack-bridge/.env
98
.pi/
9+
# Coverage
10+
coverage/
11+
.c8_output/

bin/test.sh

Lines changed: 54 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
# Run all Baudbot tests. Exit code reflects overall pass/fail.
33
#
44
# 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
89
#
910
# Add new test files here — don't scatter test invocations across CI/docs.
1011

@@ -43,25 +44,64 @@ run() {
4344
fi
4445
}
4546

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+
)
4856

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() {
5067
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
5771
echo ""
58-
fi
72+
}
5973

60-
if [ "$FILTER" = "all" ] || [ "$FILTER" = "shell" ]; then
74+
run_shell_tests() {
6175
echo "Shell:"
6276
run "safe-bash wrapper" bash bin/baudbot-safe-bash.test.sh
6377
run "log redaction" bash bin/redact-logs.test.sh
6478
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
65105
fi
66106

67107
echo "=== $PASSED/$TOTAL passed, $FAILED failed ==="

0 commit comments

Comments
 (0)