cortex
aien-dev/cortex
Brought by drakestapleton
cortex / tests / brain / mutant.sh
| 1 | #!/bin/sh |
| 2 | # tests/brain/mutant.sh : negative controls for the Company Brain gate (tests/brain/run.sh). |
| 3 | # sh tests/brain/mutant.sh |
| 4 | # Each mutant (thirteen, listed below) changes exactly one line of build/cortex.unit.om inside one function |
| 5 | # of om/brain.om (or, for the last three, of the incremental FTS index in om/fts.om), |
| 6 | # is compiled with the pinned omc and run through the whole brain gate on its own port and scratch |
| 7 | # directories. Every mutant must be caught: gate rc 1 with at least one FAIL line. Writes |
| 8 | # $BRAIN_EVIDENCE/mutants.txt (default build/brain). Exit 0 only when every mutant is caught, |
| 9 | # 1 when one survives, 2 on a setup error. |
| 10 | set -u |
| 11 | R=$(cd "$(dirname "$0")/../.." && pwd) |
| 12 | M=${BRAIN_MUTANT_WORK:-$R/build/brain-mutant} |
| 13 | EV=${BRAIN_EVIDENCE:-$R/build/brain} |
| 14 | PORT=${BRAIN_MUTANT_PORT:-18233} |
| 15 | mkdir -p "$EV" |
| 16 | [ -s "$R/build/cortex.unit.om" ] || { echo "brain mutant: build first (sh build.sh)" >&2; exit 2; } |
| 17 | OMC=$(sh "$R/tools/omc.sh") || exit 2 |
| 18 | rm -rf "$M" && mkdir -p "$M" |
| 19 | out=$EV/mutants.txt |
| 20 | echo "brain mutants $(date -u +%Y-%m-%dT%H:%M:%SZ), base unit sha256 $(sha256sum < "$R/build/cortex.unit.om" | cut -c1-64)" > "$out" |
| 21 | survived=0 |
| 22 | errors=0 |
| 23 | # NAME|FUNCTION|LINE|REPLACEMENT|PROPERTY |
| 24 | while IFS='|' read -r name fn from to what; do |
| 25 | [ -n "$name" ] || continue |
| 26 | d=$M/$name |
| 27 | mkdir -p "$d" |
| 28 | awk -v fn="fn $fn " -v from="$from" -v to="$to" ' |
| 29 | index($0, "fn ") == 1 { f = (index($0, fn) == 1) } |
| 30 | f && n == 0 && $0 == from { print to; n = 1; next } |
| 31 | { print } |
| 32 | END { if (n != 1) exit 3 }' "$R/build/cortex.unit.om" > "$d/cortex.unit.om" || |
| 33 | { echo "brain mutant $name: site not found" >&2; exit 2; } |
| 34 | chg=$(diff "$R/build/cortex.unit.om" "$d/cortex.unit.om" | grep -c '^[<>]') |
| 35 | [ "$chg" -eq 2 ] || { echo "brain mutant $name: expected one changed line, got $chg diff lines" >&2; exit 2; } |
| 36 | "$OMC" < "$d/cortex.unit.om" > "$d/cortex" 2> "$d/cortex.err" |
| 37 | if [ $? -ne 0 ] || [ -s "$d/cortex.err" ]; then echo "brain mutant $name: compile failed: $(cat "$d/cortex.err")" >&2; exit 2; fi |
| 38 | chmod +x "$d/cortex" |
| 39 | CORTEX_BIN=$d/cortex BRAIN_PORT=$PORT BRAIN_WORK=$d/work BRAIN_EVIDENCE=$d/ev sh "$R/tests/brain/run.sh" > "$d/run.log" 2>&1 |
| 40 | rc=$? |
| 41 | nf=$(grep -c '^FAIL' "$d/run.log") |
| 42 | first=$(grep '^FAIL' "$d/run.log" | head -2 | cut -c1-160 | tr '\n' ';') |
| 43 | if [ $rc -eq 1 ] && [ "$nf" -gt 0 ]; then |
| 44 | echo "CAUGHT $name ($what): fn $fn, '$from' -> '$to'; gate rc $rc, $nf FAIL line(s): $first" >> "$out" |
| 45 | elif [ $rc -eq 2 ]; then |
| 46 | echo "ERROR $name: the gate could not run (rc 2): $(grep '^brain:' "$d/run.log" | head -1)" >> "$out" |
| 47 | errors=$((errors + 1)) |
| 48 | else |
| 49 | echo "SURVIVED $name ($what): fn $fn, '$from' -> '$to'; gate rc $rc" >> "$out" |
| 50 | survived=$((survived + 1)) |
| 51 | fi |
| 52 | done <<'EOF' |
| 53 | supersede|bn_live|ret eq get bsup e 0|ret true|a superseded entry is never returned by read-before |
| 54 | cite-drop|bn_ocite|for i ulong n|for i ulong div n 2|every returned entry is cited |
| 55 | cite-id|bn_ocite|o_hs get enm e|o_hs get evf e|citation ids resolve to stored entries |
| 56 | confirm-gate|bn_aok|if not bn_conf get ect e|if false|an unconfirmed contract never appears in alerts |
| 57 | date-kinds|bn_okind|js_raw bo_k2|js_raw bo_k1|on_completion and hard_expiry stay distinct |
| 58 | import-idem|bn_import|if bn_same e k b|if false|an unchanged import changes nothing |
| 59 | window-end|bn_inwin|ret le ulong sub y dd get bfa 3|ret lt ulong sub y dd get bfa 3|day N is inside the window |
| 60 | window-start|bn_inwin|if lt y dd|if le y dd|day 0 (the date itself) is inside the window |
| 61 | guard|bn_guard|ret x|ret false|the generic write may not revise a Brain entry |
| 62 | index-update|bn_commit|put bsup t add e 1|t = t|each Brain write updates the live supersede index |
| 63 | fts-count|fts_lstep|put qdf t uint add ulong get qdf t 1|put qdf t uint ulong get qdf t|each put counts its terms in the FTS row counts |
| 64 | fts-link|fts_lstep|put qlh t uint add k 1|put qlv 1 get qlv 1|each put links its terms into the FTS term lists |
| 65 | fts-space|fts_gadd|put qgc g uint add ulong get qgc g 1|put qgc g get qgc g|each put counts its row in its space's list |
| 66 | EOF |
| 67 | cat "$out" |
| 68 | if [ $errors -gt 0 ]; then echo "brain mutants: $errors could not be run" | tee -a "$out"; exit 2; fi |
| 69 | if [ $survived -eq 0 ]; then echo "brain mutants: ALL CAUGHT" | tee -a "$out"; exit 0; fi |
| 70 | echo "brain mutants: $survived survived" | tee -a "$out"; exit 1 |