interplane-forge
INTERPLANE Forge
Brought by drakestapleton
interplane-forge / collab / tests / verdict.sh
| 1 | #!/bin/bash |
| 2 | # collab/tests/verdict.sh: HOST test of the patch page's verdict line (sec review forge-web-13102b54 |
| 3 | # P3-1) and build commit (corr P1). Two test forgeds on PORT (default 18495) read the real store and |
| 4 | # allow-list (read-only); sed points the review folder (text tcrevd) at a temp dir of fixture verdict |
| 5 | # files and writes the build commit (text tcbldc). Only a first line that is exactly |
| 6 | # VERDICT (MERGE|MERGE_AFTER_FIX|REJECT) head=<the revision head> may appear, nothing else of the file, |
| 7 | # and no folder or file name. Usage: collab/tests/verdict.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=${VERDICT_PORT:-18495} CORES=${CORES:-14} |
| 14 | T=$(mktemp -d /tmp/cpverd.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 | start() { # binary |
| 21 | FORGE_SOCIAL_DIR=$T/data/ taskset -c "$CORES" nice -n 10 "$1" 2>> "$T/forged.err" & |
| 22 | PID=$! |
| 23 | for i in $(seq 50); do curl -s -o /dev/null "$U" && break; sleep 0.1; done |
| 24 | kill -0 $PID 2> /dev/null || { echo "test forged did not start: $(cat "$T/forged.err")"; exit 1; } |
| 25 | } |
| 26 | stop() { kill $PID 2>/dev/null; wait $PID 2>/dev/null; PID=; } |
| 27 | get() { curl -s -o "$T/b" "$U/$1"; untr "$T/b"; } |
| 28 | has() { grep -qF -- "$1" "$T/b"; } |
| 29 | A=215ea39afdc0cf1914cfadf43bbb6d23ce68c920 # head of 4dd099df's revision |
| 30 | B=3743d642cf034299009936eb8d458ba96a0a8589 # head of 88050ef7's revision |
| 31 | mkdir -p "$T/rev" "$T/data" |
| 32 | printf 'VERDICT MERGE_AFTER_FIX head=%s\nsecret second line <b>x</b>\n' "$A" > "$T/rev/omega-mv-${A:0:8}.verdict.txt" |
| 33 | printf 'VERDICT MERGE head=%s <script>alert(1)</script>\n' "$B" > "$T/rev/omega-mv-${B:0:8}.verdict.txt" |
| 34 | STAMP=0123456789abcdef0123456789abcdef01234567 |
| 35 | DATA=$T/data/ SEDX="s|^text tcrevd \".*\"\$|text tcrevd \"$T/rev/\"|;s/^text tcbldc \"unrecorded\"\$/text tcbldc \"$STAMP\"/" \ |
| 36 | "$H/tbuild.sh" "$T/f1" > /dev/null || exit 1 |
| 37 | grep -q "^text tcrevd \"$T/rev/\"\$" "$T/f1.om" && grep -q "^text tcbldc \"$STAMP\"\$" "$T/f1.om" && ok "fixture folder and stamp compiled in" || { bad "sed did not apply"; exit 1; } |
| 38 | start "$T/f1" |
| 39 | get 4dd099df |
| 40 | has "<b>VERDICT MERGE_AFTER_FIX head=$A</b>" && ok "well-formed verdict line shown" || bad "verdict line: $(grep -o '<b>VERDICT[^<]*' "$T/b")" |
| 41 | ! has 'secret second line' && ok "NEG nothing after line 1 shown" || bad "second line leaked" |
| 42 | ! has 'verdict.txt' && ! has 'review folder' && ! has 'handoffs' && ok "NEG no folder or file name on the page" || bad "layout disclosed" |
| 43 | has "built from commit <code>$STAMP</code>" && ok "page names the build commit" || bad "build commit missing" |
| 44 | get 88050ef7 |
| 45 | ! has '<b>VERDICT' && ! has 'alert(1)' && has 'No review verdict names a head' && ok "NEG line with trailing text not shown" || bad "trailing-text line shown" |
| 46 | # a verdict for another head with the same sha8, and a malformed word |
| 47 | printf 'VERDICT MERGE head=%s\n' "${A:0:8}ffffffffffffffffffffffffffffffff" > "$T/rev/omega-mv-${A:0:8}.verdict.txt" |
| 48 | get 4dd099df |
| 49 | ! has '<b>VERDICT' && ok "NEG head of another commit (same sha8) not shown" || bad "foreign head shown" |
| 50 | printf 'VERDICT: MERGE head=%s\n' "$A" > "$T/rev/omega-mv-${A:0:8}.verdict.txt" |
| 51 | get 4dd099df |
| 52 | ! has '<b>VERDICT' && ok "NEG malformed verdict word not shown" || bad "malformed line shown" |
| 53 | printf 'VERDICT REJECT head=%s\r\n' "$A" > "$T/rev/omega-mv-${A:0:8}.verdict.txt" |
| 54 | get 4dd099df |
| 55 | has "<b>VERDICT REJECT head=$A</b>" && ok "REJECT with CRLF shown" || bad "REJECT line" |
| 56 | stop |
| 57 | # negative control for the stamp: a value that is not 40 hex is not printed |
| 58 | DATA=$T/data/ SEDX="s/^text tcbldc \"unrecorded\"\$/text tcbldc \"<b>dirty<\/b>$STAMP\"/" "$H/tbuild.sh" "$T/f2" > /dev/null || exit 1 |
| 59 | start "$T/f2" |
| 60 | get 4dd099df |
| 61 | has 'commit was not recorded' && ! has 'dirty' && ok "NEG non-hex build stamp not printed" || bad "bad stamp printed" |
| 62 | has "<b>VERDICT MERGE head=$A</b>" && ok "real review folder still read" || bad "real verdict missing: $(grep -o '<b>VERDICT[^<]*' "$T/b")" |
| 63 | stop |
| 64 | echo "collab verdict: $PASS passed, $FAIL failed" |
| 65 | [ "$FAIL" = 0 ] |