interplane-forge
INTERPLANE Forge
Brought by drakestapleton
interplane-forge / server / tests / jsonpages.sh
| 1 | # ORACLE: host test driver (bash + curl + server/tests/jsonpages.py), not product code. |
| 2 | # server/tests/jsonpages.sh: the machine form of every page (card t_6b17c31a, docs/API.md). |
| 3 | # bash server/tests/jsonpages.sh (spark; FORGED_CPUS default 10-11; FORGE_TEST_PORT default 18478, |
| 4 | # the base build listens on FORGE_TEST_PORT+1; FORGE_BASE_COMMIT |
| 5 | # default e2feabcb, the tree before this card: forge/json-counts |
| 6 | # rebased onto edge/spark-front-door b413007c) |
| 7 | # Builds this tree (NEW) and FORGE_BASE_COMMIT (BASE) with the port, the allow-list, the storage, the |
| 8 | # data dir and the count sources moved into a temp dir: the allow-list is the first table of the real |
| 9 | # ~/handoffs/radicle/RIDS.md (storage = symlinks to the real repos, read-only) plus three refused rows |
| 10 | # (omega-pearl and aien-crypto by name, pearl-alias by the withdrawn RID), each with storage present, |
| 11 | # so only the deny list can refuse them. Then jsonpages.py walks every page under / and /forge/ as JSON |
| 12 | # and as HTML (schemas from docs/API.md, facts on the HTML page, HTML byte-equal to BASE apart from the |
| 13 | # one alternate link, refused repos 404 with forge/error/1). A generated big-diff repo (3000000 bytes of |
| 14 | # 0xFF lines) is walked too, and its commit / compare JSON must parse with diff_truncated true. |
| 15 | # Negative controls (each must FAIL the walk; two repos each): BASE itself (no JSON forms), a mutant |
| 16 | # that renames one documented key, a mutant whose browse slice ignores the Accept header, a mutant |
| 17 | # without the deny list; and a mutant without the diff budget in brzxs must fail the big-diff check. |
| 18 | # Read-only on real storage; never touches 18480, ~/forge-data or port 18091. |
| 19 | set -u |
| 20 | cd "$(dirname "$0")/../.." |
| 21 | ROOT=$(pwd) |
| 22 | CORES=${FORGED_CPUS:-10-11} |
| 23 | PORT=${FORGE_TEST_PORT:-18478} |
| 24 | BPORT=$((PORT + 1)) |
| 25 | BASEC=${FORGE_BASE_COMMIT:-e2feabcbf0cf56e1a4dae20f4d724b3169054747} |
| 26 | OMC=$HOME/work/flux/omega-mv/seed/out/omc |
| 27 | # the Radicle storage the table links to: FORGE_TEST_RSTORE (default ~/radicle-storage-frozen/storage, |
| 28 | # the read-only copy kept after the Radicle removal of 2026-11-14); the chrome from its interplane.io. |
| 29 | # STORE_VARIANT=1 (with IPL_DIR): both builds are store-reading builds of the same table, made into a |
| 30 | # store by store/tests/fixstore.sh (the live projects hard-linked from ~/interplane-store-owner, read only). |
| 31 | STORE=${FORGE_TEST_RSTORE:-$HOME/radicle-storage-frozen/storage} |
| 32 | export FORGE_SITE_STORE=${FORGE_SITE_STORE:-$STORE/z399yKvnXcBQNkKoq86iBDgTvQ5QV} |
| 33 | R1=z44GqrPVAPjZkhoD2MWVjqy18ighN # aien-sovereign-core-mv storage, listed as omega-pearl |
| 34 | R2=z6do9WDBhuSnvopDkgFdFr1yWA62 # omega-mv storage, listed as aien-crypto |
| 35 | DENY=z2ft64NFLsKzWttCXw6NWNbRQLggQ # withdrawn omega-pearl RID |
| 36 | T=$(mktemp -d) |
| 37 | pids=() |
| 38 | pass=0; fail=0 |
| 39 | ok() { pass=$((pass+1)); echo "PASS $*"; } |
| 40 | bad() { fail=$((fail+1)); echo "FAIL $*"; } |
| 41 | cleanup() { for p in "${pids[@]}"; do kill "$p" 2>/dev/null; done; wait 2>/dev/null; [ -n "${KEEP:-}" ] || rm -rf "$T"; } |
| 42 | trap cleanup EXIT |
| 43 | for p in $PORT $BPORT; do |
| 44 | if ss -ltn | grep -q "127.0.0.1:$p "; then echo "NOT_RUN: port $p busy"; exit 3; fi |
| 45 | done |
| 46 | |
| 47 | # ---- allow-list and storage |
| 48 | mkdir -p "$T/storage" "$T/ng" "$T/bin" |
| 49 | cp server/tests/fake/rad server/tests/fake/getent "$T/bin/" |
| 50 | chmod 755 "$T/bin/rad" "$T/bin/getent" |
| 51 | : > "$T/ng/dl.log"; : > "$T/ng/access.log" |
| 52 | awk 'f==0 && /^\|---/ {print; f=1; next} f==1 && !/^\|/ {exit} {print}' "$HOME/handoffs/radicle/RIDS.md" > "$T/RIDS.md" |
| 53 | for r in $(sed -n 's/^| [^|]* | rad:\([A-Za-z0-9]*\) |.*/\1/p' "$T/RIDS.md"); do |
| 54 | [ -e "$STORE/$r" ] && ln -sfn "$STORE/$r" "$T/storage/$r" |
| 55 | done |
| 56 | ln -sfn "$STORE/$R1" "$T/storage/$R1"; ln -sfn "$STORE/$R2" "$T/storage/$R2"; ln -sfn "$STORE/z631r2JJiVT8it4tST7RK24hpowi" "$T/storage/$DENY" |
| 57 | printf '| omega-pearl | rad:%s | main | - | - | - |\n| aien-crypto | rad:%s | main | - | - | - |\n| pearl-alias | rad:%s | main | - | - | - |\n' "$R1" "$R2" "$DENY" >> "$T/RIDS.md" |
| 58 | # heartwood (upstream Radicle, seeded here, never listed live) only in this temp table: no served repo has |
| 59 | # issues or release tags, heartwood has both, so the issue and release pages are walked on real data |
| 60 | HW=z3gqcJUoA1n9HaHKufZs5FCSGazv5 |
| 61 | if [ -e "$STORE/$HW" ]; then |
| 62 | ln -sfn "$STORE/$HW" "$T/storage/$HW" |
| 63 | printf '| heartwood | rad:%s | %s | - | test only | - |\n' "$HW" "$(git -C "$STORE/$HW" symbolic-ref --short HEAD)" >> "$T/RIDS.md" |
| 64 | fi |
| 65 | # big-diff fixture (bay 11 finding 1 on 4270c80d): a commit adding 30000 lines of 99 0xFF bytes |
| 66 | # (3000000 bytes, text to git). Escaped as \ufffd that is far past the 8 MiB response buffer, so the |
| 67 | # commit and compare JSON must stop at the reserve with diff_truncated true and still parse. The walk |
| 68 | # visits this repo too (both commits, the compare of the two). |
| 69 | FXR=zJsonPagesBigDiff1 |
| 70 | [ "${STORE_VARIANT:-0}" = 1 ] && FXR=zJsonPagesBigDiffStore1 |
| 71 | FXW=$T/fxw |
| 72 | export GIT_AUTHOR_NAME=fixture GIT_AUTHOR_EMAIL=fixture@invalid GIT_COMMITTER_NAME=fixture \ |
| 73 | GIT_COMMITTER_EMAIL=fixture@invalid GIT_AUTHOR_DATE=2026-11-09T00:00:00Z GIT_COMMITTER_DATE=2026-11-09T00:00:00Z |
| 74 | git init -q -b main "$FXW" && printf 'a\n' > "$FXW/a.txt" && git -C "$FXW" add a.txt && git -C "$FXW" commit -q -m one \ |
| 75 | && python3 -c 'import sys; sys.stdout.buffer.write((b"\xff" * 99 + b"\n") * 30000)' > "$FXW/latin.txt" \ |
| 76 | && git -C "$FXW" add latin.txt && git -C "$FXW" commit -q -m two \ |
| 77 | && git clone -q --bare "$FXW" "$T/storage/$FXR" || { bad "fixture repo"; exit 1; } |
| 78 | unset GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL GIT_AUTHOR_DATE GIT_COMMITTER_DATE |
| 79 | FXH=$(git -C "$FXW" rev-parse HEAD); FXP=$(git -C "$FXW" rev-parse HEAD~1) |
| 80 | printf '| big-diff | rad:%s | main | - | test only | - |\n' "$FXR" >> "$T/RIDS.md" |
| 81 | # fxcheck PORT: commit and compare JSON of the fixture parse, fit the buffer, say diff_truncated true |
| 82 | fxcheck() { |
| 83 | local p r=0 |
| 84 | for p in "commit/$FXH" "compare/$FXP...$FXH"; do |
| 85 | curl -s -o "$T/fx.json" -H 'X-Forge-Base: /' -H 'Accept: application/json' "http://127.0.0.1:$1/drakestapleton/big-diff/$p" |
| 86 | python3 -c 'import json, sys; b = open(sys.argv[1], "rb").read(); d = json.loads(b); sys.exit(0 if d.get("diff_truncated") is True and len(b) <= 8388608 else 1)' "$T/fx.json" 2> /dev/null \ |
| 87 | || { echo "fixture ${p%%/*} JSON: $(wc -c < "$T/fx.json") bytes, does not parse or diff_truncated is not true"; r=1; } |
| 88 | done |
| 89 | return $r |
| 90 | } |
| 91 | echo "allow-list: $(grep -c ' | rad:' "$T/RIDS.md") rows, $(ls "$T/storage" | wc -l) storage links" |
| 92 | if [ "${STORE_VARIANT:-0}" = 1 ]; then |
| 93 | bash store/tests/fixstore.sh "$T/RIDS.md" "$T/storage" "$T/store" || { bad "fixture store"; exit 1; } |
| 94 | export FORGE_STORE=$T/store |
| 95 | echo "STORE_VARIANT: store-reading builds, store $T/store ($(wc -l < "$T/store/catalog.tsv") projects)" |
| 96 | fi |
| 97 | |
| 98 | compose() { # compose DIR OUT DATA PORT: every unit of the tree in DIR, redirected into $T |
| 99 | (cd "$1" && { printf 'om2\n'; cat $(./run.sh units); }) > "$2" |
| 100 | sed -i -e "s|haddr4 a 2130706433 18480|haddr4 a 2130706433 $4|" \ |
| 101 | -e "s|/home/drakestapleton/handoffs/radicle/RIDS.md|$T/RIDS.md|" \ |
| 102 | -e "s|/home/drakestapleton/.radicle/storage/|$T/storage/|g" \ |
| 103 | -e "s|/home/drakestapleton/forge-data/|$3/|g" \ |
| 104 | -e "s|^text tfzp0 \".*\"|text tfzp0 \"$T/ng/dl.log\"|" \ |
| 105 | -e "s|^text tfzp1 \".*\"|text tfzp1 \"$T/ng/access.log\"|" \ |
| 106 | -e "s|^text tfzwal \".*\"|text tfzwal \"$T/ng/wal\"|" \ |
| 107 | -e "s|^text tfzrad \".*\"|text tfzrad \"$T/bin/rad\"|" \ |
| 108 | -e "s|^text tfzspth \".*\"|text tfzspth \"$T/counts.snapshot\"|" \ |
| 109 | -e "s|^text tfzgent \".*\"|text tfzgent \"$T/bin/getent\"|" "$2" |
| 110 | if grep -q '2130706433 18480\|/home/drakestapleton/forge-data\|/home/drakestapleton/.radicle/storage\|/home/drakestapleton/handoffs/radicle' "$2"; then |
| 111 | bad "compose $2: a live path or port remains"; exit 1 |
| 112 | fi |
| 113 | mkdir -p "$3/logs" |
| 114 | } |
| 115 | start() { # start SRC PORT |
| 116 | taskset -c "$CORES" nice -n 10 "$OMC" < "$1" > "$1.bin" 2> "$1.err" || { bad "build $1: $(cat "$1.err")"; return 1; } |
| 117 | chmod 755 "$1.bin" |
| 118 | taskset -c "$CORES" nice -n 10 "$1.bin" > "$1.log" 2>&1 & |
| 119 | pids+=($!) |
| 120 | for _ in $(seq 50); do curl -s -o /dev/null "http://127.0.0.1:$2/explore" && return 0; sleep 0.2; done |
| 121 | bad "trial $1 did not listen on $2"; return 1 |
| 122 | } |
| 123 | stopall() { for p in "${pids[@]}"; do kill "$p" 2>/dev/null; wait "$p" 2>/dev/null; done; pids=(); sleep 0.5; } |
| 124 | |
| 125 | mkdir -p "$T/base" |
| 126 | git archive "$BASEC" | tar -x -C "$T/base" |
| 127 | compose "$ROOT" "$T/new.om" "$T/dnew" "$PORT" |
| 128 | compose "$T/base" "$T/base.om" "$T/dbase" "$BPORT" |
| 129 | start "$T/new.om" "$PORT" || exit 1 |
| 130 | start "$T/base.om" "$BPORT" || exit 1 |
| 131 | echo "new $(sha256sum < "$T/new.om.bin" | cut -c1-16) base $(git rev-parse --short "$BASEC") $(sha256sum < "$T/base.om.bin" | cut -c1-16)" |
| 132 | DEN=omega-pearl,aien-crypto,pearl-alias,no-such-repo |
| 133 | if python3 server/tests/jsonpages.py "$PORT" "$BPORT" docs/API.md "$DEN" "${JSONPAGES_MAXREPOS:-1000}" > "$T/walk.log" 2>&1; then |
| 134 | ok "walk: $(tail -1 "$T/walk.log")" |
| 135 | else |
| 136 | bad "walk: $(tail -1 "$T/walk.log")"; grep '^FAIL' "$T/walk.log" | head -40 |
| 137 | fi |
| 138 | cp "$T/walk.log" "${JSONPAGES_LOG:-/dev/null}" 2>/dev/null |
| 139 | if out=$(fxcheck "$PORT"); then ok "big-diff fixture: commit and compare JSON parse, <= 8 MiB, diff_truncated true"; else bad "big-diff fixture: $out"; fi |
| 140 | stopall |
| 141 | |
| 142 | # ---- negative controls: each must fail the walk (two repos, no byte compare) |
| 143 | neg() { # neg NAME OM |
| 144 | if ! start "$2" "$PORT"; then bad "negative control $1 did not build"; return; fi |
| 145 | if python3 server/tests/jsonpages.py "$PORT" 0 docs/API.md "$DEN" 2 > "$T/neg.log" 2>&1; then |
| 146 | bad "negative control $1: the walk PASSED" |
| 147 | else |
| 148 | ok "negative control $1: walk fails ($(grep -c '^FAIL' "$T/neg.log") failures, e.g. $(grep -m1 '^FAIL' "$T/neg.log" | cut -c1-140))" |
| 149 | fi |
| 150 | stopall |
| 151 | } |
| 152 | cp "$T/base.om" "$T/n1.om"; sed -i "s|haddr4 a 2130706433 $BPORT|haddr4 a 2130706433 $PORT|" "$T/n1.om" |
| 153 | neg "base build (no JSON forms)" "$T/n1.om" |
| 154 | sed -e 's|^text tfysc4 ",\\"line\\":"|text tfysc4 ",\\"lineno\\":"|' "$T/new.om" > "$T/n2.om" |
| 155 | grep -q 'lineno' "$T/n2.om" || bad "mutant n2 not applied" |
| 156 | neg "renamed key forge/search/1 line" "$T/n2.om" |
| 157 | sed -e 's/^ret brjroute w$/ret brroute2 w/' "$T/new.om" > "$T/n3.om" |
| 158 | grep -q '^ret brjroute w$' "$T/n3.om" && bad "mutant n3 not applied" |
| 159 | neg "browse ignores Accept" "$T/n3.om" |
| 160 | if [ "${STORE_VARIANT:-0}" = 1 ]; then |
| 161 | sed -e 's/^if fdeny k$/if false/' "$T/new.om" > "$T/n4.om" |
| 162 | grep -q '^if fdeny k$' "$T/n4.om" && bad "mutant n4 not applied" |
| 163 | else |
| 164 | sed -e 's/^if and not fdeny i fstok i$/if fstok i/' "$T/new.om" > "$T/n4.om" |
| 165 | grep -q '^if fstok i$' "$T/n4.om" || bad "mutant n4 not applied" |
| 166 | fi |
| 167 | neg "deny list removed" "$T/n4.om" |
| 168 | # n5: brzxs without its BRYCAP stop (the 4270c80d code): the fixture JSON overflows fob and is cut |
| 169 | sed -e '/^put gbzful 0 1$/{n;d}' "$T/new.om" > "$T/n5.om" |
| 170 | [ "$(grep -c '^put gbzful 0 1$' "$T/n5.om")" = 1 ] && ! grep -A1 '^put gbzful 0 1$' "$T/n5.om" | grep -q '^break$' || bad "mutant n5 not applied" |
| 171 | if start "$T/n5.om" "$PORT"; then |
| 172 | if out=$(fxcheck "$PORT"); then bad "negative control no diff budget: fixture check PASSED"; else ok "negative control no diff budget: fixture check fails (${out%%$'\n'*})"; fi |
| 173 | stopall |
| 174 | else |
| 175 | bad "negative control no diff budget did not build" |
| 176 | fi |
| 177 | echo "jsonpages.sh: $pass passed, $fail failed" |
| 178 | [ "$fail" = 0 ] |