#!/usr/bin/env bash # Single entry point for all project checks (local and CI). # # Usage: # scripts/test.sh [main|game|frontend|all] [--install] # # main - main-server: db:prepare, rubocop, bundler-audit, brakeman, rspec # game - game-server: gofmt check, go vet, go test -race # frontend - frontend: npm ci (if needed), npm run build, npm test (if present) # all - all of the above (default) # # --install - force `npm ci` even if node_modules already exists # # Requirements: Ruby (bundle), Go, Node/npm; Redis on localhost:6379 for main. set -euo pipefail ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" TARGET="all" INSTALL="no" for arg in "$@"; do case "$arg" in main | game | frontend | all) TARGET="$arg" ;; --install) INSTALL="yes" ;; -h | --help) sed -n '2,14p' "$0" | sed 's/^# \{0,1\}//' exit 0 ;; *) echo "Unknown argument: $arg (see --help)" >&2 exit 2 ;; esac done log() { printf '\n\033[1;35m==> %s\033[0m\n' "$*"; } ok() { printf '\033[1;32m ok: %s\033[0m\n' "$*"; } die() { printf '\033[1;31mERROR: %s\033[0m\n' "$*" >&2 exit 1 } require_redis() { command -v redis-cli >/dev/null 2>&1 || die "redis-cli not found; install Redis" redis-cli -n 15 ping >/dev/null 2>&1 || die "Redis is not reachable on localhost:6379 (start it with: redis-server)" } main_server() { cd "$ROOT/main-server" require_redis log "main-server: dependencies" bundle check >/dev/null 2>&1 || bundle install log "main-server: db:prepare (test)" RAILS_ENV=test bundle exec rails db:prepare log "main-server: rubocop" bundle exec rubocop log "main-server: bundler-audit" bundle exec bundler-audit check --update log "main-server: brakeman" # config/brakeman.ignore holds one documented exception (Ruby2Shell on # Ruby 4.0.0); --ensure-ignore-notes keeps every entry justified. bundle exec brakeman --quiet --no-pager --exit-on-warn --exit-on-error --ensure-ignore-notes log "main-server: rspec" bundle exec rspec } game_server() { cd "$ROOT/game-server" log "game-server: gofmt" unformatted="$(gofmt -l .)" [ -z "$unformatted" ] || die "gofmt: these files are not formatted: $unformatted" log "game-server: go vet" go vet ./... log "game-server: go test -race" go test -race ./... } frontend() { cd "$ROOT/frontend" if [ "$INSTALL" = "yes" ] || [ ! -d node_modules ]; then log "frontend: npm ci" npm ci else log "frontend: dependencies already installed (use --install to refresh)" fi log "frontend: build" npm run build has_test="$(node -e "process.stdout.write(require('./package.json').scripts?.test ? 'yes' : 'no')")" if [ "$has_test" = "yes" ]; then log "frontend: npm test" npm test else log "frontend: no npm test script; build is the only automated check (see AGENTS.md)" fi } case "$TARGET" in main) main_server ;; game) game_server ;; frontend) frontend ;; all) main_server game_server frontend ;; esac log "done: $TARGET"