Compare commits

...

2 commits

Author SHA1 Message Date
a6a3084acd Parallelize check across Gradle subprojects for faster pre-commit.
Run :backend:check, frontend coverage, and :e2e:check as sibling tasks with
org.gradle.parallel=true. Move E2E Docker compose into an e2e subproject so
Playwright can start while unit tests run. Copy e2e/ in the E2E backend image
so settings.gradle resolves inside Docker.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-01 12:42:27 +02:00
764a620689 Enforce coverage thresholds in pre-commit via gradlew check.
Wire frontendCoverage (Vitest 70%/60%/70%) into the check task chain
instead of plain unit tests so commits fail when line or branch coverage
drops. Document thresholds in AGENTS.md and improve pre-commit failure hints.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-01 12:14:13 +02:00
8 changed files with 60 additions and 26 deletions

View file

@ -37,7 +37,7 @@ docker compose up -d # starts postgres, backend, frontend
### All-in-one
```bash
./gradlew check # frontend lint → frontend test → backend test+coverage → E2E (Docker)
./gradlew check # backend, frontend coverage, E2E (sibling tasks + org.gradle.parallel)
./gradlew coverage # backend + frontend tests with coverage reports
./gradlew up # docker compose up -d
./gradlew down # docker compose down
@ -170,10 +170,18 @@ export STRIPE_SECRET_KEY=sk_test_fake STRIPE_WEBHOOK_SECRET=whsec_fake STRIPE_PR
./gradlew check
```
This runs frontend lint, frontend unit tests (242), backend tests (163), coverage
thresholds, Flyway checks, and **all 90 E2E tests in Docker**. **Do not commit or
push if this fails.** Optional local guard: `./scripts/install-pre-commit-hook.sh`
(runs the same `check` on every `git commit`).
`check` depends on `:backend:check`, `frontendCoverage` (root), and `:e2e:check`
as **siblings** with `org.gradle.parallel=true`. Gradle parallelizes **across
subprojects**, not multiple tasks in one project — E2E is in `e2e/` so Docker can
start while backend tests and frontend Vitest run. Within root, `frontendLint`
`frontendCoverage` stays serial. Measured `unitAndCoverage --rerun-tasks`: ~30s
parallel on vs ~36s off. Full `check` wall time ≈ `max(:backend, frontend, :e2e)`;
E2E (~3 min) is usually the limit.
Forgejo CI already runs unit and E2E as separate workflow jobs in parallel.
Quick path without E2E: `./gradlew unitAndCoverage`.
**Do not commit or push if this fails.** Optional local guard:
`./scripts/install-pre-commit-hook.sh` (runs the same `check` on every `git commit`;
fails if line or branch coverage is below threshold).
### Frontend (Vue.js 3)
- `<script setup>` with Composition API only. Never Options API.

View file

