Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/interplane-forge/blob/main/nodes/tests/ab.sh # interplane-forge INTERPLANE Forge Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `interplane-forge / nodes / tests / ab.sh` 282 lines ยท 14777 bytes Raw Blame History 1 # ORACLE: host A/B harness (sh + git + curl + python3 json) for forged. Not product code; changes no live state. 2 # nodes/tests/ab.sh build DIR base COMMIT | build DIR after | build DIR mut | check DIR | time DIR 3 # Run each step under a queen pool lock; it never touches :18480, the live snapshot or live storage. 4 # build one trial forged with the pinned omc into DIR: base (the units of COMMIT), after (this 5 # working tree) or mut (this tree with two faults: a git grep stopped for having enough 6 # lines is treated as failed, and nodes/head.om never finds a branch). Each variant has its own port 7 # (base AB_PORT, after +1, mut +2); data dir, node snapshot and Radicle storage are moved 8 # into DIR/run. The storage there is a view: a symlink to every real repository, except 9 # two fixtures whose HEAD file is changed (their objects and refs are the real ones): 10 # one names a delegate branch that is not main, one is detached (a bare commit id). 11 # check 1. parity: base (git symbolic-ref) and after (nodes/head.om) running side by side give 12 # byte-equal home, commits, branches and in-repository search pages for every public repository and both 13 # fixtures, under / and /forge/; /search pages are byte-equal between base (reads all of 14 # every git grep) and after (stops each grep once the page has its lines) for queries 15 # with and without the 100-hit stop, and no git child is left behind. Negative control: 16 # mut differs on the non-main fixture and on search. 17 # 2. /status and /status.json from fixture snapshots: public rows shown with their numbers, 18 # withdrawn, unlisted and poisoned rows never shown, malformed or overlong lines dropped 19 # with the server still answering, JSON parses; old format, wrong node, a 25-digit time, 20 # missing file give "not measured"; an old snapshot is flagged; POST is refused. 21 # time nodes/tests/measure.sh against base, after, base, after: one server at a time on the same 22 # cores, so slow drift of the machine hits both. Samples land in DIR/-. 23 # CORES (client, default 12) and SRV_CORES (servers and omc, default 13-14) must be inside the pool 24 # lock the caller holds. AB_PORT default 18486 (uses 18486-18488). 25 set -eu 26 CMD=$1 27 OUT=$(realpath -m "$2") 28 cd "$(dirname "$0")/../.." 29 ROOT=$(pwd) 30 OMC=$HOME/work/flux/omega-mv/seed/out/omc 31 PIN=`3ad9f10f64309e7acf8a725082b28e23a2a4aeb07e98322fb4dc0fcd8fc93194` 32 CORES=${CORES:-12} 33 SRV=${SRV_CORES:-13-14} 34 P0=${AB_PORT:-18486} 35 SNAP=$OUT/run/nodes.txt 36 STORE=$OUT/run/store 37 RIDS=$HOME/handoffs/radicle/RIDS.md 38 NID=`z6MkfZDue1TbaNFi3ZzcD9uiTeduPLC52ucdFVuLKZwexxhK` 39 T=$(mktemp -d) 40 pids= 41 pass=0 42 fail=0 43 ok() { pass=$((pass + 1)); echo "PASS $*"; } 44 bad() { fail=$((fail + 1)); echo "FAIL $*"; } 45 cleanup() { 46 for p in $pids; do kill "$p" 2> /dev/null || true; done 47 git -C "$ROOT" worktree remove --force "$T/base" 2> /dev/null || true 48 rm -rf "$T" 49 } 50 trap cleanup EXIT 51 mkdir -p "$OUT/run" 52 port() { case $1 in base) echo "$P0" ;; after) echo $((P0 + 1)) ;; mut) echo $((P0 + 2)) ;; esac; } 53 compose() { # compose DIR VARIANT: every unit of DIR's run.sh on stdout, moved into $OUT/run 54 (cd "$1" && { printf 'om2\n'; for u in $(sh run.sh units); do cat "$u"; done; }) | 55 sed -e "s|haddr4 a `2130706433` 18480|haddr4 a `2130706433` $(port "$2")|" \ 56 -e "s|/home/drakestapleton/forge-data/|$OUT/run/data-$2/|g" \ 57 -e "s|/home/drakestapleton/.local/state/aien-factory/nodes.txt|$SNAP|" \ 58 -e "s|/home/drakestapleton/.radicle/storage/|$STORE/|" 59 } 60 build() { # build VARIANT: $T/src.om into $OUT/VARIANT.bin 61 if ! grep -q "`2130706433` $(port "$1")" "$T/src.om" || 62 grep -q '`2130706433` 18480\|/home/drakestapleton/forge-data\|aien-factory/nodes.txt\|/home/drakestapleton/.radicle/storage' "$T/src.om"; then 63 echo "redirect failed for $1" 64 exit 1 65 fi 66 [ "$(sha256sum "$OMC" | cut -d' ' -f1)" = "$PIN" ] || { echo "NOT_RUN: omc is not the run.sh pin"; exit 2; } 67 if ! taskset -c "$SRV" nice -n 10 "$OMC" < "$T/src.om" > "$OUT/$1.bin" 2> "$T/err"; then 68 echo "BUILD FAILED $1: $(cat "$T/err")" 69 exit 1 70 fi 71 chmod 755 "$OUT/$1.bin" 72 echo "$1 bytes $(stat -c %s "$OUT/$1.bin") sha256 $(sha256sum "$OUT/$1.bin" | cut -d' ' -f1)" | tee -a "$OUT/binaries.txt" 73 } 74 store() { # the storage view and its two HEAD fixtures; prints "NAME1 BRANCH1 NAME2" for check 75 rm -rf "$STORE" 76 mkdir -p "$STORE" 77 for d in "$HOME"/.radicle/storage/*; do ln -s "$d" "$STORE/${d##*/}"; done 78 # public rows of the first RIDS.md table: "name rid" 79 awk -F'|' 't && !/^\|/ {exit} /^\| repo \| RID \| default branch/{t=1; next} t && $3 ~ /rad:z/ {gsub(/ /,"",$2); gsub(/ /,"",$3); print $2, substr($3,5)}' "$RIDS" > "$OUT/run/public.txt" 80 f1= b1= f2= 81 while read -r n r; do 82 [ -d "$HOME/.radicle/storage/$r" ] || continue 83 if [ -z "$f1" ]; then 84 b=$(git --git-dir "$HOME/.radicle/storage/$r" for-each-ref --format='%(refname)' "refs/namespaces/$NID/refs/heads/" | 85 sed "s|^refs/namespaces/$NID/refs/heads/||" | grep -v '^main$' | grep '^[A-Za-z0-9][A-Za-z0-9._/-]*$' | head -n 1 || true) 86 if [ -n "$b" ]; then f1=$n b1=$b r1=$r; continue; fi 87 fi 88 if [ -z "$f2" ]; then f2=$n r2=$r; fi 89 done < "$OUT/run/public.txt" 90 [ -n "$f1" ] && [ -n "$f2" ] || { echo "no fixture repositories found"; exit 1; } 91 for r in "$r1" "$r2"; do 92 rm "$STORE/$r" 93 mkdir "$STORE/$r" 94 for e in "$HOME/.radicle/storage/$r"/*; do 95 [ "${e##*/}" = HEAD ] || ln -s "$e" "$STORE/$r/${e##*/}" 96 done 97 done 98 printf 'ref: refs/heads/%s\n' "$b1" > "$STORE/$r1/HEAD" 99 git --git-dir "$HOME/.radicle/storage/$r2" rev-parse refs/heads/main > "$STORE/$r2/HEAD" 100 echo "$f1 $b1 $f2" 101 } 102 start() { # start VARIANT 103 rm -rf "$OUT/run/data-$1" 104 mkdir -p "$OUT/run/data-$1/logs" 105 taskset -c "$SRV" nice -n 10 "$OUT/$1.bin" > "$OUT/run/$1.log" 2>&1 & 106 pids="$pids $!" 107 eval "pid_$1=$!" 108 for _ in $(seq 100); do 109 curl -s -o /dev/null "http://127.0.0.1:$(port "$1")/explore" && return 0 110 sleep 0.1 111 done 112 echo "trial forged $1 did not listen on $(port "$1")" 113 exit 1 114 } 115 stop() { # stop VARIANT 116 eval "sp=\$pid_$1" 117 kill "$sp" 118 wait "$sp" 2> /dev/null || true 119 for _ in $(seq 50); do 120 ss -Htln "sport = :$(port "$1")" | grep -q . || return 0 121 sleep 0.1 122 done 123 echo "port $(port "$1") still busy" 124 exit 1 125 } 126 get() { # get VARIANT BASE PATH [curl args]: body on stdout 127 gv=$1 gb=$2 gp=$3 128 shift 3 129 taskset -c "$CORES" curl -s -H "X-Forge-Base: $gb" -H 'X-Real-IP: 127.0.0.1' "$@" "http://127.0.0.1:$(port "$gv")$gp" 130 } 131 pair() { # pair A B BASE PATH: A and B serve the same bytes (one refetch allowed for a clock tick) 132 for _ in 1 2; do 133 get "$1" "$3" "$4" > "$T/pa" 134 get "$2" "$3" "$4" > "$T/pb" 135 if [ -s "$T/pa" ] && cmp -s "$T/pa" "$T/pb"; then return 0; fi 136 done 137 return 1 138 } 139 has() { grep -qF -- "$2" "$1"; } 140 busy() { for v in base after mut; do ss -Htln "sport = :$(port $v)" | grep -q . && return 0; done; return 1; } 141 case $CMD in 142 build) 143 case $3 in 144 base) 145 git -C "$ROOT" worktree add --detach "$T/base" "$4" > /dev/null 2>&1 146 compose "$T/base" base > "$T/src.om" 147 ;; 148 after) compose "$ROOT" after > "$T/src.om" ;; 149 mut) 150 compose "$ROOT" mut | sed -e 's/^full = eq get nsfull 0 1$/full = eq get nsfull 0 2/' -e 's/^fpt tnshead$/fpt tnsrefh/' > "$T/src.om" 151 [ "$(grep -c '^full = eq get nsfull 0 2$' "$T/src.om")" = 1 ] && [ "$(grep -c '^fpt tnsrefh$' "$T/src.om")" = 1 ] && 152 ! grep -q '^fpt tnshead$' "$T/src.om" || { echo "mutant sed did not apply"; exit 1; } 153 ;; 154 *) echo "build base COMMIT | after | mut"; exit 2 ;; 155 esac 156 build "$3" 157 ;; 158 check) 159 if busy; then echo "NOT_RUN: a port of $P0-$((P0 + 2)) is busy"; exit 3; fi 160 set -- $(store) 161 [ $# = 3 ] || { echo "storage view failed"; exit 1; } 162 f1=$1 b1=$2 f2=$3 163 echo "fixtures: $f1 HEAD -> $b1 (not main), $f2 HEAD detached" 164 start base 165 start after 166 start mut 167 n=0 bad1= 168 while read -r name rid; do 169 [ -e "$STORE/$rid" ] || continue 170 for b in / /forge/; do 171 for p in "/drakestapleton/$name" "/drakestapleton/$name/commits" "/drakestapleton/$name/branches" "/drakestapleton/$name/search?q=main"; do 172 n=$((n + 1)) 173 pair base after "$b" "$p" || bad1="$bad1 $b$p" 174 done 175 done 176 done < "$OUT/run/public.txt" 177 if [ -z "$bad1" ]; then ok "HEAD parity: $n repository pages byte-equal, git symbolic-ref vs nodes/head.om"; else bad "HEAD parity:$bad1"; fi 178 get after / "/drakestapleton/$f1" > "$T/f1" 179 if has "$T/f1" "/drakestapleton/$f1/tree/$b1"; then ok "fixture $f1: page follows HEAD to $b1"; else bad "fixture $f1: $b1 not on the page"; fi 180 if ! pair base mut / "/drakestapleton/$f1"; then ok "negative control: mutant without nodes/head.om differs on $f1"; else bad "negative control: mutant equals base on $f1"; fi 181 get after / "/drakestapleton/$f2" > "$T/f2" 182 if has "$T/f2" "/drakestapleton/$f2/tree/main"; then ok "fixture $f2: detached HEAD falls back to main"; else bad "fixture $f2: no main link"; fi 183 # hits per query (after, base /): which ones end at the 100-hit stop inside a repository 184 queries='omega fn%20main zz9qq8xx7nomatch e %3Cscript%3E Wolfram kanban' 185 bad2= bad3= hits= 186 for q in $queries; do 187 for b in / /forge/; do 188 pair base after "$b" "/search?q=$q" || bad2="$bad2 $b?q=$q" 189 pair base mut "$b" "/search?q=$q" || bad3="$bad3 $q" 190 done 191 hits="$hits $q=$(get after / "/search?q=$q" | grep -o '

