#!/usr/bin/env bash
# Runs the project's own "RLS coverage (mechanical)" block against a schema with
# one extra migration (the mutation). Needs a checkout of the private WayClub
# repository at 65a18ff with dependencies installed; prints the vitest summary.
set -uo pipefail
REPO=$1; MUT=$2; OUT=$3
cp "$MUT" "$REPO/infra/postgres/migrations/999_mutation.sql"
( cd "$REPO" && DATABASE_PORT=${PGPORT_EXP:-55499} ./node_modules/.bin/vitest run infra/postgres/tests/wayclub-db.test.mjs -t "RLS coverage" ) > "$OUT" 2>&1
rm -f "$REPO/infra/postgres/migrations/999_mutation.sql"
grep -E "✓|×|Tests " "$OUT"
