#!/usr/bin/env bash # Run all quality gates for the sm121 launcher (see AGENTS.md and Makefile): # # 1. cargo fmt --check (formatting) # 2. cargo clippy --all-targets -- -D warnings (lints, warnings-as-errors) # 3. cargo test (unit tests) # 4. file-size check (no src/**/*.rs > 500 lines) # # Fails fast on the first failed gate so devs see one problem at a time. # Wire into CI by running `./scripts/check.sh`; locally use `make check`. set -euo pipefail cd "$(dirname "$0")/.." # Color output if stderr is a tty. if [ -t 2 ]; then RED=$'\033[31m'; GREEN=$'\033[32m'; YELLOW=$'\033[33m'; RESET=$'\033[0m' else RED=""; GREEN=""; YELLOW=""; RESET="" fi step() { printf '%s==> %s%s\n' "$YELLOW" "$*" "$RESET" >&2; } ok() { printf '%s ✓ %s%s\n' "$GREEN" "$*" "$RESET" >&2; } die() { printf '%s ✗ %s%s\n' "$RED" "$*" "$RESET" >&2; exit 1; } # 1. Formatting step "cargo fmt --check" if cargo fmt --check; then ok "fmt" else die "cargo fmt --check failed — run 'cargo fmt' or 'make fmt' to fix" fi # 2. Lints (treat warnings as errors) step "cargo clippy --all-targets -- -D warnings" if cargo clippy --all-targets -- -D warnings; then ok "clippy" else die "cargo clippy failed" fi # 3. Tests — the two Playwright UI suites run in a separate serial leg: # chromium flakes under the 300+ parallel tests. SM121_RECIPE_GATE_DIR # points the recipe-contract gate at the shared recipe-repo checkout # (../recipes) when present (the launcher repo no longer carries recipes/). gate_dir="" if [ -d "../recipes" ]; then gate_dir="../recipes"; fi step "cargo test (non-UI)" if SM121_RECIPE_GATE_DIR="$gate_dir" cargo test -- --skip playwright_checks; then ok "test" else die "cargo test failed" fi step "cargo test (Playwright UI, serial)" if SM121_RECIPE_GATE_DIR="$gate_dir" cargo test -- --test-threads=1 playwright_checks; then ok "test (UI)" else die "cargo test (Playwright UI) failed" fi # 4. File size (AGENTS.md: no src file >500 lines) step "src/**/*.rs ≤ 500 lines" max=500 exit_code=0 while IFS= read -r f; do [ -f "$f" ] || continue lines=$(wc -l < "$f") if [ "$lines" -gt "$max" ]; then printf '%s ✗ %s has %s lines (max %s)%s\n' "$RED" "$f" "$lines" "$max" "$RESET" >&2 exit_code=1 fi done < <(find src -type f -name '*.rs') if [ "$exit_code" -eq 0 ]; then ok "lines" else exit 1 fi echo printf '%sAll gates passed.%s\n' "$GREEN" "$RESET"