interplane.Get Omega
Read in your language

interplane-forge

INTERPLANE Forge

Brought by drakestapleton

branch main Branches Tags History

interplane-forge / collab / tests / check.sh

100 lines · 7011 bytes Raw Blame History
1#!/bin/bash
2# collab/tests/check.sh [base-url]: HOST gates for the patches and issues pages of forged.
3# Every positive gate has a negative control. Default target: a test forged on 127.0.0.1:18486.
4# ISSUES=1 also runs the issue gates against heartwood (only on a test build whose allow-list
5# includes heartwood; the production allow-list does not).
6U=${1:-http://127.0.0.1:18486}
7O=/drakestapleton/omega-mv
8S=$HOME/.radicle/storage/z6do9WDBhuSnvopDkgFdFr1yWA62
9T=$(mktemp -d)
10trap 'rm -rf "$T"' EXIT
11pass=0
12fail=0
13ok() { pass=$((pass+1)); echo "PASS $*"; }
14no() { fail=$((fail+1)); echo "FAIL $*"; }
15# get BASE PATH [METHOD] -> $T/b body, $T/h headers, $code. forged adds translation hints while it sends an
16# HTML page (server/tr.om); the checks read HTML bodies without them (server/tests/translate.sh gates them)
17get() {
18 code=$(curl -s -o "$T/b" -D "$T/h" -w '%{http_code}' -X "${3:-GET}" -H "X-Forge-Base: $1" "$U$2")
19 grep -qi '^content-type: text/html' "$T/h" && sed -i 's/<span translate="no">\([^<]*\)<\/span>/\1/g; s/ translate="no"//g' "$T/b"
20 return 0
21}
22has() { grep -qF -- "$1" "$T/b"; }
23# Expected patch counts come from the Radicle CLI reading the same storage (oracle, not forged code):
24# rows of `rad patch list --merged` / `--open` (7-hex id column). The lists change as patches land, so
25# they are read right before the pages; a list page shows at most 200 COBs.
26radn() { rad patch list --repo rad:z6do9WDBhuSnvopDkgFdFr1yWA62 "--$1" 2> /dev/null | grep -cE '^│ [^ ]+ [0-9a-f]{7} '; }
27M=$(radn merged); OP=$(radn open)
28echo "oracle: rad patch list omega-mv: merged $M, open $OP"
29[ "$M" -ge 4 ] && [ "$M" -le 200 ] && [ "$OP" -le 200 ] || { no "oracle: rad patch list gave merged '$M' open '$OP'"; }
30for B in / /forge/; do
31 P=${B%/}
32 get $B "$O/patches/4dd099df"
33 [ "$code" = 200 ] && has '<b class="ok">Merged</b>' && has 'VERDICT MERGE head=215ea39afdc0cf1914cfadf43bbb6d23ce68c920' \
34 && has 'Linked verdicts' && has "href=\"$P$O/patches/4dd099df31792d5ddb0d9fac5ca6d568513f4539.diff" \
35 && ok "[$B] 4dd099df merged with verdict 215ea39a" || no "[$B] 4dd099df ($code)"
36 get $B "$O/patches/88050ef7d710cb43d65214ff50bb1a0882770bb9"
37 [ "$code" = 200 ] && has '<b class="ok">Merged</b>' && has 'VERDICT MERGE head=3743d642cf034299009936eb8d458ba96a0a8589' \
38 && ok "[$B] 88050ef7 merged with verdict 3743d642" || no "[$B] 88050ef7 ($code)"
39 # negative control: a merged patch without a verdict file shows no verdict box
40 get $B "$O/patches/35e5e0f7"
41 [ "$code" = 200 ] && has 'Merged' && has 'No review verdict names a head' && ! has '<b>VERDICT' && ! has '&lt;head sha8&gt;.verdict.txt' && ! has 'review folder' && ok "[$B] 35e5e0f7 merged, no verdict (control)" || no "[$B] 35e5e0f7 control ($code)"
42 for bad in deadbeef 4dd 4DD099DF zz "4dd099df/x" "4dd099dfz"; do
43 get $B "$O/patches/$bad"
44 [ "$code" = 404 ] && ok "[$B] patches/$bad -> 404" || no "[$B] patches/$bad -> $code"
45 done
46 get $B "$O/patches"
47 [ "$code" = 200 ] && has "Merged ($M)" && has "Open ($OP)" && ok "[$B] list counts equal rad (Merged $M, Open $OP)" || no "[$B] list ($code; want Merged ($M) Open ($OP))"
48 get $B "$O/patches?state=merged"
49 n=$(grep -c '<li><a class="rname"' "$T/b")
50 [ "$code" = 200 ] && [ "$n" = "$M" ] && has "href=\"$P$O/patches/4dd099df31792d5ddb0d9fac5ca6d568513f4539\"" \
51 && ok "[$B] merged list has $M rows (rad)" || no "[$B] merged list ($code, $n rows, rad $M)"
52 get $B "$O/patches?state=open"
53 n=$(grep -c '<li><a class="rname"' "$T/b")
54 [ "$code" = 200 ] && [ "$n" = "$OP" ] && ! has "patches/4dd099df31792d5ddb0d9fac5ca6d568513f4539\"" && ok "[$B] open list has $OP rows (rad), merged 4dd099df absent (control)" || no "[$B] open list ($code, $n, rad $OP)"
55 get $B "$O/pulls"
56 [ "$code" = 200 ] && has "Merged ($M)" && ok "[$B] /pulls lists patches" || no "[$B] /pulls ($code)"
57 get $B "$O/pulls/4dd099df"
58 loc=$(grep -i '^location:' "$T/h" | tr -d '\r' | cut -d' ' -f2)
59 [ "$code" = 302 ] && [ "$loc" = "$P$O/patches/4dd099df" ] && ok "[$B] /pulls/<id> 302 $loc" || no "[$B] /pulls/<id> ($code $loc)"
60 get $B "$O/pull/88050ef7"
61 loc=$(grep -i '^location:' "$T/h" | tr -d '\r' | cut -d' ' -f2)
62 [ "$code" = 302 ] && [ "$loc" = "$P$O/patches/88050ef7" ] && ok "[$B] /pull/<id> 302" || no "[$B] /pull/<id> ($code $loc)"
63 get $B "$O/patches/4dd099df" POST
64 [ "$code" = 405 ] && ok "[$B] POST -> 405" || no "[$B] POST -> $code"
65 get $B "$O/issues"
66 [ "$code" = 200 ] && has 'Open (0)' && ok "[$B] issues list (no issues in omega-mv)" || no "[$B] issues ($code)"
67 get $B "$O/issues/deadbeef"
68 [ "$code" = 404 ] && ok "[$B] issues/deadbeef -> 404" || no "[$B] issues/deadbeef -> $code"
69 # allow-list gates: only meaningful on the production allow-list (skipped on the ISSUES test build)
70 if [ "${ISSUES:-0}" != 1 ]; then
71 get $B "/drakestapleton/heartwood/patches"
72 [ "$code" = 404 ] && ok "[$B] non-allow-listed heartwood -> 404" || no "[$B] heartwood -> $code"
73 get $B "/drakestapleton/aien-sovereign-core-mv/patches/f75aeaa5"
74 [ "$code" = 200 ] && has '<b class="ok">Merged</b>' && ok "[$B] core f75aeaa5 renders" || no "[$B] core f75aeaa5 ($code)"
75 fi
76done
77# raw diff: byte-identical to git diff --full-index (88050ef7: about 21 MB). Abbreviation length is not stable.
78code=$(curl -s -o "$T/d" -w '%{http_code} %{content_type}' -H 'X-Forge-Base: /' "$U$O/patches/88050ef7.diff")
79git --git-dir="$S" diff --full-index --no-color --no-ext-diff -M 943d9555d0a1a2c6e5bcac9e1b6a54b4b4b26cfa 3743d642cf034299009936eb8d458ba96a0a8589 -- > "$T/g" 2>/dev/null \
80 || git --git-dir="$S" diff --full-index --no-color --no-ext-diff -M "$(git --git-dir="$S" rev-parse 943d9555)" 3743d642cf034299009936eb8d458ba96a0a8589 -- > "$T/g"
81[ "${code%% *}" = 200 ] && cmp -s "$T/d" "$T/g" && ok "raw diff 88050ef7 identical to git diff ($(wc -c < "$T/d") bytes, $code)" \
82 || no "raw diff 88050ef7 ($code, $(wc -c < "$T/d") vs $(wc -c < "$T/g"))"
83code=$(curl -s -o "$T/d" -w '%{http_code}' -H 'X-Forge-Base: /' "$U$O/patches/deadbeef.diff")
84[ "$code" = 404 ] && ok "raw diff of unknown id -> 404" || no "raw diff deadbeef -> $code"
85if [ "${ISSUES:-0}" = 1 ]; then
86 H=/drakestapleton/heartwood
87 get / "$H/issues?state=all"
88 n=$(grep -c '<li><a class="rname"' "$T/b")
89 [ "$code" = 200 ] && [ "$n" -gt 0 ] && ok "heartwood issues list ($n rows)" || no "heartwood issues ($code, $n)"
90 id=$(grep -o "href=\"$H/issues/[0-9a-f]*\"" "$T/b" | head -1 | grep -o '[0-9a-f]\{40\}')
91 get / "$H/issues/$id"
92 [ "$code" = 200 ] && has 'opened by' && ok "heartwood issue ${id:0:8} renders" || no "heartwood issue $id ($code)"
93 get / "$H/issues/bc5b3ac0"
94 # the author DID comes from the change signature key, not the git email (lorenz@leutgeb.xyz)
95 [ "$code" = 200 ] && has 'did:key:z6MkkPvBfjP4bQmco5Dm7UGsX2ruDBieEHi8n9DVJWX5sTEz' && ! has 'leutgeb' && ok 'issue author DID from signature' || no "issue author DID ($code)"
96 get / "$H/issues?state=closed"
97 [ "$code" = 200 ] && has 'Closed' && ok "heartwood closed issues" || no "heartwood closed ($code)"
98fi
99echo "collab: $pass passed, $fail failed"
100[ $fail = 0 ]