check.sh 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #!/usr/bin/env bash
  2. # Run all quality gates for the sm121 launcher (see AGENTS.md and Makefile):
  3. #
  4. # 1. cargo fmt --check (formatting)
  5. # 2. cargo clippy --all-targets -- -D warnings (lints, warnings-as-errors)
  6. # 3. cargo test (unit tests)
  7. # 4. file-size check (no src/**/*.rs > 500 lines)
  8. #
  9. # Fails fast on the first failed gate so devs see one problem at a time.
  10. # Wire into CI by running `./scripts/check.sh`; locally use `make check`.
  11. set -euo pipefail
  12. cd "$(dirname "$0")/.."
  13. # Color output if stderr is a tty.
  14. if [ -t 2 ]; then
  15. RED=$'\033[31m'; GREEN=$'\033[32m'; YELLOW=$'\033[33m'; RESET=$'\033[0m'
  16. else
  17. RED=""; GREEN=""; YELLOW=""; RESET=""
  18. fi
  19. step() { printf '%s==> %s%s\n' "$YELLOW" "$*" "$RESET" >&2; }
  20. ok() { printf '%s ✓ %s%s\n' "$GREEN" "$*" "$RESET" >&2; }
  21. die() { printf '%s ✗ %s%s\n' "$RED" "$*" "$RESET" >&2; exit 1; }
  22. # 1. Formatting
  23. step "cargo fmt --check"
  24. if cargo fmt --check; then
  25. ok "fmt"
  26. else
  27. die "cargo fmt --check failed — run 'cargo fmt' or 'make fmt' to fix"
  28. fi
  29. # 2. Lints (treat warnings as errors)
  30. step "cargo clippy --all-targets -- -D warnings"
  31. if cargo clippy --all-targets -- -D warnings; then
  32. ok "clippy"
  33. else
  34. die "cargo clippy failed"
  35. fi
  36. # 3. Tests — the two Playwright UI suites run in a separate serial leg:
  37. # chromium flakes under the 300+ parallel tests. SM121_RECIPE_GATE_DIR
  38. # points the recipe-contract gate at the shared recipe-repo checkout
  39. # (../recipes) when present (the launcher repo no longer carries recipes/).
  40. gate_dir=""
  41. if [ -d "../recipes" ]; then gate_dir="../recipes"; fi
  42. step "cargo test (non-UI)"
  43. if SM121_RECIPE_GATE_DIR="$gate_dir" cargo test -- --skip playwright_checks; then
  44. ok "test"
  45. else
  46. die "cargo test failed"
  47. fi
  48. step "cargo test (Playwright UI, serial)"
  49. if SM121_RECIPE_GATE_DIR="$gate_dir" cargo test -- --test-threads=1 playwright_checks; then
  50. ok "test (UI)"
  51. else
  52. die "cargo test (Playwright UI) failed"
  53. fi
  54. # 4. File size (AGENTS.md: no src file >500 lines)
  55. step "src/**/*.rs ≤ 500 lines"
  56. max=500
  57. exit_code=0
  58. while IFS= read -r f; do
  59. [ -f "$f" ] || continue
  60. lines=$(wc -l < "$f")
  61. if [ "$lines" -gt "$max" ]; then
  62. printf '%s ✗ %s has %s lines (max %s)%s\n' "$RED" "$f" "$lines" "$max" "$RESET" >&2
  63. exit_code=1
  64. fi
  65. done < <(find src -type f -name '*.rs')
  66. if [ "$exit_code" -eq 0 ]; then
  67. ok "lines"
  68. else
  69. exit 1
  70. fi
  71. echo
  72. printf '%sAll gates passed.%s\n' "$GREEN" "$RESET"