' | wc -l)" 192 done 193 echo "hits per query:$hits" 194 if [ -z "$bad2" ]; then ok "search parity: 14 pages byte-equal, base (whole output) vs after (early stop)"; else bad "search parity:$bad2"; fi 195 if [ -n "$bad3" ]; then ok "negative control: mutant that drops a stopped grep differs on search ($bad3 )"; else bad "negative control: mutant search equals base"; fi 196 for v in base after; do 197 eval "cp=\$pid_$v" 198 k=$(ps --ppid "$cp" -o pid= | wc -l) 199 if [ "$k" = 0 ]; then ok "$v: no git child left after the searches"; else bad "$v: $k children left"; fi 200 done 201 stop base 202 stop mut 203 # fixture rows: two public RIDs and their names, one withdrawn RID (read from RIDS.md here, never 204 # written into this repository), one unlisted RID and two poisoned lines 205 set -- $(head -n 2 "$OUT/run/public.txt") 206 n1=$1 r1=$2 n2=$3 r2=$4 207 wd=$(awk -F'|' '/^## WITHDRAWN/{t=1} t && $3 ~ /rad:z/ {gsub(/ /,"",$3); print substr($3,5); exit}' "$RIDS") 208 [ -n "$r2" ] && [ -n "$wd" ] || { echo "fixture RIDs not found"; exit 1; } 209 now=$(date +%s) 210 fixture() { # fixture VERSION TIME NODE 211 printf '%s\n%s\n%s\n7\n' "$1" "$2" "$3" 212 printf '%s 2 15 3 7 4321\n' "$r1" 213 printf '%s 2 1 0 0 0\n' "$wd" 214 printf 'zUnlisted1111111111111111111 2 9 9 9 9\n' 215 printf '%s 1 4 0 3 0\n' "$r2" 216 printf 'zP