interplane.Get Omega
Read in your language

interplane-forge

INTERPLANE Forge

Brought by drakestapleton

branch main Branches Tags History

interplane-forge / store / tests / capacity.sh

106 lines · 8650 bytes Raw Blame History
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.
22set -u
23cd "$(dirname "$0")/../.."
24ROOT=$(pwd)
25RIDS=${1:-$HOME/handoffs/radicle/RIDS.md}
26STORE=${2:-$HOME/interplane-store-owner}
27CORES=${FORGED_CPUS:-0-2}
28PORT=${CAPACITY_PORT:-19995}
29case $PORT in 1999[0-9]) ;; *) echo "REFUSED: use a private port in 19990..19999"; exit 2 ;; esac
30IPLD=${IPL_DIR:?IPL_DIR: an interplane-native checkout with bin/ built}
31SITE=${FORGE_SITE_STORE:-$HOME/interplane-store-owner/projects/interplane.io/repo.git}
32OMC=$HOME/work/flux/omega-mv/seed/out/omc
33ALARM=192
34PASS=0; FAIL=0; PID=
35ok() { PASS=$((PASS+1)); echo "PASS $*"; }
36bad() { FAIL=$((FAIL+1)); echo "FAIL $*"; }
37T=$(mktemp -d /tmp/forge-capacity.XXXXXX); chmod 700 "$T"
38trap '[ -n "$PID" ] && kill "$PID" 2> /dev/null; [ -n "${KEEP:-}" ] || rm -rf "$T"' EXIT
39U=http://127.0.0.1:$PORT
40
41rows() { awk -F '|' '/^\| repo \| RID \| default branch/ { if (seen) exit; seen=1; getline; next }
42 seen && !/^\|/ { exit } seen { n++ } END { print n + 0 }' "$1"; }
43pub() { awk -F'\t' '$5 == "public" { n++ } END { print n + 0 }' "$1"; }
44alarm() { # 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}
48alarm "public lines of $STORE/catalog.tsv" "$(pub "$STORE/catalog.tsv")"
49if [ -f "$RIDS" ]; then
50 alarm "Radicle-build allow-list (first table of $RIDS)" "$(rows "$RIDS")"
51else
52 echo "NOTE: no $RIDS (the Radicle-build allow-list); the store build does not read it"
53fi
54# controls on catalogs made here: private lines never count
55fl() { 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"
58n=$(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"
59n=$(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
62ssh-keygen -q -t ed25519 -N "" -f "$T/key" || exit 1
63export GIT_AUTHOR_NAME=fixture GIT_AUTHOR_EMAIL=fixture@invalid GIT_COMMITTER_NAME=fixture GIT_COMMITTER_EMAIL=fixture@invalid
64export GIT_AUTHOR_DATE=2026-11-13T00:00:00Z GIT_COMMITTER_DATE=2026-11-13T00:00:00Z
65git 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
66mk() { # 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}
72t0=$SECONDS
73mk aien-crypto public rad:zCapacityFixtureDeniedAbCdEf
74mk cappriv private rad:zCapacityFixturePrivateAbCdEf
75for i in $(seq 264); do mk "$(printf 'cap%03d' "$i")" public "$(printf 'rad:zCapacityFixture%03dAbCdEf' "$i")"; done
76python3 store/tests/expect_served.py "$T/store" > "$T/want"
77awk -F'\t' '$5 == "public" { n++; if (n > 256) print $1 }' "$T/store/catalog.tsv" > "$T/over"
78W=$(grep -c . "$T/want")
79ok "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)"
81mkdir -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; }
85taskset -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; }
86FORGE_SOCIAL_DIR=$T/social/ taskset -c "$CORES" nice -n 10 "$T/forged" 2> "$T/forged.log" &
87PID=$!
88for _ in $(seq 100); do curl -s -o /dev/null "$U/explore" && break; sleep 0.1; done
89curl -s "$U/explore.json" > "$T/ex.json"
90c=$(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"
92python3 -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"
93sort "$T/want" > "$T/want.s"
94cmp -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' ' ')"
95for 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
96for 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
97lo=$(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' ' ')"
99grep -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")"
102s=$(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)"
104s=$(curl -s -o /dev/null -w '%{http_code}' "$U/feed"); [ "$s" = 200 ] && ok "feed 200" || bad "feed $s"
105echo "store/tests/capacity.sh: $PASS passed, $FAIL failed"
106[ "$FAIL" = 0 ]