interplane.Get Omega
Read in your language

interplane-forge

INTERPLANE Forge

Brought by drakestapleton

branch main Branches Tags History

interplane-forge / social / tests / lib.sh

105 lines · 5942 bytes Raw Blame History
1# ForgeSocial test library, sourced by run.sh and lockout.sh (from ~/work/forge/web).
2# Builds a TEST copy of forged with $SOCIAL_SRC/*.om (default social/) composed in, on a private port
3# and a private data dir (main.om's port and util.om's tfdata are rewritten in the test copy only),
4# makes two throwaway ed25519 keys (never a real signing key) and starts the server.
5set -u
6cd "$(dirname "$0")/../.."
7OMV=$HOME/work/flux/omega-mv
8OMC=$OMV/seed/out/omc
9PORT=${SOCIAL_TEST_PORT:-18489}
10CORES=${SOCIAL_TEST_CORES:-2}
11SRC=${SOCIAL_SRC:-social}
12T=$(mktemp -d /tmp/forgesocial.XXXXXX)
13mkdir -p "$T/data" "$T/social"
14PASS=0; FAIL=0
15ok() { PASS=$((PASS+1)); echo "PASS $*"; }
16bad() { FAIL=$((FAIL+1)); echo "FAIL $*"; }
17check() { if [ "$1" = "$2" ]; then ok "$3 ($1)"; else bad "$3: want $2, got $1"; fi; }
18
19# ---- build the test binary from the build's own unit list (social/tests/units.sh), after the alarm
20# social/tests/units-check.sh has passed; omc reads exactly the units social_units wrote to units.txt
21# The Radicle source reads FORGE_TEST_RSTORE (default ~/radicle-storage-frozen/storage, the read-only
22# copy kept after the Radicle removal of 2026-11-14); the site chrome comes from its interplane.io.
23# STORE_VARIANT=1: the store-reading source instead (the store's catalog, ~/interplane-store-owner by
24# default, read only; every public line less the deny list), every other unit the same: FORGE_STORE
25# is exported, so run.sh's own list names the store source. Without STORE_VARIANT a FORGE_STORE of
26# the caller is dropped: the list is the Radicle-reading one.
27RSTORE=${FORGE_TEST_RSTORE:-$HOME/radicle-storage-frozen/storage}
28export FORGE_SITE_STORE=${FORGE_SITE_STORE:-$RSTORE/z399yKvnXcBQNkKoq86iBDgTvQ5QV}
29if [ "${STORE_VARIANT:-0}" = 1 ]; then
30 export FORGE_STORE=${FORGE_STORE:-$HOME/interplane-store-owner}
31 echo "STORE_VARIANT: store-reading source $FORGE_STORE"
32else
33 unset FORGE_STORE
34fi
35buildfail() { echo "BUILD FAILED: $*"; [ -n "${KEEP:-}" ] || rm -rf "$T"; exit 1; }
36./run.sh chrome > /dev/null || buildfail "./run.sh chrome"
37sh social/tests/units-check.sh > "$T/units-check.out" 2>&1 || { cat "$T/units-check.out"; buildfail social/tests/units-check.sh; }
38. social/tests/units.sh
39social_units "$SRC" > "$T/units.txt" || buildfail "no unit list (reason above)"
40{ printf 'om2\n'; cat $(cat "$T/units.txt"); } \
41 | sed -e "s|^text tfdata \".*\"|text tfdata \"$T/data/\"|" -e "s/18480/$PORT/g" -e "s|/home/drakestapleton/.radicle/storage/|$RSTORE/|g" > "$T/all.om"
42if ! taskset -c "$CORES" nice -n 10 "$OMC" < "$T/all.om" > "$T/forged" 2> "$T/omc.err"; then
43 buildfail "$(cat "$T/omc.err")"
44fi
45chmod +x "$T/forged"
46echo "built $(sha256sum < "$T/forged" | cut -c1-16) from $SRC in $T"
47
48start() {
49 FORGE_SOCIAL_DIR="$T/social/" taskset -c "$CORES" nice -n 10 "$T/forged" 2>> "$T/forged.err" &
50 PID=$!
51 for i in $(seq 50); do curl -s -o /dev/null "http://127.0.0.1:$PORT/" && return 0; sleep 0.1; done
52 echo "server did not start"; cat "$T/forged.err"; exit 1
53}
54stop() { kill "$PID" 2>/dev/null; wait "$PID" 2>/dev/null; }
55trap 'stop; [ -n "${KEEP:-}" ] || rm -rf "$T"' EXIT
56B="http://127.0.0.1:$PORT"
57REPO=$(awk -F'|' '/^\| *[a-z0-9-]+ *\| *(rad:)?z[0-9A-Za-z]+/ {gsub(/ /,"",$2); print $2; exit}' "$HOME/handoffs/radicle/RIDS.md")
58[ -n "$REPO" ] || REPO=cuda-crack
59R=/drakestapleton/$REPO
60
61# status of a request: code(method path [curl args...])
62# code: an HTML body is read without the send-time translation hints of server/tr.om (translate="no"
63# attributes and <span translate="no"> around hashes and ids; server/tests/translate_check.py strip)
64code() {
65 m=$1; p=$2; local c; shift 2
66 c=$(curl -s -o "$T/body" -D "$T/hdr" -X "$m" "$@" "$B$p" -w '%{http_code}')
67 if grep -qi '^content-type: text/html' "$T/hdr"; then python3 server/tests/translate_check.py strip "$T/body" "$T/body.s" && mv "$T/body.s" "$T/body"; fi
68 printf '%s' "$c"
69}
70hdr() { grep -i "^$1:" "$T/hdr" | head -1 | cut -d' ' -f2- | tr -d '\r'; }
71field() { grep -o "name=\"$1\" value=\"[^\"]*\"" "$T/body" | head -1 | sed 's/.*value="//; s/"$//'; }
72stars() { code GET "$R/stargazers" >/dev/null; grep -o 'stargazers">[0-9][0-9]*' "$T/body" | head -1 | grep -o '[0-9]*$'; }
73# the same count from the JSON form (forge/stargazers/1), and the length of its users list
74jstars() { code GET "$R/stargazers" -H 'Accept: application/json' >/dev/null
75 python3 -c 'import json,sys; d=json.load(open(sys.argv[1])); print(d["schema"], d["count"], len(d["users"]))' "$T/body"; }
76
77# ---- throwaway keys + DID oracle (did:key = z + base58btc(0xed 0x01 || pk))
78ssh-keygen -q -t ed25519 -N '' -C t1 -f "$T/k1"
79ssh-keygen -q -t ed25519 -N '' -C t2 -f "$T/k2"
80did() { python3 - "$1" <<'EOF'
81import sys, base64
82blob = base64.b64decode(open(sys.argv[1]).read().split()[1])
83raw = b'\xed\x01' + blob[-32:]
84A = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
85n = int.from_bytes(raw, 'big'); s = ''
86while n: n, r = divmod(n, 58); s = A[r] + s
87print('did:key:z' + '1' * (len(raw) - len(raw.lstrip(b'\0'))) + s)
88EOF
89}
90D1=$(did "$T/k1.pub"); D2=$(did "$T/k2.pub")
91
92# ---- sign-in helpers. The cookie names are read from Set-Cookie, so the old code (forge_pre /
93# forge_session) and the new (__Host-forge_pre / __Host-forge_session) both run under lockout.sh.
94login_get() { # [extra curl args]
95 c=$(code GET /login "$@"); check "$c" 200 "GET /login"
96 PREN=$(hdr set-cookie | sed -n 's/^\([A-Za-z_-]*forge_pre\)=.*/\1/p')
97 PRE=$(hdr set-cookie | sed -n 's/^[A-Za-z_-]*forge_pre=\([0-9a-f]*\);.*/\1/p')
98 CSRF=$(field csrf); NONCE=$(field nonce); TS=$(field ts)
99}
100sign() { printf '%s' "interplane-forge-login:$NONCE:$TS" | ssh-keygen -Y sign -f "$1" -n interplane-forge > "$T/sig" 2>/dev/null; }
101login_post() { # did [extra curl args]
102 d=$1; shift
103 code POST /login -H "Cookie: ${PREN:-__Host-forge_pre}=$PRE" --data-urlencode "csrf=$CSRF" --data-urlencode "nonce=$NONCE" \
104 --data-urlencode "ts=$TS" ${d:+--data-urlencode "did=$d"} --data-urlencode "sig@$T/sig" "$@"
105}