interplane.Get Omega
Read in your language

interplane-forge

INTERPLANE Forge

Brought by drakestapleton

branch main Branches Tags History

interplane-forge / infra / smoke.sh

275 lines · 17660 bytes Raw Blame History
1#!/usr/bin/env bash
2# INTERPLANE Forge smoke test.
3# bash infra/smoke.sh public: https://interplane.io/ (base /), and https://www.aienos.com/forge/ answers
4# 301 (GET/HEAD) or 308 (other methods) to interplane.io (one-site, 2026-11-10)
5# bash infra/smoke.sh local forged direct: http://127.0.0.1:18480/ (or FORGE_SMOKE_PORT) with X-Forge-Base / and /forge/
6# Every line is tagged [site] (existing pages that must never break: a FAIL there means roll back the
7# edge) or [forge] (forge routes). Exit 0 only when everything passes; exit 1 if any [forge] check
8# fails; exit 2 if any [site] check fails.
9# Never touches port 18091. Read-only except one unauthenticated POST that must be refused.
10# bash infra/smoke.sh reach [NAME...] can an outside visitor reach each public name? Lines are
11# tagged [reach] (the public path to a name); exit 3 if any fails: fix the path, nothing to roll back.
12# Details at the "reach" section below.
13set -u
14MODE=${1:-public}
15R=drakestapleton/cuda-crack
16RID_OK=z631r2JJiVT8it4tST7RK24hpowi
17RID_WITHDRAWN=z2ft64NFLsKzWttCXw6NWNbRQLggQ # omega-pearl
18T=$(mktemp -d); trap 'rm -rf "$T"' EXIT
19pass=0; fsite=0; fforge=0; freach=0
20ok() { pass=$((pass+1)); echo "PASS [$1] $2"; }
21bad() { case "$1" in site) fsite=$((fsite+1));; reach) freach=$((freach+1));; *) fforge=$((fforge+1));; esac; echo "FAIL [$1] $2"; }
22
23# req TAG METHOD PATH [extra curl args...] -> sets code, loc, ctype; body in $T/b, headers in $T/h
24req() {
25 local m=$2 p=$3; shift 3
26 local hdr=()
27 [ "$MODE" = local ] && hdr=(-H "X-Forge-Base: $FBASE" -H "X-Real-IP: 127.0.0.1")
28 code=$(curl -sS -o "$T/b" -D "$T/h" -w '%{http_code}' --max-time 60 -X "$m" ${hdr[@]+"${hdr[@]}"} "$@" "$ROOT$p" 2>"$T/e") || code=000
29 loc=$(tr -d '\r' < "$T/h" | sed -n 's/^[Ll]ocation: //p' | tail -1)
30 ctype=$(tr -d '\r' < "$T/h" | sed -n 's/^[Cc]ontent-[Tt]ype: //p' | tail -1)
31}
32want() { # want TAG CODE METHOD PATH [curl args]
33 local tag=$1 w=$2 m=$3 p=$4; shift 4
34 req "$tag" "$m" "$p" "$@"
35 [ "$code" = "$w" ] && ok "$tag" "$m $NAME$p = $code" || bad "$tag" "$m $NAME$p = $code (want $w) $(head -c 200 "$T/e")"
36}
37magic() { # magic PATH HEXPREFIX LABEL
38 want forge 200 GET "$1"
39 local got; got=$(head -c 4 "$T/b" | od -An -tx1 | tr -d ' \n')
40 case "$got" in "$2"*) ok forge "$NAME$1 is $3 ($(wc -c < "$T/b") bytes)";; *) bad forge "$NAME$1 not $3 (magic $got)";; esac
41}
42
43profile() { # profile NAME ROOT FBASE
44 NAME=$1 ROOT=$2 FBASE=$3
45 echo "== $NAME (base $FBASE)"
46 # 10 forge routes that must answer 200. In the store-reading build (SANDBOX_STORE=1 / SMOKE_STORE=1)
47 # collab/ is composed out: patches and issues answer the seam's 501.
48 ST=${SMOKE_STORE:-${SANDBOX_STORE:-0}}
49 for p in explore drakestapleton $R $R/tree/main $R/commits/main $R/blob/main/README.md; do
50 want forge 200 GET "$p"
51 done
52 for p in $R/issues $R/patches; do
53 if [ "$ST" = 1 ]; then want forge 501 GET "$p"; else want forge 200 GET "$p"; fi
54 done
55 magic "$R/archive/refs/heads/main.zip" 504b0304 zip
56 magic "$R/archive/refs/heads/main.tar.gz" 1f8b gzip
57 want forge 200 GET "$R/releases"
58 want forge 200 GET login
59 want forge 200 GET assets/forge.css
60 case "$ctype" in text/css*) ok forge "forge.css is text/css";; *) bad forge "forge.css content-type '$ctype'";; esac
61 # links are built from the base
62 req forge GET drakestapleton
63 if grep -q "href=\"${FBASE}${R}\"" "$T/b"; then ok forge "profile links ${FBASE}${R}"; else bad forge "profile has no href=\"${FBASE}${R}\""; fi
64 if [ "$FBASE" = / ] && grep -q 'href="/forge/' "$T/b"; then bad forge "base / page links into /forge/"; fi
65 # CSP: no script at all, forms only to self
66 csp=$(tr -d '\r' < "$T/h" | sed -n 's/^[Cc]ontent-[Ss]ecurity-[Pp]olicy: //p')
67 case "$csp" in *"script-src 'none'"*) ok forge "CSP script-src 'none'";; *) bad forge "CSP lacks script-src 'none': $csp";; esac
68 case "$csp" in *"form-action 'self'"*) ok forge "CSP form-action 'self'";; *) bad forge "CSP lacks form-action 'self': $csp";; esac
69 n=$(printf '%s\n' "$csp" | grep -c .)
70 [ "$n" = 1 ] && ok forge "page has exactly one CSP" || bad forge "page has $n CSP headers"
71 # raw files keep forged's sandbox CSP (security review P2-3): exactly one header, sandbox first
72 want forge 200 GET "$R/raw/main/README.md"
73 csp=$(tr -d '\r' < "$T/h" | sed -n 's/^[Cc]ontent-[Ss]ecurity-[Pp]olicy: //p')
74 n=$(printf '%s\n' "$csp" | grep -c .)
75 case "$n:$csp" in "1:sandbox;"*) ok forge "raw CSP is forged's sandbox, alone";; *) bad forge "raw CSP: $n header(s): $(printf %s "$csp" | tr '\n' '|')";; esac
76 # rad:<RID> redirects to the canonical URL
77 req forge GET "rad:$RID_OK"
78 case "$code $loc" in 30[12]\ *"${FBASE}${R}") ok forge "rad:$RID_OK -> $code $loc";; *) bad forge "rad:$RID_OK -> $code '$loc' (want 302 to ${FBASE}${R})";; esac
79 # negative controls: withdrawn / private / unknown repos are 404, even by RID
80 want forge 404 GET "rad:$RID_WITHDRAWN"
81 want forge 404 GET drakestapleton/omega-pearl
82 want forge 404 GET drakestapleton/aien-crypto
83 want forge 404 GET drakestapleton/no-such-repo-smoke
84 want forge 404 GET "$R/archive/refs/heads/no-such-branch.zip"
85 # JSON form (docs/API.md): .json suffix and Accept, valid JSON, schema names, 404 for denied repos
86 for p in explore.json "$R.json"; do
87 want forge 200 GET "$p"
88 case "$ctype" in "application/json; charset=utf-8") ok forge "$NAME$p is application/json";; *) bad forge "$NAME$p content-type '$ctype'";; esac
89 if python3 -m json.tool "$T/b" > /dev/null 2>&1; then ok forge "$NAME$p is valid JSON (python3 -m json.tool)"; else bad forge "$NAME$p is not valid JSON"; fi
90 done
91 req forge GET explore.json
92 grep -q '"schema":"forge/explore/1","base":"'"$FBASE"'"' "$T/b" && ok forge "explore.json schema forge/explore/1, base $FBASE" || bad forge "explore.json schema/base"
93 req forge GET "$R.json"
94 # the repo id: the bare old id (Radicle build); the store build's git:<id> (its old id kept for /rad: links)
95 idpat='"rid":"'"$RID_OK"'"'; [ "$ST" = 1 ] && idpat='"rid":"git:[0-9a-f]\{64\}"'
96 grep -q '"schema":"forge/repo/1"' "$T/b" && grep -q "$idpat" "$T/b" && grep -q '"git_fetches":{"count":' "$T/b" && ok forge "$R.json schema forge/repo/1, RID, counts" || bad forge "$R.json schema/rid/counts"
97 req forge GET explore -H 'Accept: application/json'
98 case "$ctype" in application/json*) ok forge "explore with Accept: application/json is JSON";; *) bad forge "explore with Accept JSON: '$ctype'";; esac
99 req forge GET "$R" -H 'Accept: application/json'
100 case "$ctype" in application/json*) ok forge "$R with Accept: application/json is JSON";; *) bad forge "$R with Accept JSON: '$ctype'";; esac
101 req forge GET explore
102 grep -q "<link rel=\"alternate\" type=\"application/json\" href=\"${FBASE}explore.json\">" "$T/b" && ok forge "explore links ${FBASE}explore.json" || bad forge "explore has no alternate link"
103 req forge GET "$R"
104 grep -q "<link rel=\"alternate\" type=\"application/json\" href=\"${FBASE}${R}.json\">" "$T/b" && ok forge "$R links ${FBASE}${R}.json" || bad forge "$R has no alternate link"
105 # the store build has no node: no seeding line
106 if [ "$ST" = 1 ]; then
107 grep -q '<p class="meta">Clones and fetches over HTTPS: ' "$T/b" && grep -q '<p class="meta">Downloads: ' "$T/b" && ! grep -q '<p class="meta">Seeding: ' "$T/b" && ok forge "$R header shows clone and download count lines, no seeding line" || bad forge "$R header lacks the count lines"
108 else
109 grep -q '<p class="meta">Clones and fetches over HTTPS: ' "$T/b" && grep -q '<p class="meta">Downloads: ' "$T/b" && grep -q '<p class="meta">Seeding: ' "$T/b" && ok forge "$R header shows clone, download and seeding count lines" || bad forge "$R header lacks the count lines"
110 fi
111 want forge 404 GET drakestapleton/omega-pearl.json
112 want forge 404 GET drakestapleton/aien-crypto.json
113 want forge 404 GET drakestapleton/no-such-repo-smoke.json
114 # a write without a session is refused: 403, or 303 to <base>login
115 req forge POST "$R/star" -H "Origin: ${ROOT%/}" --data-urlencode "csrf=x"
116 case "$code $loc" in
117 "403 "*) ok forge "POST $R/star without session = 403";;
118 303\ *"${FBASE}login"*) ok forge "POST $R/star without session = 303 -> $loc";;
119 *) bad forge "POST $R/star without session = $code '$loc' (want 403 or 303 to ${FBASE}login)";;
120 esac
121 # a forged X-Forge-Base never reaches a page
122 req forge GET drakestapleton -H "X-Forge-Base: /evil/"
123 if grep -q '/evil/' "$T/b"; then bad forge "injected X-Forge-Base /evil/ reflected"; else ok forge "injected X-Forge-Base ignored"; fi
124}
125
126# ---- reach: can an outside visitor reach each public name? ----------------------------------------
127# bash infra/smoke.sh reach [NAME...] default names: interplane.io www.interplane.io www.aienos.com aienos.com
128# Per name, all tagged [reach]:
129# dns A records from 1.1.1.1 and from 8.8.8.8: both answer, same set. REACH_ADDR=<ip> skips DNS and
130# uses that address (negative control: REACH_ADDR=192.0.2.1, a documentation address nobody serves).
131# https GET https://NAME/ at that address answers within 20 s: 200, or 301/308 to an https:// URL.
132# curl checks the certificate chain, the name and the dates.
133# cert the certificate served for NAME has more than REACH_CERT_DAYS (default 14) days left.
134# http GET http://NAME/ answers within 20 s with 301/308 to https://NAME/ (plain-http visitors and
135# tools that start on http:// must not time out).
136# outside REACH_OUTSIDE=1 (default): check-host.net nodes on the internet fetch https://NAME/ and
137# http://NAME/; at least REACH_OUTSIDE_MIN (default 70) percent of the nodes that report must
138# answer. Reference runs 2026-11-09 against example.com and wikipedia.org: 1 to 2 of 20 nodes
139# time out on their own, so 70 % separates checker noise from a dead path.
140# curl runs on REACH_VIA: hub (default; the Pi, a house-LAN machine, through the router like a visitor
141# whose packets turn around at the router) or local (this host). Not local by default on the Spark:
142# its connections to its own public address lose packets at the router (measured 2026-11-09: 4 of 40
143# requests timed out at 15 s and TLS stalled up to 10 s, against 0 of 40 from the Mac and 0 of 20
144# from the Pi on the same path), which would turn into false failures here.
145reach_lan() {
146 case "${REACH_VIA:-hub}" in
147 local) "$@" ;;
148 hub) ssh -o BatchMode=yes -o ConnectTimeout=10 hub "$(printf '%q ' "$@")" ;;
149 *) echo "REACH_VIA must be hub or local" >&2; return 99 ;;
150 esac
151}
152reach_ipv4() { # 0 when ADDR is four dotted octets, each 0..255
153 local a=$1 rest=$1 p i=0
154 while [ "$i" -lt 4 ]; do
155 case "$rest" in
156 *.*) p=${rest%%.*}; rest=${rest#*.} ;;
157 *) p=$rest; rest= ;;
158 esac
159 case "$p" in
160 ''|*[!0-9]*) return 1 ;;
161 esac
162 [ "${#p}" -le 3 ] && [ "$p" -le 255 ] || return 1
163 i=$((i + 1))
164 [ -z "$rest" ] && break
165 done
166 [ "$i" = 4 ] && [ -z "$rest" ]
167}
168reach_submit() { # reach_submit URL -> prints a check-host.net request id (empty on failure)
169 curl -sS -m 20 -H 'Accept: application/json' "https://check-host.net/check-http?host=$1&max_nodes=${REACH_OUTSIDE_NODES:-12}" 2>/dev/null \
170 | sed -n 's/.*"request_id":"\([^"]*\)".*/\1/p'
171}
172reach_outside() { # reach_outside URL ID -> ok/bad line from the node results
173 local u=$1 id=$2 j="" i good badn pend tot
174 [ -n "$id" ] || { bad reach "outside $u: check-host.net gave no request id (checker unreachable; outside reach not measured)"; return; }
175 for i in 1 2 3 4 5 6; do
176 j=$(curl -sS -m 20 -H 'Accept: application/json' "https://check-host.net/check-result/$id" 2>/dev/null)
177 pend=$(printf '%s' "$j" | grep -o '":null' | wc -l)
178 [ "$pend" = 0 ] && [ -n "$j" ] && break
179 sleep 10
180 done
181 good=$(printf '%s' "$j" | grep -o '\[\[1,' | wc -l)
182 badn=$(printf '%s' "$j" | grep -o '\[\[0,\|\[null,' | wc -l)
183 tot=$((good + badn))
184 if [ "$tot" -lt 5 ]; then bad reach "outside $u: only $tot nodes reported (want >= 5; outside reach not measured)"; return; fi
185 if [ $((100 * good)) -ge $(( ${REACH_OUTSIDE_MIN:-70} * tot )) ]; then ok reach "outside $u: $good of $tot check-host.net nodes answered (request $id)"
186 else bad reach "outside $u: $good of $tot check-host.net nodes answered (want >= ${REACH_OUTSIDE_MIN:-70} %; request $id)"; fi
187}
188reach_name() { # reach_name NAME
189 local n=$1 a1 a8 addr got code loc end days
190 if [ -n "${REACH_ADDR:-}" ]; then addr=$REACH_ADDR; ok reach "dns $n: skipped, REACH_ADDR=$addr"
191 else
192 a1=$(dig +short +time=3 +tries=2 @1.1.1.1 "$n" A 2>/dev/null | grep -E '^[0-9.]+$' | sort | tr '\n' ' ')
193 a8=$(dig +short +time=3 +tries=2 @8.8.8.8 "$n" A 2>/dev/null | grep -E '^[0-9.]+$' | sort | tr '\n' ' ')
194 if [ -n "$a1" ] && [ "$a1" = "$a8" ]; then ok reach "dns $n: 1.1.1.1 and 8.8.8.8 agree ($a1)"
195 else bad reach "dns $n: 1.1.1.1 '$a1' 8.8.8.8 '$a8' (want the same non-empty set)"; fi
196 addr=${a1%% *}
197 fi
198 if [ -z "$addr" ]; then
199 bad reach "https $n: no address"; bad reach "cert $n: no address"; bad reach "http $n: no address"; return
200 fi
201 got=$(reach_lan curl -sS -o /dev/null -m 20 -w '%{http_code} %{redirect_url}' --resolve "$n:443:$addr" "https://$n/" 2>&1 | tr '\n' ' ')
202 code=${got%% *}; loc=${got#* }
203 case "$code" in
204 200) ok reach "https $n via $addr: 200" ;;
205 301|308) case "$loc" in https://*) ok reach "https $n via $addr: $code -> $loc" ;; *) bad reach "https $n via $addr: $code to '$loc' (want an https:// URL)" ;; esac ;;
206 *) bad reach "https $n via $addr: '$got' (want 200, or 301/308 to https)" ;;
207 esac
208 end=$(reach_lan sh -c 'timeout 20 openssl s_client -connect "$1:443" -servername "$2" </dev/null 2>/dev/null | openssl x509 -noout -enddate 2>/dev/null' _ "$addr" "$n" | sed -n 's/^notAfter=//p')
209 if [ -n "$end" ] && days=$(( ( $(date -d "$end" +%s) - $(date +%s) ) / 86400 )); then
210 [ "$days" -gt "${REACH_CERT_DAYS:-14}" ] && ok reach "cert $n: $days days left (notAfter $end)" \
211 || bad reach "cert $n: $days days left (want > ${REACH_CERT_DAYS:-14}; notAfter $end)"
212 else bad reach "cert $n: no certificate read from $addr:443"; fi
213 got=$(reach_lan curl -sS -o /dev/null -m 20 -w '%{http_code} %{redirect_url}' --resolve "$n:80:$addr" "http://$n/" 2>&1 | tr '\n' ' ')
214 code=${got%% *}; loc=${got#* }
215 case "$code $loc" in
216 "301 https://$n/"|"308 https://$n/") ok reach "http $n via $addr: $code -> $loc" ;;
217 *) bad reach "http $n via $addr: '$got' (want 301 or 308 to https://$n/)" ;;
218 esac
219}
220if [ "$MODE" = reach ]; then
221 shift
222 [ $# -gt 0 ] && names=("$@") || names=(interplane.io www.interplane.io www.aienos.com aienos.com)
223 for n in "${names[@]}"; do
224 case "$n" in
225 ""|*[!A-Za-z0-9.-]*) bad reach "name '$n' is not a DNS name; nothing queried"; exit 3 ;;
226 esac
227 done
228 if [ -n "${REACH_ADDR:-}" ]; then
229 case "$REACH_ADDR" in
230 ""|*[!0-9.]*) bad reach "REACH_ADDR '$REACH_ADDR' is not an IPv4 address; nothing queried"; exit 3 ;;
231 esac
232 reach_ipv4 "$REACH_ADDR" || { bad reach "REACH_ADDR '$REACH_ADDR' is not an IPv4 address; nothing queried"; exit 3; }
233 fi
234 declare -A rid=()
235 if [ "${REACH_OUTSIDE:-1}" = 1 ]; then # submit first, so the nodes work while the LAN checks run
236 for n in "${names[@]}"; do for s in https http; do rid[$s://$n/]=$(reach_submit "$s://$n/"); done; done
237 fi
238 for n in "${names[@]}"; do echo "== reach $n"; reach_name "$n"; done
239 if [ "${REACH_OUTSIDE:-1}" = 1 ]; then
240 echo "== outside (check-host.net)"
241 sleep 20
242 for n in "${names[@]}"; do for s in https http; do reach_outside "$s://$n/" "${rid[$s://$n/]}"; done; done
243 fi
244 echo "smoke reach: $pass passed, $freach reach failures"
245 [ "$freach" -gt 0 ] && exit 3
246 exit 0
247fi
248
249if [ "$MODE" = local ]; then
250 profile "local[/] " http://127.0.0.1:${FORGE_SMOKE_PORT:-18480}/ /
251 profile "local[/forge/] " http://127.0.0.1:${FORGE_SMOKE_PORT:-18480}/ /forge/
252else
253 echo "== existing pages"
254 NAME=https://interplane.io/ ROOT=https://interplane.io/ FBASE=/
255 for p in "" quick-start/ concepts/ llms.txt robots.txt sitemap.xml; do want site 200 GET "$p"; done
256 req site GET quick-start; case "$code $loc" in 301\ /quick-start/) ok site "quick-start -> relative $loc";; *) bad site "quick-start -> $code '$loc' (want 301 /quick-start/)";; esac
257 NAME=https://www.aienos.com/ ROOT=https://www.aienos.com/
258 want site 200 GET ""
259 # The old forge address redirects to interplane.io: prefix removed, query kept, 308 for a POST.
260 # [site] lines: a failure means the redirect edge is wrong and is rolled back.
261 for pair in "forge explore" "forge/ explore" "forge/explore explore" "forge/search?q=omega search?q=omega" \
262 "forge/stars stars" "forge/login login" "forge/drakestapleton/CUDApp drakestapleton/CUDApp" \
263 "forge/drakestapleton/hop/releases drakestapleton/hop/releases" "forge/$R/archive/refs/heads/main.zip $R/archive/refs/heads/main.zip"; do
264 from=${pair% *} to=https://interplane.io/${pair#* }
265 req site GET "$from"
266 if [ "$code $loc" = "301 $to" ] && grep -qi '^strict-transport-security:' "$T/h"; then ok site "/$from -> 301 $loc"; else bad site "/$from -> $code '$loc' (want 301 $to with HSTS)"; fi
267 done
268 req site POST forge/login -d x=1
269 [ "$code $loc" = "308 https://interplane.io/login" ] && ok site "POST /forge/login -> 308 $loc" || bad site "POST /forge/login -> $code '$loc' (want 308 https://interplane.io/login)"
270 profile https://interplane.io/ https://interplane.io/ /
271fi
272echo "smoke: $pass passed, $fsite site failures, $fforge forge failures"
273[ "$fsite" -gt 0 ] && exit 2
274[ "$fforge" -gt 0 ] && exit 1
275exit 0