interplane.Get Omega
Read in your language

interplane-forge

INTERPLANE Forge

Brought by drakestapleton

branch main Branches Tags History

interplane-forge / collab / tests / receipt.sh

113 lines · 6853 bytes Raw Blame History
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.
10untr() { 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; }
11set -u
12H=$(cd "$(dirname "$0")" && pwd)
13export PORT=${RECEIPT_PORT:-18496} CORES=${CORES:-14}
14T=$(mktemp -d /tmp/cprcpt.XXXXXX)
15PASS=0; FAIL=0; PID=
16ok() { PASS=$((PASS+1)); echo "PASS $*"; }
17bad() { FAIL=$((FAIL+1)); echo "FAIL $*"; }
18trap '[ -n "$PID" ] && kill $PID 2>/dev/null; [ -n "${KEEP:-}" ] || rm -rf "$T"' EXIT
19U="http://127.0.0.1:$PORT/drakestapleton/omega-mv/patches"
20get() { curl -s -m 10 -o "$T/b" "$U/$1"; untr "$T/b"; }
21has() { grep -qF -- "$1" "$T/b"; }
22A=215ea39afdc0cf1914cfadf43bbb6d23ce68c920 # head of 4dd099df's revision 1
23B=3743d642cf034299009936eb8d458ba96a0a8589 # head of 88050ef7's revision 1
24V=$T/rev/omega-mv-${A:0:8}.verdict.txt
25R=$T/rcp/omega-mv-${A:0:8}.receipt.txt
26mkdir -p "$T/rev" "$T/rcp" "$T/data"
27verd() { 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)
29rcpt() {
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}
37word() { grep -o 'forge decide: <b class="[a-z]*">[A-Z_ ]*' "$T/b" | head -1 | sed 's/.*">//'; }
38shown() { has 'gate receipt: gate_rc='; }
39check() { # 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}
48DATA=$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
50grep -q "^text tcrcpd \"$T/rcp/\"\$" "$T/f1.om" && ok "fixture folders compiled in" || { bad "sed did not apply"; exit 1; }
51FORGE_SOCIAL_DIR=$T/data/ taskset -c "$CORES" nice -n 10 "$T/f1" 2>> "$T/forged.err" &
52PID=$!
53for i in $(seq 50); do curl -s -o /dev/null "$U" && break; sleep 0.1; done
54kill -0 $PID 2> /dev/null || { echo "test forged did not start: $(cat "$T/forged.err")"; exit 1; }
55
56get 88050ef7
57! has 'forge decide:' && ok "NEG no verdict and no receipt: no decide row" || bad "decide row without any file"
58verd MERGE 'bay 4 (gpt-6)'
59get 4dd099df
60[ "$(word)" = 'HOLD RECEIPT_UNREADABLE' ] && ok "verdict without receipt -> HOLD RECEIPT_UNREADABLE" || bad "no receipt: '$(word)'"
61cp "$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)"
64rcpt "$A" 0 1 'ForgeWeb <i>w</i> & co'
65check "valid MERGE verdict and receipt" 'MERGE OK' 1
66has 'gate_rc=0, negctl_rc=1, author <code>ForgeWeb &lt;i&gt;w&lt;/i&gt; &amp; co</code>' && ok "gate_rc, negctl_rc and escaped author shown" || bad "receipt values: $(grep -o 'gate receipt:[^<]*<code>[^<]*' "$T/b")"
67has "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"
69rcpt "$A" 0 0 ForgeWeb
70check "NEG gate_rc=0 negctl_rc=0" 'HOLD NEGCTL_PASSED' 1
71rcpt "$A" 2 1 ForgeWeb
72check "NEG gate_rc=2" 'HOLD GATE_FAIL' 1
73rcpt "$A" 0 1 'Bay_4'
74check "NEG author is the reviewer" 'HOLD SELF_REVIEW' 1
75rcpt "$A" 0 - ForgeWeb
76check "NEG no negctl_rc" 'HOLD NO_NEGCTL' 0
77rcpt "$B" 0 1 ForgeWeb
78check "NEG wrong head (clone is another commit)" 'HOLD CLONE_MISMATCH' 0
79rcpt "$A" 0 1 ForgeWeb 'gate_rc=0'
80check "NEG malformed (duplicate key)" 'HOLD RECEIPT_MALFORMED' 0
81rcpt "$A" 0 1 ForgeWeb 'colour=blue'
82check "NEG malformed (unknown key)" 'HOLD RECEIPT_MALFORMED' 0
83rcpt "$A" 0 1 ForgeWeb ''; printf '\n' >> "$R"
84check "NEG malformed (empty line)" 'HOLD RECEIPT_MALFORMED' 0
85rcpt "$A" 256 1 ForgeWeb
86check "NEG malformed (gate_rc 256)" 'HOLD RECEIPT_MALFORMED' 0
87rcpt "$A" 0 1 ForgeWeb "gate_cmd=$(head -c 4100 /dev/zero | tr '\0' x)"; sed -i '/^gate_cmd=sh/d' "$R"
88check "NEG oversized (4096 bytes or more)" 'HOLD RECEIPT_UNREADABLE' 0
89rcpt "$A" 0 1 ForgeWeb; mv "$R" "$T/real.txt"; ln -s "$T/real.txt" "$R"
90check "NEG symlink to a valid receipt" 'HOLD RECEIPT_UNREADABLE' 0
91rm "$R"; mkfifo "$R"
92check "NEG FIFO (no hang)" 'HOLD RECEIPT_UNREADABLE' 0
93rm "$R"; rcpt "$A" 0 1 ForgeWeb; cp "$R" "$T/rcp/other-${A:0:8}.receipt.txt"
94check "NEG ambiguous (two receipts for the head)" 'HOLD RECEIPT_AMBIGUOUS' 0
95rm "$T/rcp/other-${A:0:8}.receipt.txt"
96check "ambiguity cleared" 'MERGE OK' 1
97verd MERGE_AFTER_FIX 'bay 4'
98check "NEG verdict MERGE_AFTER_FIX" 'HOLD VERDICT_MERGE_AFTER_FIX' 1
99verd REJECT 'bay 4'
100check "NEG verdict REJECT" 'HOLD VERDICT_REJECT' 1
101printf 'VERDICT MERGE head=%s\n' "$A" > "$V"
102check "NEG verdict without reviewer" 'HOLD NO_REVIEWER' 1
103printf 'VERDICT MERGE head=%s\nreviewer=a\nreviewer=b\n' "$A" > "$V"
104check "NEG two reviewer lines" 'HOLD VERDICT_MALFORMED' 1
105printf 'VERDICT MERGE head=%s\nreviewer=a\nVERDICT REJECT head=%s\n' "$A" "$A" > "$V"
106check "NEG second VERDICT line" 'HOLD VERDICT_MALFORMED' 1
107printf 'VERDICT MERGE head=%s\nreviewer=bay 4\n' "${A:0:8}ffffffffffffffffffffffffffffffff" > "$V"
108check "NEG verdict for another head (same sha8)" 'HOLD HEAD_MISMATCH' 1
109rm "$V"
110check "NEG no verdict, receipt present" 'HOLD VERDICT_UNREADABLE' 1
111kill $PID; wait $PID 2> /dev/null; PID=
112echo "collab receipt: $PASS passed, $FAIL failed"
113[ "$FAIL" = 0 ]