interplane.Get Omega
Read in your language

interplane-forge

INTERPLANE Forge

Brought by drakestapleton

branch main Branches Tags History

interplane-forge / store / tests / crawl-store.sh

59 lines · 4187 bytes Raw Blame History
1#!/usr/bin/env bash
2# ORACLE: host test driver (bash + curl + python3 store/tests/radcrawl.py), not product code.
3# store/tests/crawl-store.sh: the store-reading build of this tree, on the production store (read only,
4# STORE default ~/interplane-store-owner; it serves every public catalog line less the deny list), crawled from /
5# (radcrawl.py: /, /explore, /agents.json, /events.json, /feed, project homes, ?format=text forms and
6# the links they lead to, up to CRAWL_LIMIT addresses, default 400): no Radicle pattern of
7# RadFreeForgeAndSI's crawl may appear in what the forge writes; repository content (READMEs,
8# descriptions, commit subjects, files) is counted apart and allowed.
9# Negative control: the same build with one forge-written sentence (the feed intro) naming Radicle
10# must give a forge hit on /feed.
11# Private port CRAWL_PORT (default 19996, 19990..19999 only), data dir and social dir in a temp dir;
12# FORGED_CPUS default 0-2. Never 18480, ~/forge-data or a write to the store.
13set -u
14cd "$(dirname "$0")/../.."
15STORE=${STORE:-$HOME/interplane-store-owner}
16CORES=${FORGED_CPUS:-0-2}
17PORT=${CRAWL_PORT:-19996}
18case $PORT in 1999[0-9]) ;; *) echo "REFUSED: use a private port in 19990..19999"; exit 2 ;; esac
19OMC=$HOME/work/flux/omega-mv/seed/out/omc
20T=$(mktemp -d /tmp/crawl-store.XXXXXX); chmod 700 "$T"
21PASS=0; FAIL=0; PID=
22ok() { PASS=$((PASS+1)); echo "PASS $*"; }
23bad() { FAIL=$((FAIL+1)); echo "FAIL $*"; }
24stop() { [ -n "$PID" ] && kill "$PID" 2> /dev/null; [ -n "$PID" ] && wait "$PID" 2> /dev/null; PID=; }
25trap 'stop; [ -n "${KEEP:-}" ] || rm -rf "$T"' EXIT
26if ss -ltn | grep -q "127.0.0.1:$PORT "; then echo "NOT_RUN: port $PORT busy"; exit 3; fi
27mkdir -p "$T/data/logs" "$T/social"
28(export FORGE_STORE=$STORE; { printf 'om2\n'; cat $(./run.sh units); }) \
29 | sed -e "s/haddr4 a 2130706433 18480/haddr4 a 2130706433 $PORT/" -e "s|^text tfdata \".*\"|text tfdata \"$T/data/\"|" > "$T/f.om" || { bad "compose"; exit 1; }
30grep -q '2130706433 18480\|/home/drakestapleton/forge-data/' "$T/f.om" && { bad "a live port or data path remains"; exit 1; }
31build() { taskset -c "$CORES" nice -n 10 "$OMC" < "$1.om" > "$1" 2> "$1.err" && chmod 755 "$1"; }
32start() {
33 FORGE_SOCIAL_DIR=$T/social/ taskset -c "$CORES" nice -n 10 "$1" 2> "$1.log" &
34 PID=$!
35 for _ in $(seq 100); do curl -s -o /dev/null "http://127.0.0.1:$PORT/explore" && return 0; sleep 0.1; done
36 return 1
37}
38build "$T/f" || { bad "build: $(cat "$T/f.err")"; exit 1; }
39ok "store build $(sha256sum < "$T/f" | cut -c1-16), catalog $(grep -c . "$STORE/catalog.tsv") lines"
40start "$T/f" || { bad "start"; exit 1; }
41want=$(python3 store/tests/expect_served.py --count "$STORE")
42got=$(curl -s "http://127.0.0.1:$PORT/explore.json" | python3 -c 'import json,sys; print(json.load(sys.stdin)["count"])')
43[ "$got" = "$want" ] && ok "explore.json count $got = public catalog lines less the deny list (store/tests/expect_served.py)" || bad "explore.json count $got, want $want"
44python3 store/tests/radcrawl.py "http://127.0.0.1:$PORT" "${CRAWL_LIMIT:-400}" "$T/crawl.json" > "$T/crawl.out" 2>&1; rc=$?
45cat "$T/crawl.out"
46L=$(grep '^RADCRAWL ' "$T/crawl.out")
47[ "$rc" = 0 ] && ok "crawl: no Radicle pattern in forge-written text ($L)" || bad "crawl: forge-written Radicle text ($L)"
48n=$(echo "$L" | sed -n 's/.*urls=\([0-9]*\).*/\1/p'); [ "${n:-0}" -ge 100 ] && ok "crawl reached $n addresses" || bad "crawl reached only ${n:-0} addresses"
49stop
50# negative control: the feed intro names Radicle
51sed 's/What happened on this forge, newest first/What happened on this Radicle forge, newest first/' "$T/f.om" > "$T/m.om"
52cmp -s "$T/f.om" "$T/m.om" && { bad "control: mutation did not apply"; exit 1; }
53build "$T/m" || { bad "control build"; exit 1; }
54start "$T/m" || { bad "control start"; exit 1; }
55CRAWL_SEEDS_ONLY=1 python3 store/tests/radcrawl.py "http://127.0.0.1:$PORT" 40 "$T/crawl-m.json" > "$T/crawl-m.out" 2>&1; rc=$?
56grep -q '^FORGE 200 [0-9]* /feed ' "$T/crawl-m.out" && [ "$rc" = 1 ] && ok "control: a Radicle word in the feed intro is a forge hit on /feed" || bad "control not caught: $(grep '^RADCRAWL' "$T/crawl-m.out")"
57stop
58echo "store/tests/crawl-store.sh: $PASS passed, $FAIL failed"
59[ "$FAIL" = 0 ]