#!/usr/bin/env bash # .agent/validate.sh — validation gate for the phased-execution pipeline. # # A phase is only moved to .agent/phases/complete/ if this script exits 0. # Project adaptation (brain_of_reese — AGENTS.md rule 9, PLAN §10): # 1. unit + integration tests with coverage on app/ (floor: >90%) # 2. ruff (lint) # 3. pyright (types) # The per-story Playwright E2E gate (one file per story, run in isolation) # is driven by each task file and is NOT part of this gate. set -uo pipefail cd "$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" rc=0 # ---- 1. unit + integration tests; coverage floor app/ > 90% ---- pytest_out="$(mktemp)" trap 'rm -f "$pytest_out"' EXIT if uv run pytest --cov=app --cov-report=term -q >"$pytest_out" 2>&1; then cat "$pytest_out" total_pct="$(awk '/^TOTAL/ {p = $NF} END {print p}' "$pytest_out" | tr -d '%')" if [[ -n "$total_pct" ]] && awk -v p="$total_pct" 'BEGIN { exit !(p > 90) }'; then echo "coverage gate: app/ ${total_pct}% (>90%) OK" else echo "coverage gate FAILED: app/ coverage ${total_pct:-unknown}% (floor >90%)" rc=1 fi else cat "$pytest_out" echo "tests FAILED: unit + integration suite did not pass" rc=1 fi # ---- 2. lint ---- if ! uv run ruff check .; then rc=1 fi # ---- 3. types ---- if ! uv run pyright; then rc=1 fi if [[ $rc -ne 0 ]]; then echo "validation FAILED (see output above)" else echo "validation OK" fi exit "$rc"