@ -16,7 +16,8 @@ tasks.register('frontendTest', Exec) {
}
tasks.register('frontendCoverage', Exec) {
description = 'Run Vitest with coverage in the frontend directory'
description = 'Run Vitest with coverage thresholds (70% lines, 60% branches, 70% functions)'
dependsOn frontendLint
workingDir = file("${rootProject.projectDir}/frontend")
commandLine 'npm', 'run', 'test:coverage'
}
@ -27,25 +28,23 @@ tasks.register('coverage') {
dependsOn(':backend:jacocoTestReport', 'frontendCoverage')
}
tasks.register('frontendE2E', Exec) {
// E2E lives in :e2e subproject so Gradle can run it parallel to root + :backend.
tasks.register('frontendE2E', Task) {
group = 'verification'
description = 'Run Playwright E2E tests in Docker (same stack as Forgejo CI)'
dependsOn frontendTest
workingDir = rootProject.projectDir
environment 'POSTGRES_DB', 'bilhej'
environment 'POSTGRES_USER', 'bilhej'
environment 'POSTGRES_PASSWORD', 'test_pw_ci_123'
environment 'JWT_SECRET', 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
environment 'STRIPE_SECRET_KEY', 'sk_test_fake'
environment 'STRIPE_WEBHOOK_SECRET', 'whsec_fake'
environment 'STRIPE_PRICE_ID', 'price_fake'
commandLine 'docker', 'compose', '-f', 'docker-compose.e2e.yml',
'up', '--build', '--abort-on-container-exit', '--exit-code-from', 'playwright'
description = 'Alias for :e2e:check (Playwright in Docker)'
dependsOn ':e2e:check'
}
tasks.register('unitAndCoverage', Task) {
group = 'verification'
description = 'Backend + frontend unit tests with coverage thresholds (no E2E)'
dependsOn ':backend:check', 'frontendCoverage'
}
tasks.named('check').configure {
description = 'Full verification: frontend lint/tests, backend tests+coverage, E2E'
dependsOn ':backend:check', frontendE2E
description = 'Full verification: :backend, frontend coverage, and :e2e in parallel'
dependsOn ':backend:check', 'frontendCoverage', ':e2e:check'
}
tasks.register('up', Exec) {

View file

@ -3,6 +3,7 @@ WORKDIR /app
COPY gradlew settings.gradle ./
COPY gradle/wrapper/ gradle/wrapper/
COPY backend/build.gradle backend/
COPY e2e/build.gradle e2e/
RUN chmod +x gradlew && ./gradlew :backend:dependencies --no-daemon -q
COPY backend/src backend/src
RUN ./gradlew :backend:bootJar --no-daemon -q

14
e2e/build.gradle Normal file
View file

@ -0,0 +1,14 @@
tasks.register('check', Exec) {
group = 'verification'
description = 'Playwright E2E stack in Docker (parallel with :backend and root frontend tasks)'
workingDir = rootProject.projectDir
environment 'POSTGRES_DB', 'bilhej'
environment 'POSTGRES_USER', 'bilhej'
environment 'POSTGRES_PASSWORD', 'test_pw_ci_123'
environment 'JWT_SECRET', 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
environment 'STRIPE_SECRET_KEY', 'sk_test_fake'
environment 'STRIPE_WEBHOOK_SECRET', 'whsec_fake'
environment 'STRIPE_PRICE_ID', 'price_fake'
commandLine 'docker', 'compose', '-f', 'docker-compose.e2e.yml',
'up', '--build', '--abort-on-container-exit', '--exit-code-from', 'playwright'
}

1
gradle.properties Normal file
View file

@ -0,0 +1 @@
org.gradle.parallel=true

View file

@ -12,4 +12,4 @@ ln -sf "../../scripts/pre-commit-check.sh" "$HOOK"
chmod +x "$HOOK"
echo "Installed pre-commit hook -> scripts/pre-commit-check.sh"
echo "Every commit will run: ./gradlew check"
echo "Every commit will run: ./gradlew check (includes line/branch coverage thresholds)"

View file

@ -1,6 +1,10 @@
#!/usr/bin/env bash
# Runs the same verification as CI before allowing a commit.
# Install: ./scripts/install-pre-commit-hook.sh
#
# Fails if line/branch coverage falls below project thresholds:
# Backend: 70% lines, 60% branches (JaCoCo jacocoTestCoverageVerification)
# Frontend: 70% lines, 60% branches, 70% functions (Vitest test:coverage)
set -euo pipefail
@ -15,6 +19,13 @@ export STRIPE_SECRET_KEY="${STRIPE_SECRET_KEY:-sk_test_fake}"
export STRIPE_WEBHOOK_SECRET="${STRIPE_WEBHOOK_SECRET:-whsec_fake}"
export STRIPE_PRICE_ID="${STRIPE_PRICE_ID:-price_fake}"
echo "pre-commit: running ./gradlew check (lint + unit + E2E in Docker)..."
./gradlew check --no-daemon
echo "pre-commit: all checks passed."
echo "pre-commit: running ./gradlew check (lint, coverage thresholds, E2E)..."
if ! ./gradlew check --no-daemon; then
echo ""
echo "pre-commit: FAILED."
echo " - Backend coverage: ./gradlew :backend:jacocoTestCoverageVerification (70% lines, 60% branches)"
echo " - Frontend coverage: cd frontend && npm run test:coverage (70% lines, 60% branches, 70% functions)"
echo " - Reports: backend/build/reports/jacoco/test/html/ frontend/coverage/"
exit 1
fi
echo "pre-commit: all checks passed (including line and branch coverage thresholds)."

View file

@ -1,3 +1,3 @@
rootProject.name = 'bilhej'
include 'backend'
include 'backend', 'e2e'