interplane-forge
INTERPLANE Forge
Brought by drakestapleton
interplane-forge / collab / tests / receipt.sh
| 1 | #!/bin/bash |
| 2 | # collab/tests/receipt.sh: HOST test of the patch page's gate receipt and forge decide word |
| 3 | # (docs/FEATURES.md "Gate receipts: exact reader behaviour"). One test forged on PORT (default 18496) |
| 4 | # reads the real store and allow-list (read-only); sed points the review folder (text tcrevd) and the |
| 5 | # receipts folder (text tcrcpd) at temp dirs whose files change between requests. MUTX adds one more |
| 6 | # sed expression to the build (a mutant): with it the test must fail. |
| 7 | # Usage: collab/tests/receipt.sh (CORES default 14; KEEP=1 keeps temp) |
| 8 | # untr FILE: forged adds translation hints while it sends an HTML page (server/tr.om); the checks here |
| 9 | # read pages without them (server/tests/translate.sh gates the hints). Other bodies are left as sent. |
| 10 | untr() { case "$(head -c 15 "$1" 2>/dev/null)" in '<!doctype html'*) sed -i 's/<span translate="no">\([^<]*\)<\/span>/\1/g; s/ translate="no"//g' "$1" ;; esac; } |
| 11 | set -u |
| 12 | H=$(cd "$(dirname "$0")" && pwd) |
| 13 | export PORT=${RECEIPT_PORT:-18496} CORES=${CORES:-14} |
| 14 | T=$(mktemp -d /tmp/cprcpt.XXXXXX) |
| 15 | PASS=0; FAIL=0; PID= |
| 16 | ok() { PASS=$((PASS+1)); echo "PASS $*"; } |
| 17 | bad() { FAIL=$((FAIL+1)); echo "FAIL $*"; } |
| 18 | trap '[ -n "$PID" ] && kill $PID 2>/dev/null; [ -n "${KEEP:-}" ] || rm -rf "$T"' EXIT |
| 19 | U="http://127.0.0.1:$PORT/drakestapleton/omega-mv/patches" |
| 20 | get() { curl -s -m 10 -o "$T/b" "$U/$1"; untr "$T/b"; } |
| 21 | has() { grep -qF -- "$1" "$T/b"; } |
| 22 | A=215ea39afdc0cf1914cfadf43bbb6d23ce68c920 # head of 4dd099df's revision 1 |
| 23 | B=3743d642cf034299009936eb8d458ba96a0a8589 # head of 88050ef7's revision 1 |
| 24 | V=$T/rev/omega-mv-${A:0:8}.verdict.txt |
| 25 | R=$T/rcp/omega-mv-${A:0:8}.receipt.txt |
| 26 | mkdir -p "$T/rev" "$T/rcp" "$T/data" |
| 27 | verd() { printf 'VERDICT %s head=%s\nreviewer=%s\nnotes follow\n' "$1" "$A" "$2" > "$V"; } |
| 28 | # rcpt CLONE GATE_RC NEGCTL_RC AUTHOR [EXTRA LINE]: a FORGE-RECEIPT v1 (the shape of a real forge gate receipt) |
| 29 | rcpt() { |
| 30 | { printf 'FORGE-RECEIPT v1\nrid=rad:z6do9WDBhuSnvopDkgFdFr1yWA62\nclone=%s\n' "$1" |
| 31 | printf 'tree=e2b97327c20ce697eab6bc605538acc85bc9d513\nomc=none\ngate_cmd=sh -c true\ngate_rc=%s\n' "$2" |
| 32 | [ "$3" = - ] || printf 'negctl_cmd=sh -c false\nnegctl_rc=%s\n' "$3" |
| 33 | printf 'author=%s\nstarted=2026-11-09T01:00:00Z\nfinished=2026-11-09T01:05:00Z\n' "$4" |
| 34 | printf 'log_sha256=d0996facfe0364e0a80ba9d3a2bc49c85d185e17f1fb1e1b9a6db2d04b5aa99a\n' |
| 35 | [ -z "${5:-}" ] || printf '%s\n' "$5"; } > "$R" |
| 36 | } |
| 37 | word() { grep -o 'forge decide: <b class="[a-z]*">[A-Z_ ]*' "$T/b" | head -1 | sed 's/.*">//'; } |
| 38 | shown() { has 'gate receipt: gate_rc='; } |
| 39 | check() { # NAME EXPECTED_WORD SHOWN(1/0) |
| 40 | get 4dd099df |
| 41 | local w; w=$(word) |
| 42 | if [ "$w" = "$2" ] && { [ "$3" = 1 ] && shown || { [ "$3" = 0 ] && ! shown && has 'no gate receipt shown'; }; }; then |
| 43 | ok "$1 -> $2" |
| 44 | else |
| 45 | bad "$1: word '$w' (want '$2'), receipt shown: $(shown && echo yes || echo no) (want $3)" |
| 46 | fi |
| 47 | } |
| 48 | DATA=$T/data/ SEDX="s|^text tcrevd \".*\"\$|text tcrevd \"$T/rev/\"|;s|^text tcrcpd \".*\"\$|text tcrcpd \"$T/rcp/\"|${MUTX:+;$MUTX}" \ |
| 49 | "$H/tbuild.sh" "$T/f1" > /dev/null || exit 1 |
| 50 | grep -q "^text tcrcpd \"$T/rcp/\"\$" "$T/f1.om" && ok "fixture folders compiled in" || { bad "sed did not apply"; exit 1; } |
| 51 | FORGE_SOCIAL_DIR=$T/data/ taskset -c "$CORES" nice -n 10 "$T/f1" 2>> "$T/forged.err" & |
| 52 | PID=$! |
| 53 | for i in $(seq 50); do curl -s -o /dev/null "$U" && break; sleep 0.1; done |
| 54 | kill -0 $PID 2> /dev/null || { echo "test forged did not start: $(cat "$T/forged.err")"; exit 1; } |
| 55 | |
| 56 | get 88050ef7 |
| 57 | ! has 'forge decide:' && ok "NEG no verdict and no receipt: no decide row" || bad "decide row without any file" |
| 58 | verd MERGE 'bay 4 (gpt-6)' |
| 59 | get 4dd099df |
| 60 | [ "$(word)" = 'HOLD RECEIPT_UNREADABLE' ] && ok "verdict without receipt -> HOLD RECEIPT_UNREADABLE" || bad "no receipt: '$(word)'" |
| 61 | cp "$HOME/handoffs/hive/forge/v1/omega-mv-215ea39a.receipt.txt" "$R" 2> /dev/null \ |
| 62 | && { check "real forge gate receipt (v1 run of 2026-11-07)" 'MERGE OK' 1; has 'author <code>t_04379749</code>' && ok "real receipt author shown" || bad "real author"; } \ |
| 63 | || echo "NOT_RUN real receipt copy (file absent)" |
| 64 | rcpt "$A" 0 1 'ForgeWeb <i>w</i> & co' |
| 65 | check "valid MERGE verdict and receipt" 'MERGE OK' 1 |
| 66 | has 'gate_rc=0, negctl_rc=1, author <code>ForgeWeb <i>w</i> & co</code>' && ok "gate_rc, negctl_rc and escaped author shown" || bad "receipt values: $(grep -o 'gate receipt:[^<]*<code>[^<]*' "$T/b")" |
| 67 | has "revision 1, head <code>$A</code>" && ok "row names revision and head" || bad "row head" |
| 68 | ! has 'receipt.txt' && ! has 'handoffs' && ! has 'verdict.txt' && ! has "$T" && ok "NEG no folder or file name on the page" || bad "layout disclosed" |
| 69 | rcpt "$A" 0 0 ForgeWeb |
| 70 | check "NEG gate_rc=0 negctl_rc=0" 'HOLD NEGCTL_PASSED' 1 |
| 71 | rcpt "$A" 2 1 ForgeWeb |
| 72 | check "NEG gate_rc=2" 'HOLD GATE_FAIL' 1 |
| 73 | rcpt "$A" 0 1 'Bay_4' |
| 74 | check "NEG author is the reviewer" 'HOLD SELF_REVIEW' 1 |
| 75 | rcpt "$A" 0 - ForgeWeb |
| 76 | check "NEG no negctl_rc" 'HOLD NO_NEGCTL' 0 |
| 77 | rcpt "$B" 0 1 ForgeWeb |
| 78 | check "NEG wrong head (clone is another commit)" 'HOLD CLONE_MISMATCH' 0 |
| 79 | rcpt "$A" 0 1 ForgeWeb 'gate_rc=0' |
| 80 | check "NEG malformed (duplicate key)" 'HOLD RECEIPT_MALFORMED' 0 |
| 81 | rcpt "$A" 0 1 ForgeWeb 'colour=blue' |
| 82 | check "NEG malformed (unknown key)" 'HOLD RECEIPT_MALFORMED' 0 |
| 83 | rcpt "$A" 0 1 ForgeWeb ''; printf '\n' >> "$R" |
| 84 | check "NEG malformed (empty line)" 'HOLD RECEIPT_MALFORMED' 0 |
| 85 | rcpt "$A" 256 1 ForgeWeb |
| 86 | check "NEG malformed (gate_rc 256)" 'HOLD RECEIPT_MALFORMED' 0 |
| 87 | rcpt "$A" 0 1 ForgeWeb "gate_cmd=$(head -c 4100 /dev/zero | tr '\0' x)"; sed -i '/^gate_cmd=sh/d' "$R" |
| 88 | check "NEG oversized (4096 bytes or more)" 'HOLD RECEIPT_UNREADABLE' 0 |
| 89 | rcpt "$A" 0 1 ForgeWeb; mv "$R" "$T/real.txt"; ln -s "$T/real.txt" "$R" |
| 90 | check "NEG symlink to a valid receipt" 'HOLD RECEIPT_UNREADABLE' 0 |
| 91 | rm "$R"; mkfifo "$R" |
| 92 | check "NEG FIFO (no hang)" 'HOLD RECEIPT_UNREADABLE' 0 |
| 93 | rm "$R"; rcpt "$A" 0 1 ForgeWeb; cp "$R" "$T/rcp/other-${A:0:8}.receipt.txt" |
| 94 | check "NEG ambiguous (two receipts for the head)" 'HOLD RECEIPT_AMBIGUOUS' 0 |
| 95 | rm "$T/rcp/other-${A:0:8}.receipt.txt" |
| 96 | check "ambiguity cleared" 'MERGE OK' 1 |
| 97 | verd MERGE_AFTER_FIX 'bay 4' |
| 98 | check "NEG verdict MERGE_AFTER_FIX" 'HOLD VERDICT_MERGE_AFTER_FIX' 1 |
| 99 | verd REJECT 'bay 4' |
| 100 | check "NEG verdict REJECT" 'HOLD VERDICT_REJECT' 1 |
| 101 | printf 'VERDICT MERGE head=%s\n' "$A" > "$V" |
| 102 | check "NEG verdict without reviewer" 'HOLD NO_REVIEWER' 1 |
| 103 | printf 'VERDICT MERGE head=%s\nreviewer=a\nreviewer=b\n' "$A" > "$V" |
| 104 | check "NEG two reviewer lines" 'HOLD VERDICT_MALFORMED' 1 |
| 105 | printf 'VERDICT MERGE head=%s\nreviewer=a\nVERDICT REJECT head=%s\n' "$A" "$A" > "$V" |
| 106 | check "NEG second VERDICT line" 'HOLD VERDICT_MALFORMED' 1 |
| 107 | printf 'VERDICT MERGE head=%s\nreviewer=bay 4\n' "${A:0:8}ffffffffffffffffffffffffffffffff" > "$V" |
| 108 | check "NEG verdict for another head (same sha8)" 'HOLD HEAD_MISMATCH' 1 |
| 109 | rm "$V" |
| 110 | check "NEG no verdict, receipt present" 'HOLD VERDICT_UNREADABLE' 1 |
| 111 | kill $PID; wait $PID 2> /dev/null; PID= |
| 112 | echo "collab receipt: $PASS passed, $FAIL failed" |
| 113 | [ "$FAIL" = 0 ] |