#!/usr/bin/env bash # usage: devbox run mutation (or tools/mutation.sh inside devbox shell) # Mutation check on a TEMP COPY of server/ + tests/ (the tree is never touched). One mutation per run. # Control must pass; every mutation must fail >=1 expected test; a sed that changes nothing is an error. # a: no +-RayEps rays | b: upper segment end exclusive | c: lower segment end exclusive (rayHit only; # moveBlocked's segsCross is a separate, intentionally inclusive test) | d1/d2: drop arm 1/2 of the shared-vertex fixture. # Log: results/mutation.log cd "$(dirname "$0")/.." || exit 1 mkdir -p results LOG=$PWD/results/mutation.log T=$(mktemp -d); trap 'rm -rf "$T"' EXIT NEW="shared endpoint: no leak at the vertex|'<' apex|every segment endpoint|rays nudged past a corner" D="shared vertex: both arms required" rc=0 : > "$LOG" run() { # $1 id $2 title $3 file (server/geometry.nim | tests/tgeometry.nim) $4 sed script ("" = control) $5 expected-failure regex local id=$1 title=$2 file=$3 sedscr=$4 expect=$5 w=$T/w rm -rf "$w"; mkdir -p "$w"; cp -r server tests nim.cfg "$w"/ find "$w/tests" -maxdepth 1 -type f ! -name '*.nim' -delete { echo "## $id: $title" if [ -n "$sedscr" ]; then sed -i "$sedscr" "$w/$file" if cmp -s "$file" "$w/$file"; then echo "MUTATION $id DID NOT APPLY (sed matched nothing)"; echo "## $id: sed no-op" ; rc=1; return; fi echo "# diff $file -> mutated copy:"; diff "$file" "$w/$file" | sed 's/^/# /' fi } >> "$LOG" local out="$T/out-$id.txt" r F (cd "$w" && nim c -r --hints:off --nimcache:"$T/nc" tests/tgeometry.nim) > "$out" 2>&1; r=$? grep -E '\[(OK|FAILED)\]|Success|Failure|Error' "$out" | sed 's/^ *\.* */ /' >> "$LOG" F=$(grep '\[FAILED\]' "$out" | grep -E "$expect") { echo "# test exit=$r; expected tests failed: $(printf '%s' "$F" | grep -c .)"; [ -n "$F" ] && echo "$F"; echo; } >> "$LOG" local verdict=ok if [ -z "$sedscr" ]; then [ $r -eq 0 ] || { verdict="CONTROL FAILED"; rc=1; } else [ -n "$F" ] || { verdict="SURVIVED"; rc=1; }; fi echo "$id: exit=$r expected_failed=$(printf '%s' "$F" | grep -c .) $verdict" | tee -a "$LOG" } run control "unmutated copy (must pass)" server/geometry.nim "" "" run a "remove the +-RayEps rays" server/geometry.nim '/angles.add ang [-+] RayEps/d' "$NEW" run b "upper segment end exclusive" server/geometry.nim 's/u <= 1 + Eps/u < 1 - Eps/' "$NEW" run c "lower segment end exclusive" server/geometry.nim 's/u >= -Eps/u > Eps/' "$NEW" run d1 "shared-vertex fixture without arm 1" tests/tgeometry.nim 's/@\[arm1, arm2\] *# SHARED-VERTEX/@[arm2]/' "$D" run d2 "shared-vertex fixture without arm 2" tests/tgeometry.nim 's/@\[arm1, arm2\] *# SHARED-VERTEX/@[arm1]/' "$D" echo "exit=$rc" | tee -a "$LOG" exit $rc