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/growth/tests/check.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 / growth / tests / check.sh` 276 lines ยท 16135 bytes Raw Blame History 1 #!/bin/sh 2 # ORACLE 3 # growth/tests/check.sh: trending order, zero, insights, JSON. Independent recount is oracle.py. 4 set -u 5 cd "$(dirname "$0")/../.." 6 ROOT=$(pwd) 7 CORES=${FORGED_CPUS:-12-14} 8 PORT=${FORGE_TEST_PORT:-18471} 9 OMC=$HOME/work/flux/omega-mv/seed/out/omc 10 PY=/usr/bin/python3 11 T=$(mktemp -d) 12 pid= 13 pass=0 14 fail=0 15 ok() { pass=$((pass+1)); echo "PASS $*"; } 16 bad() { fail=$((fail+1)); echo "FAIL $*"; } 17 check() { if [ "$1" = "$2" ]; then ok "$3 ($1)"; else bad "$3: want '$2', got '$1'"; fi; } 18 cleanup() { [ -n "$pid" ] && kill "$pid" 2>/dev/null; wait 2>/dev/null; [ -n "${KEEP:-}" ] || rm -rf "$T"; } 19 trap cleanup EXIT 20 mkdir -p "$T/bin" "$T/ng" "$T/data/logs" 21 cp growth/tests/fake/rad server/tests/fake/getent "$T/bin/" 22 chmod 755 "$T/bin/rad" "$T/bin/getent" 23 : > "$T/ng/wal" 24 { printf 'om2\n'; cat $(./run.sh units); } | sed \ 25 -e "s|^text tfdata \".*\"|text tfdata \"$T/data/\"|" \ 26 -e "s|^text tfzp0 \".*\"|text tfzp0 \"$T/ng/dl.log\"|" \ 27 -e "s|^text tfzp1 \".*\"|text tfzp1 \"$T/ng/access.log\"|" \ 28 -e "s|^text tfzwal \".*\"|text tfzwal \"$T/ng/wal\"|" \ 29 -e "s|^text tfzrad \".*\"|text tfzrad \"$T/bin/rad\"|" \ 30 -e "s|^text tfzgent \".*\"|text tfzgent \"$T/bin/getent\"|" \ 31 -e "s/18480/$PORT/g" > "$T/all.om" 32 taskset -c "$CORES" nice -n 10 "$OMC" < "$T/all.om" > "$T/forged" 2>"$T/omc.err" || { echo "BUILD FAILED $(cat "$T/omc.err")"; exit 1; } 33 chmod 755 "$T/forged" 34 NOW=$(date +%s) 35 IN=$((NOW - 1000)) 36 OLD=$((NOW - `30000000`)) 37 RID=$(awk -F'|' '/^\| repo \| RID \| default branch/ {t=1; next} t && /cuda-crack/ {gsub(/ /,"",$3); print substr($3,5); exit}' "$HOME/handoffs/radicle/RIDS.md") 38 OTHER=$(awk -F'|' '/^\| repo \| RID \| default branch/ {t=1; next} t && /^\| [A-Za-z0-9._-]+ \| rad:z/ && $2 !~ /cuda-crack/ {gsub(/ /,"",$2); gsub(/ /,"",$3); print $2, substr($3,5); exit}' "$HOME/handoffs/radicle/RIDS.md") 39 ONAME=${OTHER%% *} 40 ORID=${OTHER#* } 41 NSID=`z6MkfZDue1TbaNFi3ZzcD9uiTeduPLC52ucdFVuLKZwexxhK` 42 Q='/info/refs?service=git-upload-pack' 43 cat > "$T/ng/dl.log" < "$T/ng/access.log" < "$T/data/logs/forged.log" <"$T/err" & pid=$! 97 for i in $(seq 100); do curl -s -o /dev/null "http://127.0.0.1:$PORT/explore" && break; sleep 0.1; done 98 get() { b=$1; shift; curl -s -o "$T/b" -D "$T/h" -w '%{http_code}' -H "X-Forge-Base: $b" -H "X-Real-IP: 203.0.113.50" "$@"; } 99 jv() { jq -r "$1" "$T/b"; } 100 c=$(get / "http://127.0.0.1:$PORT/trending.json") 101 check "$c" 200 "GET /trending.json" 102 $PY -m json.tool "$T/b" >/dev/null && ok "trending.json is valid JSON" || bad "trending.json is not valid JSON" 103 check "$(jv .schema)" "forge/explore-order/1" "trending schema" 104 check "$(jv .order)" "trending" "trending order name" 105 check "$(jv .window_seconds)" "604800" "default window is 7 days" 106 check "$(jv '.repos[0].name')" "cuda-crack" "trending puts the in-window repo first" 107 check "$(jv '.repos[0].score')" "6" "cuda-crack score is 3 fetches + 2 downloads + 1 window star" 108 check "$(jv '.repos[0].clones')" "3" "cuda-crack window clones" 109 check "$(jv '.repos[0].downloads')" "2" "cuda-crack window downloads" 110 check "$(jv '.repos[0].stars')" "1" "in-window net stars are 1" 111 check "$(jv '.repos[0].path')" "/drakestapleton/cuda-crack" "trending repo has the documented path key" 112 Z=$(jq -r --arg n "$ONAME" '.repos[] | select(.name==$n) | .score' "$T/b") 113 check "$Z" "0" "out-of-window activity scores 0" 114 S0=$(jq -r '.repos[] | select(.name=="cuda-crack") | .seeds' "$T/b") 115 check "$S0" "null" "NEG trending runs no routing read (seeds not measured before a repo check)" 116 c=$(get / "http://127.0.0.1:$PORT/explore.json?order=new") 117 check "$c" 200 "GET /explore.json?order=new" 118 check "$(jv .order)" "new" "new order name" 119 cp "$T/b" "$T/new.json" 120 c=$(get / "http://127.0.0.1:$PORT/explore.json?order=nope") 121 check "$c" 400 "NEG unknown order is 400" 122 c=$(get / -X POST "http://127.0.0.1:$PORT/trending") 123 check "$c" 405 "NEG POST /trending is 405" 124 c=$(get / "http://127.0.0.1:$PORT/explore.json") 125 check "$(jv .schema)" "forge/explore/1" "NEG plain explore.json stays forge/explore/1" 126 c=$(get / "http://127.0.0.1:$PORT/drakestapleton/cuda-crack/insights.json") 127 check "$c" 200 "GET insights.json" 128 $PY -m json.tool "$T/b" >/dev/null && ok "insights.json is valid JSON" || bad "insights.json is not valid JSON" 129 check "$(jv .schema)" "forge/insights/1" "insights schema" 130 check "$(jv .clones.count)" "3" "insights lifetime clones" 131 check "$(jv .clones.in_window)" "3" "insights window clones" 132 check "$(jv .downloads.count)" "2" "insights lifetime downloads" 133 check "$(jv .downloads.archives)" "1" "insights archives" 134 check "$(jv .downloads.release_assets)" "1" "insights release assets" 135 check "$(jv .downloads.in_window)" "2" "insights window downloads" 136 check "$(jv .stars.count)" "2" "insights current stars" 137 check "$(jv .stars.in_window)" "1" "insights window stars" 138 check "$(jv .follows.count)" "0" "insights follows zero" 139 check "$(jv .seeds.count)" "3" "insights seeds from the routing table" 140 check "$(jv '.seeds.series | length')" "1" "one seed check recorded" 141 check "$(jq -r '.seeds.series[0].count' "$T/b")" "3" "recorded seed count is 3" 142 cp "$T/b" "$T/ins.json" 143 c=$(get /forge/ "http://127.0.0.1:$PORT/drakestapleton/cuda-crack/insights") 144 check "$c" 200 "GET insights HTML under /forge/" 145 grep -q '0' "$T/b" && ok "HTML shows zero as zero" || bad "HTML does not show zero" 146 grep -q 'since ' "$T/b" && ok "HTML shows since" || bad "HTML has no since" 147 grep -q 'front-door nginx download log' "$T/b" && ok "HTML names the clone source" || bad "HTML missing clone source" 148 grep -q 'social log' "$T/b" && ok "HTML names the social source" || bad "HTML missing social source" 149 START=$(jq -r .window_start "$T/ins.json") 150 END=$(jq -r .as_of "$T/ins.json") 151 ora=$($PY - "$T" "$START" "$END" "$RID" "$ONAME" "$ORID" "$IN" "$OLD" <<'PY' 152 import json, sys 153 sys.path.insert(0, "growth/tests") 154 from oracle import authors, patches, recount, social 155 from datetime import datetime, timezone 156 T, start_s, end_s, rid, oname, orid, inn, old = sys.argv[1:] 157 def ep(s): 158 return int(datetime.strptime(s, "%Y-%m-%dT%H:%M:%SZ").replace(tzinfo=timezone.utc).timestamp()) 159 page = json.load(open(T + "/ins.json")) 160 start, end = ep(start_s), ep(end_s) 161 rows = recount(T + "/ng/dl.log", T + "/ng/access.log", T + "/data/logs/forged.log", 162 {"cuda-crack": rid, oname: orid}, start, end) 163 cc = rows["cuda-crack"] 164 soc = social(T + "/data/social.log", start, end) 165 key = "rad:" + rid 166 ok = page["clones"]["count"] == cc["fetches"] and page["clones"]["in_window"] == cc["win_fetches"] 167 ok = ok and page["downloads"]["count"] == cc["archives"] + cc["releases"] 168 ok = ok and page["downloads"]["in_window"] == cc["win_dl"] 169 ok = ok and page["downloads"]["archives"] == cc["archives"] 170 ok = ok and page["downloads"]["release_assets"] == cc["releases"] 171 ok = ok and rows[oname]["win_fetches"] == 0 and rows[oname]["fetches"] == 5 172 ok = ok and page["stars"]["count"] == soc["stars"].get(key, 0) 173 ok = ok and page["stars"]["in_window"] == soc["window"].get(key, 0) 174 ok = ok and page["follows"]["count"] == 0 175 ok = ok and ep(page["clones"]["since"]) == int(inn) 176 ok = ok and ep(page["stars"]["since"]) == int(old) 177 ok = ok and soc["first"] == int(old) 178 names = authors(sys.argv[0] and __import__("os").path.expanduser("~/.radicle/storage/" + rid)) 179 ok = ok and page["contributors"]["names"] == names 180 ok = ok and page["contributors"]["count"] == len(names) 181 pat = patches(__import__("os").path.expanduser("~/.radicle/storage/" + rid)) 182 ok = ok and page["patches"]["opened"] == pat["opened"] 183 ok = ok and page["patches"]["merged"] == pat["merged"] 184 print("yes" if ok else "no") 185 if not ok: 186 print(json.dumps({"stars": page["stars"], "soc": {"stars": soc["stars"], "window": soc["window"], "first": soc["first"]}, "names": names, "page_names": page["contributors"]["names"], "pat": pat, "page_pat": page["patches"], "clones_since": page["clones"]["since"]}, default=list), file=sys.stderr) 187 PY 188 ) 189 check "$ora" "yes" "oracle recount of the same logs matches the insights page" 190 sleep 2 191 echo x >> "$T/ng/wal" 192 c=$(get / "http://127.0.0.1:$PORT/drakestapleton/cuda-crack/insights.json") 193 check "$(jv .seeds.count)" "3" "second check still 3 seeds" 194 check "$(jv '.seeds.series | length')" "1" "NEG an unchanged seed count adds no series point" 195 sleep 2 196 touch "$T/bin/seedzero" 197 echo y >> "$T/ng/wal" 198 c=$(get / "http://127.0.0.1:$PORT/drakestapleton/cuda-crack/insights.json") 199 check "$(jv .seeds.count)" "0" "zero seeding nodes shown as 0" 200 check "$(jv '.seeds.series | length')" "2" "a changed seed count adds a series point" 201 check "$(jv '.seeds.series[1].count')" "0" "the new series point is 0" 202 touch "$T/bin/radfail" 203 rm -f "$T/bin/seedzero" 204 sleep 2 205 echo z >> "$T/ng/wal" 206 c=$(get / "http://127.0.0.1:$PORT/drakestapleton/cuda-crack/insights.json") 207 check "$(jv .seeds.count)" "null" "rad failure is not measured, not zero" 208 git --git-dir="$HOME/.radicle/storage/$RID" log -1 --format=%ct refs/heads/main >"$T/ct" 2>/dev/null || git --git-dir="$HOME/.radicle/storage/$RID" log -1 --format=%ct "refs/namespaces/$NSID/refs/heads/main" >"$T/ct" 209 CT=$(cat "$T/ct") 210 PT=$(jq -r '.repos[] | select(.name=="cuda-crack") | .last_commit' "$T/new.json") 211 PT=${PT%Z} 212 PT=$(printf '%s' "$PT" | tr T ' ') 213 PE=$(date -u -d "$PT" +%s) 214 check "$PE" "$CT" "new-order commit time matches git" 215 c=$(get / "http://127.0.0.1:$PORT/trending.json?window=1") 216 check "$c" 200 "GET trending.json?window=1" 217 W=$(jq -r '.repos[] | select(.name=="cuda-crack") | .score' "$T/b") 218 check "$W" "0" "NEG window=1 drops events older than one second" 219 c=$(get / "http://127.0.0.1:$PORT/trending.json") 220 S=$(jq -r --arg n "$ONAME" '.repos[] | select(.name==$n) | .stars' "$T/b") 221 check "$S" "0" "NEG an old star stays out of the other repo's window score" 222 c=$(get /forge/ "http://127.0.0.1:$PORT/trending.json") 223 check "$c" 200 "GET trending.json under /forge/" 224 check "$(jv .schema)" "forge/explore-order/1" "trending schema under /forge/" 225 check "$(jq -r '.repos[] | select(.name=="cuda-crack") | .path' "$T/b")" "/forge/drakestapleton/cuda-crack" "trending path under /forge/ carries the base" 226 check "$(jq -r .clones.source "$T/ins.json")" "front-door nginx download log" "clone source" 227 check "$(jq -r .downloads.source "$T/ins.json")" "forged access log" "download source" 228 check "$(jq -r .stars.source "$T/ins.json")" "social log" "star source" 229 check "$(jq -r .seeds.source "$T/ins.json")" "this node's routing table" "seed source" 230 check "$(jq -r .contributors.source "$T/ins.json")" "git log author names on the default branch" "contributor source" 231 check "$(jq -r .patches.source "$T/ins.json")" "patch objects in this repository's storage" "patch source" 232 c=$(get / "http://127.0.0.1:$PORT/drakestapleton/omega-mv/insights.json") 233 check "$c" 200 "GET omega-mv insights.json" 234 cp "$T/b" "$T/mv.json" 235 ora2=$($PY - "$T/mv.json" <<'PY' 236 import json, os, sys 237 sys.path.insert(0, "growth/tests") 238 from oracle import patches 239 page = json.load(open(sys.argv[1])) 240 pat = patches(os.path.expanduser("~/.radicle/storage/z6do9WDBhuSnvopDkgFdFr1yWA62")) 241 ok = page["patches"]["opened"] == pat["opened"] and page["patches"]["merged"] == pat["merged"] 242 print("yes" if ok else "no") 243 if not ok: 244 print(json.dumps({"page": page["patches"], "oracle": pat}), file=sys.stderr) 245 PY 246 ) 247 check "$ora2" "yes" "oracle patch recount matches omega-mv insights" 248 c=$(get / "http://127.0.0.1:$PORT/login/x/insights") 249 check "$c" 404 "NEG a reserved owner path ending in /insights is 404" 250 c=$(get / "http://127.0.0.1:$PORT/assets/x/insights.json") 251 check "$c" 404 "NEG a reserved owner path ending in /insights.json is 404" 252 kill -0 "$pid" 2>/dev/null && ok "forged still running after reserved /insights paths" || bad "forged died on a reserved /insights path" 253 printf 'e g %s %s\ne g %s %s\n' "$NOW" "$RID" "$NOW" "$RID" >> "$T/data/counts.log" 254 c=$(get / "http://127.0.0.1:$PORT/drakestapleton/cuda-crack/insights.json") 255 check "$(jv .clones.in_window)" "3" "NEG a torn journal batch (no cursor line) is not counted in the window" 256 c=$(get / "http://127.0.0.1:$PORT/trending.json?window=0"); check "$c" 400 "NEG window=0 is 400" 257 c=$(get / "http://127.0.0.1:$PORT/trending.json?window=`315360001`"); check "$c" 400 "NEG window one past 3650 days is 400" 258 c=$(get / "http://127.0.0.1:$PORT/trending.json?window=1x"); check "$c" 400 "NEG window=1x is 400" 259 c=$(get / "http://127.0.0.1:$PORT/trending.json?window=`1234567890`"); check "$c" 400 "NEG a 10-digit window is 400" 260 c=$(get / "http://127.0.0.1:$PORT/drakestapleton/cuda-crack/insights.json?window=0"); check "$c" 400 "NEG insights window=0 is 400" 261 c=$(get / "http://127.0.0.1:$PORT/trending.json?window=`315360000`"); check "$c" 200 "window=`315360000` (3650 days) is 200" 262 check "$(jv .window_seconds)" "`315360000`" "the maximum window is echoed" 263 # An unread source is null, not 0: restart with the nginx download log absent and a fresh counts journal. 264 kill "$pid"; wait "$pid" 2>/dev/null 265 mv "$T/ng/dl.log" "$T/ng/dl.log.away" 266 mv "$T/data/counts.log" "$T/data/counts.log.away" 267 taskset -c "$CORES" nice -n 10 "$T/forged" 2>>"$T/err" & pid=$! 268 for i in $(seq 100); do curl -s -o /dev/null "http://127.0.0.1:$PORT/explore" && break; sleep 0.1; done 269 c=$(get / "http://127.0.0.1:$PORT/trending.json") 270 check "$(jv '.repos[] | select(.name=="cuda-crack") | .clones')" "null" "NEG an unread download log is null in trending, not 0" 271 check "$(jv '.repos[] | select(.name=="cuda-crack") | .score')" "3" "an unmeasured part is left out of the score (2 downloads + 1 star)" 272 c=$(get / "http://127.0.0.1:$PORT/drakestapleton/cuda-crack/insights.json") 273 check "$(jv .clones.in_window)" "null" "NEG an unread download log is null in the insights window" 274 check "$(jv .downloads.in_window)" "2" "the forged access log is still read after the restart" 275 echo "growth: $pass passed, $fail failed" 276 [ "$fail" = 0 ]