cortex
aien-dev/cortex
Brought by drakestapleton
cortex / tests / parity / mutant.sh
| 1 | #!/bin/sh |
| 2 | # tests/parity/mutant.sh : negative control for the parity gate (spec/PARITY.md). |
| 3 | # sh tests/parity/mutant.sh SRC.db |
| 4 | # Builds a mutant server whose LIKE-fallback score in o_search_row is 0.71 instead of 0.7, runs the |
| 5 | # full gate against it with scratch work/evidence directories, and expects the gate to FAIL. |
| 6 | # Writes $MUTANT_EVIDENCE/mutant.txt (default evidence/parity). Exit 0 only when the mutant is caught |
| 7 | # (gate rc 1 with at least one FAIL record), 1 when it survives, 2 on a setup error. |
| 8 | set -u |
| 9 | SRC=${1:?usage: mutant.sh SRC.db} |
| 10 | R=$(cd "$(dirname "$0")/../.." && pwd) |
| 11 | M=${MUTANT_WORK:-$R/build/mutant} |
| 12 | EV=${MUTANT_EVIDENCE:-$R/evidence/parity} |
| 13 | mkdir -p "$EV" |
| 14 | [ -s "$R/build/cortex.unit.om" ] || { echo "mutant: build first (sh build.sh)" >&2; exit 2; } |
| 15 | OMC=$(sh "$R/tools/omc.sh") || exit 2 |
| 16 | rm -rf "$M" && mkdir -p "$M/ev" |
| 17 | # the one mutation: the first `s = 0.7` after `fn o_search_row` in the server unit |
| 18 | awk 'BEGIN{n=0} /^fn o_search_row/{f=1} f && n==0 && $0=="s = 0.7" {print "s = 0.71"; n=1; next} {print} END{if(n!=1) exit 3}' \ |
| 19 | "$R/build/cortex.unit.om" > "$M/cortex.unit.om" || { echo "mutant: site not found" >&2; exit 2; } |
| 20 | CHG=$(diff "$R/build/cortex.unit.om" "$M/cortex.unit.om" | grep -c '^[<>]') |
| 21 | [ "$CHG" -eq 2 ] || { echo "mutant: expected one changed line, got $CHG diff lines" >&2; exit 2; } |
| 22 | "$OMC" < "$M/cortex.unit.om" > "$M/cortex" 2> "$M/cortex.err" |
| 23 | if [ $? -ne 0 ] || [ -s "$M/cortex.err" ]; then echo "mutant: compile failed: $(cat "$M/cortex.err")" >&2; exit 2; fi |
| 24 | chmod +x "$M/cortex" |
| 25 | CORTEX_BIN=$M/cortex PARITY_WORK=$M/work PARITY_EVIDENCE=$M/ev sh "$R/tests/parity/run.sh" "$SRC" > "$M/run.log" 2>&1 |
| 26 | GRC=$? |
| 27 | NF=$(grep -c '^FAIL ' "$M/ev/report.txt" 2>/dev/null) |
| 28 | NF=${NF:-0} |
| 29 | { |
| 30 | echo "parity mutant $(date -u +%Y-%m-%dT%H:%M:%SZ)" |
| 31 | echo "mutation o_search_row LIKE score s = 0.7 -> s = 0.71 (one line of build/cortex.unit.om)" |
| 32 | echo "mutant sha256 $(sha256sum < "$M/cortex" | cut -c1-64)" |
| 33 | echo "gate rc $GRC (expected 1)" |
| 34 | grep '^TOTAL' "$M/ev/report.txt" |
| 35 | echo "failing classes (records):" |
| 36 | grep '^FAIL ' "$M/ev/report.txt" | awk '{print $3}' | sort | uniq -c |
| 37 | echo "first FAIL lines:" |
| 38 | grep '^FAIL ' "$M/ev/report.txt" | head -5 |
| 39 | } > "$EV/mutant.txt" |
| 40 | if [ "$GRC" -eq 1 ] && [ "$NF" -gt 0 ]; then |
| 41 | echo "MUTANT CAUGHT" >> "$EV/mutant.txt"; cat "$EV/mutant.txt"; exit 0 |
| 42 | fi |
| 43 | echo "MUTANT SURVIVED" >> "$EV/mutant.txt"; cat "$EV/mutant.txt"; exit 1 |