interplane-forge
INTERPLANE Forge
Brought by drakestapleton
interplane-forge / store / tests / capacity.sh
| 1 | #!/usr/bin/env bash |
| 2 | # ORACLE: host test driver (bash + curl + git + interplane-native ipl), not product code. |
| 3 | # store/tests/capacity.sh: the allow-list table (FAMAX rows, server/util.om) against what fills it. |
| 4 | # IPL_DIR=<interplane-native checkout with bin/ built> bash store/tests/capacity.sh [RIDS_MD [STORE]] |
| 5 | # (spark; FORGED_CPUS default 0-2 under its pool lock; CAPACITY_PORT default 19995, 19990..19999 only) |
| 6 | # 1. ALARM: the public lines of STORE/catalog.tsv (default ~/interplane-store-owner; the store build serves |
| 7 | # every public line less the deny list) must stay at or under 192 rows (three quarters of FAMAX |
| 8 | # 256). When RIDS_MD exists (default ~/handoffs/radicle/RIDS.md: the allow-list of the Radicle |
| 9 | # build, which the store build does not read), its first table gets the same alarm; when it does |
| 10 | # not exist that line says so and is not counted. Passing the alarm is not a refusal anywhere: |
| 11 | # this test fails loudly so someone grows the table before the forge has to leave projects out |
| 12 | # ("table is full" lines). The numbers are printed either way. |
| 13 | # Negative control: a catalog with 193 public lines (and private lines, which do not count) must |
| 14 | # raise the alarm; one with 192 public lines and 30 private ones must not. |
| 15 | # 2. The store build at FAMAX: a fixture store of a public project under a denied name (aien-crypto), |
| 16 | # a private project and 264 public projects. The expected served list is computed from the |
| 17 | # catalog (store/tests/expect_served.py: the first FAMAX public lines less the deny list): explore |
| 18 | # lists exactly it, its first and last project pages answer 200, the private and denied projects |
| 19 | # and every public line past the table 404, each public line past the table has its "table is |
| 20 | # full" line on stderr, the event stream's first pass reads one source per served project and the |
| 21 | # feed answers. |
| 22 | set -u |
| 23 | cd "$(dirname "$0")/../.." |
| 24 | ROOT=$(pwd) |
| 25 | RIDS=${1:-$HOME/handoffs/radicle/RIDS.md} |
| 26 | STORE=${2:-$HOME/interplane-store-owner} |
| 27 | CORES=${FORGED_CPUS:-0-2} |
| 28 | PORT=${CAPACITY_PORT:-19995} |
| 29 | case $PORT in 1999[0-9]) ;; *) echo "REFUSED: use a private port in 19990..19999"; exit 2 ;; esac |
| 30 | IPLD=${IPL_DIR:?IPL_DIR: an interplane-native checkout with bin/ built} |
| 31 | SITE=${FORGE_SITE_STORE:-$HOME/interplane-store-owner/projects/interplane.io/repo.git} |
| 32 | OMC=$HOME/work/flux/omega-mv/seed/out/omc |
| 33 | ALARM=192 |
| 34 | PASS=0; FAIL=0; PID= |
| 35 | ok() { PASS=$((PASS+1)); echo "PASS $*"; } |
| 36 | bad() { FAIL=$((FAIL+1)); echo "FAIL $*"; } |
| 37 | T=$(mktemp -d /tmp/forge-capacity.XXXXXX); chmod 700 "$T" |
| 38 | trap '[ -n "$PID" ] && kill "$PID" 2> /dev/null; [ -n "${KEEP:-}" ] || rm -rf "$T"' EXIT |
| 39 | U=http://127.0.0.1:$PORT |
| 40 | |
| 41 | rows() { awk -F '|' '/^\| repo \| RID \| default branch/ { if (seen) exit; seen=1; getline; next } |
| 42 | seen && !/^\|/ { exit } seen { n++ } END { print n + 0 }' "$1"; } |
| 43 | pub() { awk -F'\t' '$5 == "public" { n++ } END { print n + 0 }' "$1"; } |
| 44 | alarm() { # alarm NAME COUNT: ok at or under ALARM, else the loud line |
| 45 | if [ "$2" -le "$ALARM" ]; then ok "$1: $2 rows, at or under $ALARM (FAMAX 256)" |
| 46 | else bad "ALARM $1: $2 rows, over $ALARM of the 256 the allow-list table holds; grow FAMAX (server/util.om) before it fills"; fi |
| 47 | } |
| 48 | alarm "public lines of $STORE/catalog.tsv" "$(pub "$STORE/catalog.tsv")" |
| 49 | if [ -f "$RIDS" ]; then |
| 50 | alarm "Radicle-build allow-list (first table of $RIDS)" "$(rows "$RIDS")" |
| 51 | else |
| 52 | echo "NOTE: no $RIDS (the Radicle-build allow-list); the store build does not read it" |
| 53 | fi |
| 54 | # controls on catalogs made here: private lines never count |
| 55 | fl() { printf '%s\t%064d\tmain\tnone\t%s\n' "$1" "$2" "$3"; } |
| 56 | { for i in $(seq 193); do fl "p$i" "$i" public; done; for i in $(seq 30); do fl "q$i" "$((i + 500))" private; done; } > "$T/193.tsv" |
| 57 | { for i in $(seq 192); do fl "p$i" "$i" public; done; for i in $(seq 30); do fl "q$i" "$((i + 500))" private; done; } > "$T/192.tsv" |
| 58 | n=$(pub "$T/193.tsv"); [ "$n" -gt "$ALARM" ] && ok "control: $n public lines (and 30 private) raise the alarm" || bad "control: $n public lines did not raise the alarm" |
| 59 | n=$(pub "$T/192.tsv"); [ "$n" -le "$ALARM" ] && ok "control: $n public lines and 30 private do not raise the alarm" || bad "control: 192 public + 30 private counted as $n" |
| 60 | |
| 61 | # ---- 2. a store of one denied, one private and 264 public projects |
| 62 | ssh-keygen -q -t ed25519 -N "" -f "$T/key" || exit 1 |
| 63 | export GIT_AUTHOR_NAME=fixture GIT_AUTHOR_EMAIL=fixture@invalid GIT_COMMITTER_NAME=fixture GIT_COMMITTER_EMAIL=fixture@invalid |
| 64 | export GIT_AUTHOR_DATE=2026-11-13T00:00:00Z GIT_COMMITTER_DATE=2026-11-13T00:00:00Z |
| 65 | git init -q -b main "$T/w" && echo x > "$T/w/a.txt" && git -C "$T/w" add a.txt && git -C "$T/w" commit -qm one || exit 1 |
| 66 | mk() { # mk NAME VISIBILITY ALIAS |
| 67 | mkdir -p "$T/store/projects/$1" && git clone -q --bare "$T/w" "$T/store/projects/$1/repo.git" || exit 1 |
| 68 | "$IPLD/ipl" init "$T/store" "$1" main "$2" "$3" "$T/key" > /dev/null 2>> "$T/ipl.err" || { bad "ipl init $1: $(tail -1 "$T/ipl.err")"; exit 1; } |
| 69 | echo "$1" > "$T/ev" |
| 70 | "$IPLD/ipl" import "$T/store" "$1" main "$T/ev" "$T/ev" "import-$1" "$T/key" > /dev/null 2>> "$T/ipl.err" || { bad "ipl import $1: $(tail -1 "$T/ipl.err")"; exit 1; } |
| 71 | } |
| 72 | t0=$SECONDS |
| 73 | mk aien-crypto public rad:zCapacityFixtureDeniedAbCdEf |
| 74 | mk cappriv private rad:zCapacityFixturePrivateAbCdEf |
| 75 | for i in $(seq 264); do mk "$(printf 'cap%03d' "$i")" public "$(printf 'rad:zCapacityFixture%03dAbCdEf' "$i")"; done |
| 76 | python3 store/tests/expect_served.py "$T/store" > "$T/want" |
| 77 | awk -F'\t' '$5 == "public" { n++; if (n > 256) print $1 }' "$T/store/catalog.tsv" > "$T/over" |
| 78 | W=$(grep -c . "$T/want") |
| 79 | ok "fixture store: $(wc -l < "$T/store/catalog.tsv") lines, $(pub "$T/store/catalog.tsv") public, $W expected served, $(grep -c . "$T/over") public lines past the table ($((SECONDS - t0)) s)" |
| 80 | [ "$(grep -c . "$T/over")" -gt 0 ] && [ "$W" -gt 200 ] || bad "fixture does not fill the table (expected served $W)" |
| 81 | mkdir -p "$T/data/logs" "$T/social" |
| 82 | (export FORGE_STORE=$T/store FORGE_SITE_STORE=$SITE |
| 83 | { printf 'om2\n'; cat $(./run.sh units); }) | sed -e "s/haddr4 a 2130706433 18480/haddr4 a 2130706433 $PORT/" \ |
| 84 | -e "s|^text tfdata \".*\"|text tfdata \"$T/data/\"|" > "$T/f.om" || { bad "compose"; exit 1; } |
| 85 | taskset -c "$CORES" nice -n 10 "$OMC" < "$T/f.om" > "$T/forged" 2> "$T/omc.err" && chmod 755 "$T/forged" || { bad "build: $(cat "$T/omc.err")"; exit 1; } |
| 86 | FORGE_SOCIAL_DIR=$T/social/ taskset -c "$CORES" nice -n 10 "$T/forged" 2> "$T/forged.log" & |
| 87 | PID=$! |
| 88 | for _ in $(seq 100); do curl -s -o /dev/null "$U/explore" && break; sleep 0.1; done |
| 89 | curl -s "$U/explore.json" > "$T/ex.json" |
| 90 | c=$(python3 -c 'import json,sys; print(json.load(open(sys.argv[1]))["count"])' "$T/ex.json") |
| 91 | [ "$c" = "$W" ] && ok "explore.json count $c = expected served" || bad "explore.json count $c, want $W" |
| 92 | python3 -c 'import json,sys; print("\n".join(r["name"] for r in json.load(open(sys.argv[1]))["repos"]))' "$T/ex.json" | sort > "$T/got.s" |
| 93 | sort "$T/want" > "$T/want.s" |
| 94 | cmp -s "$T/got.s" "$T/want.s" && ok "explore lists exactly the expected served projects" || bad "explore names differ: $(diff "$T/want.s" "$T/got.s" | head -5 | tr '\n' ' ')" |
| 95 | for n in "$(head -1 "$T/want")" "$(tail -1 "$T/want")"; do s=$(curl -s -o /dev/null -w '%{http_code}' "$U/drakestapleton/$n"); [ "$s" = 200 ] && ok "$n page 200" || bad "$n page $s"; done |
| 96 | for n in cappriv aien-crypto $(head -1 "$T/over") $(tail -1 "$T/over"); do s=$(curl -s -o /dev/null -w '%{http_code}' "$U/drakestapleton/$n"); [ "$s" = 404 ] && ok "$n (not served) page 404" || bad "$n page $s"; done |
| 97 | lo=$(grep -o 'project cap[0-9]* left out (the allow-list table is full' "$T/forged.log" | cut -d' ' -f2 | sort -u) |
| 98 | [ "$lo" = "$(sort "$T/over")" ] && ok "each public line past the table left out with a 'table is full' line ($(echo $lo | tr '\n' ' '))" || bad "table-full lines: $(echo $lo) want $(sort "$T/over" | tr '\n' ' ')" |
| 99 | grep -q "project aien-crypto left out (on the deny list" "$T/forged.log" && ok "aien-crypto left out by the deny list" || bad "no deny line for aien-crypto" |
| 100 | ! grep -q 'project cappriv' "$T/forged.log" && ok "the private line is skipped without a line" || bad "a line names cappriv" |
| 101 | ! grep -q 'catalog refused' "$T/forged.log" && ok "no catalog refusal" || bad "catalog refused: $(grep 'catalog refused' "$T/forged.log")" |
| 102 | s=$(curl -s -o /dev/null -w '%{http_code}' "$U/events.json"); L=$(grep '^events: pass ' "$T/forged.log" | tail -1) |
| 103 | [ "$s" = 200 ] && echo "$L" | grep -q "sources read $W," && ok "events.json 200, first pass read $W sources ($L)" || bad "events.json $s, $L (want $W sources)" |
| 104 | s=$(curl -s -o /dev/null -w '%{http_code}' "$U/feed"); [ "$s" = 200 ] && ok "feed 200" || bad "feed $s" |
| 105 | echo "store/tests/capacity.sh: $PASS passed, $FAIL failed" |
| 106 | [ "$FAIL" = 0 ] |