Skip to content

Commit 33db18e

Browse files
committed
ci: test-count-floor actions for frontend + backend
Same safety net as the parser-side one. Two new workflows: - test-count-floor-frontend.yml: floor = 173 passing tests. Triggers on any PR/push touching frontend/** or the workflow file. - test-count-floor-backend.yml: floor = 289 passing tests. Triggers on any PR/push touching backend/** or the workflow file. Each reads its own .test-count-baseline.json from the respective package root. Both fail loudly if the passing-test count drops below the committed floor, and instruct contributors to restore the missing tests rather than bump the baseline down. Only an ordpool core maintainer is authorised to lower a floor (by editing the baseline file and committing that edit as an explicit decision). Companion to ordpool-parser/.github/workflows/test-count-floor.yml (restored on commit 172f87e). All three workflows together form the org-wide net against accidental test deletion.
1 parent b1ada72 commit 33db18e

4 files changed

Lines changed: 198 additions & 0 deletions

File tree

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# Fails the build LOUDLY when the count of passing backend tests drops
2+
# below the committed baseline. Only an ordpool core maintainer is allowed
3+
# to lower the baseline (by editing backend/.test-count-baseline.json
4+
# and committing the edit explicitly). Every other change that reduces
5+
# test count is treated as an accident and rejected.
6+
#
7+
# Companion to the parser-side and frontend-side workflows. Same safety
8+
# net, different jest target. See workspace CLAUDE.md HARD RULE
9+
# 'Never delete a passing test without explicit permission' for context.
10+
11+
name: Test Count Floor (backend)
12+
13+
on:
14+
pull_request:
15+
paths:
16+
- 'backend/**'
17+
- '.github/workflows/test-count-floor-backend.yml'
18+
push:
19+
branches: [main, stage_prod, stage_test]
20+
paths:
21+
- 'backend/**'
22+
- '.github/workflows/test-count-floor-backend.yml'
23+
24+
jobs:
25+
26+
test-count-floor-backend:
27+
28+
runs-on: ubuntu-latest
29+
30+
steps:
31+
- uses: actions/checkout@v5
32+
33+
- uses: actions/setup-node@v6
34+
with:
35+
node-version: 24
36+
cache: 'npm'
37+
cache-dependency-path: backend/package-lock.json
38+
39+
- name: Install dependencies
40+
working-directory: backend
41+
run: npm ci
42+
43+
- name: Run jest and capture output
44+
working-directory: backend
45+
run: NODE_OPTIONS='--no-deprecation' ./node_modules/.bin/jest 2>&1 | tee jest-output.log
46+
47+
- name: Enforce test-count floor
48+
working-directory: backend
49+
run: |
50+
set -euo pipefail
51+
52+
# Backend runs a single jest config (node). Parse the 'N passed'
53+
# field out of jest's summary line:
54+
# Tests: 289 passed, 289 total
55+
CURRENT=$(grep -E '^Tests:' jest-output.log \
56+
| sed -E 's/.*[, ]([0-9]+) passed.*/\1/' \
57+
| awk '{ s += $1 } END { print s }')
58+
59+
if [ -z "$CURRENT" ] || [ "$CURRENT" = "0" ]; then
60+
echo "::error::Could not extract a passing-tests count from jest output."
61+
echo "First 50 lines of captured log:"
62+
head -50 jest-output.log
63+
exit 1
64+
fi
65+
66+
BASELINE=$(jq -r '.passing' .test-count-baseline.json)
67+
if [ -z "$BASELINE" ] || [ "$BASELINE" = "null" ]; then
68+
echo "::error::backend/.test-count-baseline.json is missing 'passing' field."
69+
exit 1
70+
fi
71+
72+
echo "Current passing tests: $CURRENT"
73+
echo "Committed baseline: $BASELINE"
74+
75+
if [ "$CURRENT" -lt "$BASELINE" ]; then
76+
echo "::error::BACKEND TEST COVERAGE DROPPED. Current passing tests ($CURRENT) is below the committed floor ($BASELINE)."
77+
echo ""
78+
echo "Only an ordpool core maintainer is authorised to lower the test"
79+
echo "floor. Reducing the baseline requires editing"
80+
echo "backend/.test-count-baseline.json and committing that edit as"
81+
echo "an explicit, reviewed decision."
82+
echo ""
83+
echo "If you got here by accident (deleted a test, broke a fixture,"
84+
echo "merged a stale branch) -- restore the missing tests instead."
85+
echo ""
86+
echo "Detected diff: $((BASELINE - CURRENT)) tests missing."
87+
exit 1
88+
fi
89+
90+
if [ "$CURRENT" -gt "$BASELINE" ]; then
91+
echo "::notice::Backend test count grew (+$((CURRENT - BASELINE)) since baseline)."
92+
echo "Consider bumping backend/.test-count-baseline.json to lock in the gain."
93+
else
94+
echo "Backend test count matches baseline exactly. All good."
95+
fi
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# Fails the build LOUDLY when the count of passing frontend tests drops
2+
# below the committed baseline. Only an ordpool core maintainer is allowed
3+
# to lower the baseline (by editing frontend/.test-count-baseline.json
4+
# and committing the edit explicitly). Every other change that reduces
5+
# test count is treated as an accident and rejected.
6+
#
7+
# Companion to the parser-side workflow in ordpool-parser. Same safety
8+
# net, different jest target. See workspace CLAUDE.md HARD RULE
9+
# 'Never delete a passing test without explicit permission' for context.
10+
11+
name: Test Count Floor (frontend)
12+
13+
on:
14+
pull_request:
15+
paths:
16+
- 'frontend/**'
17+
- '.github/workflows/test-count-floor-frontend.yml'
18+
push:
19+
branches: [main, stage_prod, stage_test]
20+
paths:
21+
- 'frontend/**'
22+
- '.github/workflows/test-count-floor-frontend.yml'
23+
24+
jobs:
25+
26+
test-count-floor-frontend:
27+
28+
runs-on: ubuntu-latest
29+
30+
steps:
31+
- uses: actions/checkout@v5
32+
33+
- uses: actions/setup-node@v6
34+
with:
35+
node-version: 24
36+
cache: 'npm'
37+
cache-dependency-path: frontend/package-lock.json
38+
39+
- name: Install dependencies
40+
working-directory: frontend
41+
run: npm ci
42+
43+
- name: Run jest and capture output
44+
working-directory: frontend
45+
run: NODE_OPTIONS='--no-deprecation' ./node_modules/.bin/jest --config jest.config.js 2>&1 | tee jest-output.log
46+
47+
- name: Enforce test-count floor
48+
working-directory: frontend
49+
run: |
50+
set -euo pipefail
51+
52+
# Frontend runs a single jest config (jsdom), so there's just one
53+
# 'Tests:' summary line. Parse the 'N passed' field out of it.
54+
# Tests: 1 skipped, 173 passed, 174 total
55+
CURRENT=$(grep -E '^Tests:' jest-output.log \
56+
| sed -E 's/.*[, ]([0-9]+) passed.*/\1/' \
57+
| awk '{ s += $1 } END { print s }')
58+
59+
if [ -z "$CURRENT" ] || [ "$CURRENT" = "0" ]; then
60+
echo "::error::Could not extract a passing-tests count from jest output."
61+
echo "First 50 lines of captured log:"
62+
head -50 jest-output.log
63+
exit 1
64+
fi
65+
66+
BASELINE=$(jq -r '.passing' .test-count-baseline.json)
67+
if [ -z "$BASELINE" ] || [ "$BASELINE" = "null" ]; then
68+
echo "::error::frontend/.test-count-baseline.json is missing 'passing' field."
69+
exit 1
70+
fi
71+
72+
echo "Current passing tests: $CURRENT"
73+
echo "Committed baseline: $BASELINE"
74+
75+
if [ "$CURRENT" -lt "$BASELINE" ]; then
76+
echo "::error::FRONTEND TEST COVERAGE DROPPED. Current passing tests ($CURRENT) is below the committed floor ($BASELINE)."
77+
echo ""
78+
echo "Only an ordpool core maintainer is authorised to lower the test"
79+
echo "floor. Reducing the baseline requires editing"
80+
echo "frontend/.test-count-baseline.json and committing that edit as"
81+
echo "an explicit, reviewed decision."
82+
echo ""
83+
echo "If you got here by accident (deleted a test, broke a fixture,"
84+
echo "merged a stale branch) -- restore the missing tests instead."
85+
echo ""
86+
echo "Detected diff: $((BASELINE - CURRENT)) tests missing."
87+
exit 1
88+
fi
89+
90+
if [ "$CURRENT" -gt "$BASELINE" ]; then
91+
echo "::notice::Frontend test count grew (+$((CURRENT - BASELINE)) since baseline)."
92+
echo "Consider bumping frontend/.test-count-baseline.json to lock in the gain."
93+
else
94+
echo "Frontend test count matches baseline exactly. All good."
95+
fi

backend/.test-count-baseline.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"passing": 289,
3+
"note": "Floor for .github/workflows/test-count-floor-backend.yml. Count of passing tests from the single jest config (node). Only an ordpool core maintainer is authorised to lower this number; every other change that reduces test count is treated as an accident and rejected. To raise the floor after legitimately adding tests, bump this value and commit. See also workspace CLAUDE.md, HARD RULE 'Never delete a passing test without explicit permission'."
4+
}

frontend/.test-count-baseline.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"passing": 173,
3+
"note": "Floor for .github/workflows/test-count-floor-frontend.yml. Count of passing tests from the single jest config (jsdom). Only an ordpool core maintainer is authorised to lower this number; every other change that reduces test count is treated as an accident and rejected. To raise the floor after legitimately adding tests, bump this value and commit. See also workspace CLAUDE.md, HARD RULE 'Never delete a passing test without explicit permission'."
4+
}

0 commit comments

Comments
 (0)