interplane.Get Omega
Read in your language

interplane-forge

INTERPLANE Forge

Brought by drakestapleton

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.
4set -u
5cd "$(dirname "$0")/../.."
6ROOT=$(pwd)
7CORES=${FORGED_CPUS:-12-14}
8PORT=${FORGE_TEST_PORT:-18471}
9OMC=$HOME/work/flux/omega-mv/seed/out/omc
10PY=/usr/bin/python3
11T=$(mktemp -d)
12pid=
13pass=0
14fail=0
15ok() { pass=$((pass+1)); echo "PASS $*"; }
16bad() { fail=$((fail+1)); echo "FAIL $*"; }
17check() { if [ "$1" = "$2" ]; then ok "$3 ($1)"; else bad "$3: want '$2', got '$1'"; fi; }
18cleanup() { [ -n "$pid" ] && kill "$pid" 2>/dev/null; wait 2>/dev/null; [ -n "${KEEP:-}" ] || rm -rf "$T"; }
19trap cleanup EXIT
20mkdir -p "$T/bin" "$T/ng" "$T/data/logs"
21cp growth/tests/fake/rad server/tests/fake/getent "$T/bin/"
22chmod 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"
32taskset -c "$CORES" nice -n 10 "$OMC" < "$T/all.om" > "$T/forged" 2>"$T/omc.err" || { echo "BUILD FAILED $(cat "$T/omc.err")"; exit 1; }
33chmod 755 "$T/forged"
34NOW=$(date +%s)
35IN=$((NOW - 1000))
36OLD=$((NOW - 30000000))
37RID=$(awk -F'|' '/^\| repo \| RID \| default branch/ {t=1; next} t && /cuda-crack/ {gsub(/ /,"",$3); print substr($3,5); exit}' "$HOME/handoffs/radicle/RIDS.md")
38OTHER=$(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")
39ONAME=${OTHER%% *}
40ORID=${OTHER#* }
41NSID=z6MkfZDue1TbaNFi3ZzcD9uiTeduPLC52ucdFVuLKZwexxhK
42Q='/info/refs?service=git-upload-pack'
43cat > "$T/ng/dl.log" <<EOF
44${IN}.100 203.0.113.5 200 "/rad/$RID.git$Q" "git/2.43.0"
45${IN}.200 203.0.113.6 200 "/rad/$RID.git/$NSID$Q" "git/2.43.0"
46${IN}.300 203.0.113.7 200 "/code/git/cuda-crack.git$Q" "git/2.43.0"
47${IN}.400 127.0.0.1 200 "/rad/$RID.git$Q" "git/2.43.0"
48${IN}.500 203.0.113.8 200 "/rad/$RID.git$Q" "SofyaBot/1.0"
49${IN}.600 192.168.1.9 200 "/rad/$RID.git$Q" "git/2.43.0"
50${IN}.700 198.51.100.7 200 "/rad/$RID.git$Q" "git/2.43.0"
51${OLD}.100 203.0.113.9 200 "/rad/$ORID.git$Q" "git/2.43.0"
52${OLD}.200 203.0.113.10 200 "/rad/$ORID.git$Q" "git/2.43.0"
53${OLD}.300 203.0.113.11 200 "/rad/$ORID.git$Q" "git/2.43.0"
54${OLD}.400 203.0.113.12 200 "/rad/$ORID.git$Q" "git/2.43.0"
55${OLD}.500 203.0.113.13 200 "/rad/$ORID.git$Q" "git/2.43.0"
56${IN}.800 203.0.113.14 404 "/rad/$RID.git$Q" "git/2.43.0"
57EOF
58cat > "$T/ng/access.log" <<EOF
59127.0.0.1 - - [08/Nov/2026:05:57:35 -0600] "POST /rad/$RID.git/git-upload-pack HTTP/2.0" 200 10 "-" "git/2.43.0"
60127.0.0.1 - - [08/Nov/2026:05:57:36 -0600] "POST /rad/$RID.git/git-upload-pack HTTP/2.0" 404 10 "-" "git/2.43.0"
61127.0.0.1 - - [08/Nov/2026:05:57:37 -0600] "GET /rad/$RID.git$Q HTTP/2.0" 200 10 "-" "git/2.43.0"
62EOF
63A=/drakestapleton/cuda-crack
64cat > "$T/data/logs/forged.log" <<EOF
65${IN} 203.0.113.5 1 $A/archive/refs/heads/main.zip 200 1000 5
66${IN} 127.0.0.1 1 $A/archive/refs/heads/main.zip 200 1000 5
67${IN} 203.0.113.5 1 $A/releases/download/v1/a.zip 200 1000 5
68${IN} 203.0.113.5 3 $A/archive/refs/heads/main.zip 200 1 1
69${OLD} 203.0.113.9 1 /drakestapleton/$ONAME/archive/refs/heads/main.zip 200 1000 5
70EOF
71$PY - "$T/data/social.log" "$IN" "$OLD" "$RID" "$ORID" <<'PY'
72import hashlib, sys
73path, inn, old, rid, orid = sys.argv[1:]
74inn, old = int(inn), int(old)
75d2 = "z6MkmMcXpKKc9GvEsoJnxJVrUJXmQ6mjfFk4MvTZoNuvGyqB"
76d1 = "z6MkfZDue1TbaNFi3ZzcD9uiTeduPLC52ucdFVuLKZwexxhK"
77d3 = "z6Mk" + ("a" * 44)
78assert all(40 <= len(d) <= 60 for d in (d1, d2, d3))
79prev = "0" * 64
80specs = [
81 (1, old, d2, "star", "rad:" + rid),
82 (2, inn, d1, "star", "rad:" + rid),
83 (3, inn, d3, "star", "rad:" + rid),
84 (4, inn, d3, "unstar", "rad:" + rid),
85 (5, old, d1, "star", "rad:" + orid),
86]
87lines = []
88for seq, ts, did, action, target in specs:
89 line = '{"seq":%d,"ts":%d,"did":"did:key:%s","action":"%s","target":"%s","prev":"%s"}' % (
90 seq, ts, did, action, target, prev)
91 lines.append(line)
92 prev = hashlib.sha256(line.encode()).hexdigest()
93open(path, "w").write("\n".join(lines) + "\n")
94open(path[:-4] + ".head", "w").write("%d %s\n" % (len(lines), prev))
95PY
96taskset -c "$CORES" nice -n 10 "$T/forged" 2>"$T/err" & pid=$!
97for i in $(seq 100); do curl -s -o /dev/null "http://127.0.0.1:$PORT/explore" && break; sleep 0.1; done
98get() { 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" "$@"; }
99jv() { jq -r "$1" "$T/b"; }
100c=$(get / "http://127.0.0.1:$PORT/trending.json")
101check "$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"
103check "$(jv .schema)" "forge/explore-order/1" "trending schema"
104check "$(jv .order)" "trending" "trending order name"
105check "$(jv .window_seconds)" "604800" "default window is 7 days"
106check "$(jv '.repos[0].name')" "cuda-crack" "trending puts the in-window repo first"
107check "$(jv '.repos[0].score')" "6" "cuda-crack score is 3 fetches + 2 downloads + 1 window star"
108check "$(jv '.repos[0].clones')" "3" "cuda-crack window clones"
109check "$(jv '.repos[0].downloads')" "2" "cuda-crack window downloads"
110check "$(jv '.repos[0].stars')" "1" "in-window net stars are 1"
111check "$(jv '.repos[0].path')" "/drakestapleton/cuda-crack" "trending repo has the documented path key"
112Z=$(jq -r --arg n "$ONAME" '.repos[] | select(.name==$n) | .score' "$T/b")
113check "$Z" "0" "out-of-window activity scores 0"
114S0=$(jq -r '.repos[] | select(.name=="cuda-crack") | .seeds' "$T/b")
115check "$S0" "null" "NEG trending runs no routing read (seeds not measured before a repo check)"
116c=$(get / "http://127.0.0.1:$PORT/explore.json?order=new")
117check "$c" 200 "GET /explore.json?order=new"
118check "$(jv .order)" "new" "new order name"
119cp "$T/b" "$T/new.json"
120c=$(get / "http://127.0.0.1:$PORT/explore.json?order=nope")
121check "$c" 400 "NEG unknown order is 400"
122c=$(get / -X POST "http://127.0.0.1:$PORT/trending")
123check "$c" 405 "NEG POST /trending is 405"
124c=$(get / "http://127.0.0.1:$PORT/explore.json")
125check "$(jv .schema)" "forge/explore/1" "NEG plain explore.json stays forge/explore/1"
126c=$(get / "http://127.0.0.1:$PORT/drakestapleton/cuda-crack/insights.json")
127check "$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"
129check "$(jv .schema)" "forge/insights/1" "insights schema"
130check "$(jv .clones.count)" "3" "insights lifetime clones"
131check "$(jv .clones.in_window)" "3" "insights window clones"
132check "$(jv .downloads.count)" "2" "insights lifetime downloads"
133check "$(jv .downloads.archives)" "1" "insights archives"
134check "$(jv .downloads.release_assets)" "1" "insights release assets"
135check "$(jv .downloads.in_window)" "2" "insights window downloads"
136check "$(jv .stars.count)" "2" "insights current stars"
137check "$(jv .stars.in_window)" "1" "insights window stars"
138check "$(jv .follows.count)" "0" "insights follows zero"
139check "$(jv .seeds.count)" "3" "insights seeds from the routing table"
140check "$(jv '.seeds.series | length')" "1" "one seed check recorded"
141check "$(jq -r '.seeds.series[0].count' "$T/b")" "3" "recorded seed count is 3"
142cp "$T/b" "$T/ins.json"
143c=$(get /forge/ "http://127.0.0.1:$PORT/drakestapleton/cuda-crack/insights")
144check "$c" 200 "GET insights HTML under /forge/"
145grep -q '<b>0</b>' "$T/b" && ok "HTML shows zero as zero" || bad "HTML does not show zero"
146grep -q 'since ' "$T/b" && ok "HTML shows since" || bad "HTML has no since"
147grep -q 'front-door nginx download log' "$T/b" && ok "HTML names the clone source" || bad "HTML missing clone source"
148grep -q 'social log' "$T/b" && ok "HTML names the social source" || bad "HTML missing social source"
149START=$(jq -r .window_start "$T/ins.json")
150END=$(jq -r .as_of "$T/ins.json")
151ora=$($PY - "$T" "$START" "$END" "$RID" "$ONAME" "$ORID" "$IN" "$OLD" <<'PY'
152import json, sys
153sys.path.insert(0, "growth/tests")
154from oracle import authors, patches, recount, social
155from datetime import datetime, timezone
156T, start_s, end_s, rid, oname, orid, inn, old = sys.argv[1:]
157def ep(s):
158 return int(datetime.strptime(s, "%Y-%m-%dT%H:%M:%SZ").replace(tzinfo=timezone.utc).timestamp())
159page = json.load(open(T + "/ins.json"))
160start, end = ep(start_s), ep(end_s)
161rows = recount(T + "/ng/dl.log", T + "/ng/access.log", T + "/data/logs/forged.log",
162 {"cuda-crack": rid, oname: orid}, start, end)
163cc = rows["cuda-crack"]
164soc = social(T + "/data/social.log", start, end)
165key = "rad:" + rid
166ok = page["clones"]["count"] == cc["fetches"] and page["clones"]["in_window"] == cc["win_fetches"]
167ok = ok and page["downloads"]["count"] == cc["archives"] + cc["releases"]
168ok = ok and page["downloads"]["in_window"] == cc["win_dl"]
169ok = ok and page["downloads"]["archives"] == cc["archives"]
170ok = ok and page["downloads"]["release_assets"] == cc["releases"]
171ok = ok and rows[oname]["win_fetches"] == 0 and rows[oname]["fetches"] == 5
172ok = ok and page["stars"]["count"] == soc["stars"].get(key, 0)
173ok = ok and page["stars"]["in_window"] == soc["window"].get(key, 0)
174ok = ok and page["follows"]["count"] == 0
175ok = ok and ep(page["clones"]["since"]) == int(inn)
176ok = ok and ep(page["stars"]["since"]) == int(old)
177ok = ok and soc["first"] == int(old)
178names = authors(sys.argv[0] and __import__("os").path.expanduser("~/.radicle/storage/" + rid))
179ok = ok and page["contributors"]["names"] == names
180ok = ok and page["contributors"]["count"] == len(names)
181pat = patches(__import__("os").path.expanduser("~/.radicle/storage/" + rid))
182ok = ok and page["patches"]["opened"] == pat["opened"]
183ok = ok and page["patches"]["merged"] == pat["merged"]
184print("yes" if ok else "no")
185if 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)
187PY
188)
189check "$ora" "yes" "oracle recount of the same logs matches the insights page"
190sleep 2
191echo x >> "$T/ng/wal"
192c=$(get / "http://127.0.0.1:$PORT/drakestapleton/cuda-crack/insights.json")
193check "$(jv .seeds.count)" "3" "second check still 3 seeds"
194check "$(jv '.seeds.series | length')" "1" "NEG an unchanged seed count adds no series point"
195sleep 2
196touch "$T/bin/seedzero"
197echo y >> "$T/ng/wal"
198c=$(get / "http://127.0.0.1:$PORT/drakestapleton/cuda-crack/insights.json")
199check "$(jv .seeds.count)" "0" "zero seeding nodes shown as 0"
200check "$(jv '.seeds.series | length')" "2" "a changed seed count adds a series point"
201check "$(jv '.seeds.series[1].count')" "0" "the new series point is 0"
202touch "$T/bin/radfail"
203rm -f "$T/bin/seedzero"
204sleep 2
205echo z >> "$T/ng/wal"
206c=$(get / "http://127.0.0.1:$PORT/drakestapleton/cuda-crack/insights.json")
207check "$(jv .seeds.count)" "null" "rad failure is not measured, not zero"
208git --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"
209CT=$(cat "$T/ct")
210PT=$(jq -r '.repos[] | select(.name=="cuda-crack") | .last_commit' "$T/new.json")
211PT=${PT%Z}
212PT=$(printf '%s' "$PT" | tr T ' ')
213PE=$(date -u -d "$PT" +%s)
214check "$PE" "$CT" "new-order commit time matches git"
215c=$(get / "http://127.0.0.1:$PORT/trending.json?window=1")
216check "$c" 200 "GET trending.json?window=1"
217W=$(jq -r '.repos[] | select(.name=="cuda-crack") | .score' "$T/b")
218check "$W" "0" "NEG window=1 drops events older than one second"
219c=$(get / "http://127.0.0.1:$PORT/trending.json")
220S=$(jq -r --arg n "$ONAME" '.repos[] | select(.name==$n) | .stars' "$T/b")
221check "$S" "0" "NEG an old star stays out of the other repo's window score"
222c=$(get /forge/ "http://127.0.0.1:$PORT/trending.json")
223check "$c" 200 "GET trending.json under /forge/"
224check "$(jv .schema)" "forge/explore-order/1" "trending schema under /forge/"
225check "$(jq -r '.repos[] | select(.name=="cuda-crack") | .path' "$T/b")" "/forge/drakestapleton/cuda-crack" "trending path under /forge/ carries the base"
226check "$(jq -r .clones.source "$T/ins.json")" "front-door nginx download log" "clone source"
227check "$(jq -r .downloads.source "$T/ins.json")" "forged access log" "download source"
228check "$(jq -r .stars.source "$T/ins.json")" "social log" "star source"
229check "$(jq -r .seeds.source "$T/ins.json")" "this node's routing table" "seed source"
230check "$(jq -r .contributors.source "$T/ins.json")" "git log author names on the default branch" "contributor source"
231check "$(jq -r .patches.source "$T/ins.json")" "patch objects in this repository's storage" "patch source"
232c=$(get / "http://127.0.0.1:$PORT/drakestapleton/omega-mv/insights.json")
233check "$c" 200 "GET omega-mv insights.json"
234cp "$T/b" "$T/mv.json"
235ora2=$($PY - "$T/mv.json" <<'PY'
236import json, os, sys
237sys.path.insert(0, "growth/tests")
238from oracle import patches
239page = json.load(open(sys.argv[1]))
240pat = patches(os.path.expanduser("~/.radicle/storage/z6do9WDBhuSnvopDkgFdFr1yWA62"))
241ok = page["patches"]["opened"] == pat["opened"] and page["patches"]["merged"] == pat["merged"]
242print("yes" if ok else "no")
243if not ok:
244 print(json.dumps({"page": page["patches"], "oracle": pat}), file=sys.stderr)
245PY
246)
247check "$ora2" "yes" "oracle patch recount matches omega-mv insights"
248c=$(get / "http://127.0.0.1:$PORT/login/x/insights")
249check "$c" 404 "NEG a reserved owner path ending in /insights is 404"
250c=$(get / "http://127.0.0.1:$PORT/assets/x/insights.json")
251check "$c" 404 "NEG a reserved owner path ending in /insights.json is 404"
252kill -0 "$pid" 2>/dev/null && ok "forged still running after reserved /insights paths" || bad "forged died on a reserved /insights path"
253printf 'e g %s %s\ne g %s %s\n' "$NOW" "$RID" "$NOW" "$RID" >> "$T/data/counts.log"
254c=$(get / "http://127.0.0.1:$PORT/drakestapleton/cuda-crack/insights.json")
255check "$(jv .clones.in_window)" "3" "NEG a torn journal batch (no cursor line) is not counted in the window"
256c=$(get / "http://127.0.0.1:$PORT/trending.json?window=0"); check "$c" 400 "NEG window=0 is 400"
257c=$(get / "http://127.0.0.1:$PORT/trending.json?window=315360001"); check "$c" 400 "NEG window one past 3650 days is 400"
258c=$(get / "http://127.0.0.1:$PORT/trending.json?window=1x"); check "$c" 400 "NEG window=1x is 400"
259c=$(get / "http://127.0.0.1:$PORT/trending.json?window=1234567890"); check "$c" 400 "NEG a 10-digit window is 400"
260c=$(get / "http://127.0.0.1:$PORT/drakestapleton/cuda-crack/insights.json?window=0"); check "$c" 400 "NEG insights window=0 is 400"
261c=$(get / "http://127.0.0.1:$PORT/trending.json?window=315360000"); check "$c" 200 "window=315360000 (3650 days) is 200"
262check "$(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.
264kill "$pid"; wait "$pid" 2>/dev/null
265mv "$T/ng/dl.log" "$T/ng/dl.log.away"
266mv "$T/data/counts.log" "$T/data/counts.log.away"
267taskset -c "$CORES" nice -n 10 "$T/forged" 2>>"$T/err" & pid=$!
268for i in $(seq 100); do curl -s -o /dev/null "http://127.0.0.1:$PORT/explore" && break; sleep 0.1; done
269c=$(get / "http://127.0.0.1:$PORT/trending.json")
270check "$(jv '.repos[] | select(.name=="cuda-crack") | .clones')" "null" "NEG an unread download log is null in trending, not 0"
271check "$(jv '.repos[] | select(.name=="cuda-crack") | .score')" "3" "an unmeasured part is left out of the score (2 downloads + 1 star)"
272c=$(get / "http://127.0.0.1:$PORT/drakestapleton/cuda-crack/insights.json")
273check "$(jv .clones.in_window)" "null" "NEG an unread download log is null in the insights window"
274check "$(jv .downloads.in_window)" "2" "the forged access log is still read after the restart"
275echo "growth: $pass passed, $fail failed"
276[ "$fail" = 0 ]