Something went wrong. Try again.
An agentic programming framework for people that don't trust an AI agent
Something went wrong. Try again.
6.0 kB · 136 lines
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137#!/usr/bin/env bash# red-check — confirm the test suite is genuinely RED before implementation,# and that the new tests actually live inside the project's own suite.## Phase 2's discipline is "failing tests first." This makes it a deterministic# gate instead of taking the oracle-author's word: it RUNS the suite and requires# that it does NOT pass. A suite that passes with no implementation means the# tests don't actually exercise the missing behavior — a vacuous red.## It also flags the difference between FAILURES (assertions failing — the right# kind of red) and ERRORS (import/collection/syntax — the wrong kind, the test# is broken, not the feature missing), best-effort per stack.## Given test paths, it first asserts the project's OWN default test run collects# them. Writing tests into a fresh file beside the suite is a real and common# failure: they pass review, then never run in CI. Note the check deliberately# runs collection with NO path argument — pointing the runner straight at a file# would collect it even when the project's configuration never would.## Auto-detects the stack. Override with an executable `.skepticism/red-check.sh`,# which receives the same test paths as arguments — an override that ignores them# opts out of the collection check, so honour them if the project has a way to.## Usage: red-check [test-path...] (repo-relative paths)## Exit codes:# 0 valid RED — suite fails due to test failures (proceed)# 1 NOT RED — suite passes (tests don't test the missing behavior)# 2 BROKEN RED — suite errors (import/collection/syntax) — fix the tests# 3 unknown — could not detect a runner# 4 NOT COLLECTED — the given tests are outside the project's own suiteset -uo pipefail
if [[ -x ".skepticism/red-check.sh" ]]; then exec ./.skepticism/red-check.sh "$@"fi
have() { command -v "$1" >/dev/null 2>&1; }ERROR_RE='(ImportError|ModuleNotFoundError|SyntaxError|collection error|errors during collection|Cannot find module|cannot find name|no such file|compilation (error|failed)|error\[E[0-9]|undefined reference)'
# Repo-relative test paths to verify, normalized (./x → x).NEW_TESTS=()for arg in "$@"; do NEW_TESTS+=("${arg#./}"); done
not_collected() { # <runner> <listing> <missing...> local runner="$1" listing="$2"; shift 2 echo echo "red-check: NOT COLLECTED — the project's own ${runner} run does not pick up:" printf ' ✗ %s\n' "$@" echo echo "These tests are outside the suite the project actually runs, so CI would" echo "never execute them. Move them into the existing layout (project.md records" echo "the conventions) rather than adding a file beside the suite." echo echo "What ${runner} does collect:" printf '%s\n' "$listing" | head -n 30 exit 4}
# Assert every path in NEW_TESTS appears in the runner's own collection listing.assert_collected() { # <runner> <listing> local runner="$1" listing="$2" p local missing=() for p in "${NEW_TESTS[@]}"; do printf '%s\n' "$listing" | grep -qF "$p" || missing+=("$p") done if [[ "${#missing[@]}" -gt 0 ]]; then not_collected "$runner" "$listing" "${missing[@]}" fi echo " ✓ collection: all ${#NEW_TESTS[@]} new test path(s) are in the project's ${runner} suite" echo}
# Run a test command; classify the result.classify() { # <label> <cmd...> local label="$1"; shift echo "──► ${label}: $*" local out rc out="$("$@" 2>&1)"; rc=$? echo "$out" | tail -n 40 echo if [[ $rc -eq 0 ]]; then echo "red-check: NOT RED — '${label}' passed with no implementation." echo "Your tests do not exercise the missing behavior. Fix the tests." exit 1 fi if echo "$out" | grep -Eiq "$ERROR_RE"; then echo "red-check: BROKEN RED — '${label}' errored (import/collection/syntax)," echo "not a clean assertion failure. The tests are broken, not the feature." exit 2 fi echo "red-check: valid RED — '${label}' fails on assertions, as it should." exit 0}
# --- Node / TS --------------------------------------------------------------if [[ -f package.json ]]; then if have pnpm && [[ -f pnpm-lock.yaml ]]; then PM=pnpm elif have yarn && [[ -f yarn.lock ]]; then PM=yarn elif have npm; then PM=npm; fi if [[ -n "${PM:-}" ]] && node -e "process.exit(require('./package.json').scripts?.test?0:1)" 2>/dev/null; then if [[ "${#NEW_TESTS[@]}" -gt 0 ]]; then echo "──► collection: $PM test -- --listTests" if listing="$("$PM" test -- --listTests 2>&1)" ; then assert_collected "$PM test" "$listing" else echo " ~ inconclusive: this runner does not support --listTests." echo " Verify by hand that the new tests are in the project's testMatch." echo fi fi classify "test" "$PM" test fifi# --- Python -----------------------------------------------------------------if have pytest && { [[ -f pyproject.toml || -f setup.cfg ]] || ls -1 test_*.py *_test.py tests/ >/dev/null 2>&1; }; then if [[ "${#NEW_TESTS[@]}" -gt 0 ]]; then echo "──► collection: pytest --collect-only -q (project default, no path given)" listing="$(pytest --collect-only -q 2>&1)" assert_collected "pytest" "$listing" fi classify "pytest" pytest -qfi# --- Rust -------------------------------------------------------------------if [[ -f Cargo.toml ]] && have cargo; then [[ "${#NEW_TESTS[@]}" -gt 0 ]] && echo " ✓ collection: cargo collects every #[test] in the crate by construction" classify "cargo test" cargo testfi# --- Go ---------------------------------------------------------------------if [[ -f go.mod ]] && have go; then [[ "${#NEW_TESTS[@]}" -gt 0 ]] && echo " ✓ collection: go test ./... collects every _test.go in the module by construction" classify "go test" go test ./...fi
echo "red-check: could not detect a test runner. Add .skepticism/red-check.sh."exit 3