Skip to content

Check_tests

FieldValue
TypeSkill Resource
Source~/.copilot/skills/quality/scripts/check_tests.sh
DescriptionNot specified

Source Content

#!/usr/bin/env bash
# House checks for test hygiene: no committed .skip/.only, and a coverage
# threshold configured somewhere.
#
# The skip/only check is the one hard-fail gate (exit 1). The coverage-config
# check is advisory only (warning) since the absence of a recognized config
# file is ambiguous — projects may configure coverage elsewhere.
#
# Usage: check_tests.sh [TARGET_PATH] (standalone — scans a directory)
# check_tests.sh FILE [FILE ...] (lint.py dispatch — scans exactly these files)
# TARGET_PATH defaults to "." when no args given.
set -uo pipefail
fail=0
warn() { printf '⚠️ %s\n' "$1"; }
error() { printf '❌ %s\n' "$1"; fail=1; }
ok() { printf '✅ %s\n' "$1"; }
if [[ "$#" -eq 0 ]]; then
TARGET="."
elif [[ "$#" -eq 1 && -d "$1" ]]; then
TARGET="$1"
else
# One or more file args (the lint.py dispatch case) — every arg must be a
# real file, since this mode skips the directory `find` entirely.
for f in "$@"; do
if [[ ! -f "$f" ]]; then
echo "Usage: $0 [TARGET_PATH] | FILE [FILE ...]" >&2
echo "error: '$f' is not a file" >&2
exit 2
fi
done
TARGET=""
fi
echo "== house rule: no .skip( or .only( in test files =="
if [[ -n "$TARGET" ]]; then
mapfile -t TEST_FILES < <(find "$TARGET" -type f \
\( -name '*.test.ts' -o -name '*.test.tsx' -o -name '*.spec.ts' -o -name '*.spec.tsx' \) \
-not -path '*/node_modules/*' \
2>/dev/null)
else
TEST_FILES=("$@")
fi
if [[ "${#TEST_FILES[@]}" -gt 0 ]]; then
skip_only_hits=$(grep -nE '\.(skip|only)\(' "${TEST_FILES[@]}" 2>/dev/null || true)
if [[ -n "$skip_only_hits" ]]; then
error "found .skip( or .only( in test files — these must not be committed:"
echo "$skip_only_hits"
else
ok "no .skip( or .only( found in ${#TEST_FILES[@]} test files"
fi
else
ok "no test files found (*.test.ts(x) / *.spec.ts(x)) — skipping"
fi
echo
echo "== advisory: coverage threshold configured =="
coverage_found=0
# This check is inherently directory-scoped (a config file lives at a repo
# root, not "at" any one test file) — in file-list dispatch mode, scan from
# cwd instead of skipping the check entirely.
cfg_root="${TARGET:-.}"
mapfile -t VITEST_CFG < <(find "$cfg_root" -maxdepth 2 -name 'vitest.config.*' -not -path '*/node_modules/*' 2>/dev/null)
mapfile -t JEST_CFG < <(find "$cfg_root" -maxdepth 2 -name 'jest.config.*' -not -path '*/node_modules/*' 2>/dev/null)
if [[ "${#VITEST_CFG[@]}" -gt 0 ]] && grep -q 'coverage' "${VITEST_CFG[@]}" 2>/dev/null; then
ok "coverage config found in ${VITEST_CFG[*]}"
coverage_found=1
fi
if [[ "${#JEST_CFG[@]}" -gt 0 ]] && grep -q 'coverageThreshold' "${JEST_CFG[@]}" 2>/dev/null; then
ok "coverageThreshold found in ${JEST_CFG[*]}"
coverage_found=1
fi
pkg_json="$cfg_root/package.json"
if [[ -f "$pkg_json" ]] && grep -q '"jest"' "$pkg_json" 2>/dev/null && grep -q 'coverageThreshold' "$pkg_json" 2>/dev/null; then
ok "coverageThreshold found in package.json \"jest\" key"
coverage_found=1
fi
if [[ "$coverage_found" -eq 0 ]]; then
warn "no coverage threshold config found (vitest.config.*, jest.config.*, or package.json 'jest' key) — advisory only, not a hard failure"
fi
echo
if [[ "$fail" -eq 0 ]]; then
echo "All checks passed."
else
echo "One or more checks failed — see ❌ lines above."
fi
exit "$fail"