interplane.Get Omega
Read in your language

interplane-forge

INTERPLANE Forge

Brought by drakestapleton

branch main Branches Tags History

interplane-forge / server / tests / bigrepo.sh

193 lines · 12312 bytes Raw Blame History
1#!/bin/bash
2# ORACLE: host test driver (bash + curl + git + python3), not product code.
3# server/tests/bigrepo.sh: git objects of unusual size in served storage must not end forged.
4# Found by the loop bound sweep of all directories (hand-over 4, evidence r4/BOUND-SWEEP.md). In
5# seeded Omega a loop that runs past its `bound` is trap 4 (exit 104), a `for` with a count that is
6# not a literal and no `bound` has a guard of 1,000,000 passes (the same trap), and a write past the
7# end of an array is trap 3 (exit 103). Each case below ended the server before the fix:
8# longref a branch name of 600 bytes: brbest (browse/a_core.om) copied it into gbref (512 bytes)
9# octopus a commit with 70 parents: brcmtids (browse/c2_hist.om) and brzpar (browse/e2_json.om)
10# walked the parents under bound 64
11# assets a tag whose release-assets/ listing is over 1,000,000 bytes: dllsa (dl/dl.om) walked it
12# in a `for` without a bound
13# tags a tag list over 1,000,000 bytes: dltags and dlsplit (dl/dl.om) copied and walked it in a
14# `for` without a bound. The list holds no message text since 735a01c (dlmsg reads one
15# tag's on its own), so 8,000 tags of 110-byte names make it long; the annotated tag with a
16# body of 1,039,900 bytes stays, for dlmsg. Lists past gdtl (16 MiB) are refused whole,
17# which is the subject of server/tests/cutdata.sh
18# longname a file name of 110,000 bytes on the default branch: fjfx (server/json.om, bound 65536),
19# brypath (browse/e1_json.om, bound 4096) and fcolon (server/pages.om, bound 100000)
20# Everything is private to a temp dir; a plain bare repository stands in for Radicle storage. Nothing
21# here shows that a Radicle node would accept such objects from a peer.
22# Negative controls: each old loop line put back by sed must end the server again (103 or 104).
23# Usage: server/tests/bigrepo.sh (CORES default 14; BIGREPO_PORT; KEEP=1 keeps the temp dir;
24# NONEG=1 skips the negative controls)
25set -u
26H=$(cd "$(dirname "$0")" && pwd)
27export PORT=${BIGREPO_PORT:-18503} CORES=${CORES:-14}
28T=$(mktemp -d /tmp/fbigr.XXXXXX); W=$T/w
29PASS=0; FAIL=0; PID=
30ok() { PASS=$((PASS+1)); echo "PASS $*"; }
31bad() { FAIL=$((FAIL+1)); echo "FAIL $*"; }
32check() { if [ "$1" = "$2" ]; then ok "$3 ($1)"; else bad "$3: want $2, got $1"; fi; }
33trap "[ -n \"\$PID\" ] && kill \$PID 2>/dev/null; wait 2>/dev/null; [ -n \"\${KEEP:-}\" ] || rm -rf \"$T\"" EXIT
34if ss -ltn | grep -q "127.0.0.1:$PORT "; then echo "NOT_RUN: port $PORT busy"; exit 3; fi
35# STORE_VARIANT=1 (with IPL_DIR): the same gates on the store-reading build. Every start makes the
36# store afresh from the fixture storage (store/tests/fixstore.sh: the repository as it is then, its
37# head recorded), so what the gate wrote into the storage is what the store holds. The id is longer
38# there (the store's old-id rule wants 20..60 letters).
39RID=zBigRepoFixture1
40[ "${STORE_VARIANT:-0}" = 1 ] && RID=zBigRepoFixtureStore1
41S=$T/storage/$RID
42G() { git -C "$S" -c user.name=fixture -c user.email=fixture@t.invalid "$@"; }
43mkdir -p "$T/storage" "$T/data" "$T/social"
44git init -q -b main "$W" && echo hi > "$W/a.txt" && git -C "$W" add a.txt \
45 && git -C "$W" -c user.name=t -c user.email=t@t.invalid commit -qm init \
46 && git clone -q --bare "$W" "$S" || { echo "fixture repo failed"; exit 1; }
47printf "# test allow-list\n\n| repo | RID | default branch |\n|---|---|---|\n| bigrepo | rad:%s | main |\n" "$RID" > "$T/rids.md"
48BASE=$(G rev-parse refs/heads/main); BTREE=$(G rev-parse "$BASE^{tree}"); ABLOB=$(G rev-parse "$BASE:a.txt")
49U=http://127.0.0.1:$PORT/drakestapleton/bigrepo
50. "$H/../../store/tests/svlib.sh"
51start() { # start OUT [SEDX]: build and start a test forged; PID set
52 if [ "${STORE_VARIANT:-0}" = 1 ]; then
53 rm -f "$T/store.fp"; svsync "$S" "$T/rids.md" "$T/storage" "$T/store" "$PORT" || return 1
54 export FORGE_STORE=$T/store
55 fi
56 DATA=$T/data/ STORE=$T/storage/ RIDS=$T/rids.md SEDX=${2:-} "$H/../../collab/tests/tbuild.sh" "$1" || return 1
57 FORGE_SOCIAL_DIR=$T/social/ taskset -c "$CORES" nice -n 10 "$1" 2>> "$1.log" &
58 PID=$!
59 for _ in $(seq 50); do curl -s -o /dev/null "http://127.0.0.1:$PORT/explore" && return 0; sleep 0.1; done
60 return 1
61}
62stop() { [ -n "$PID" ] && { kill $PID 2> /dev/null; wait $PID 2> /dev/null; }; PID=; sleep 0.3; }
63rcwait() { # RC = the exit code of the server if it ends within 10 s, else "alive" (and it is stopped)
64 for _ in $(seq 50); do kill -0 $PID 2> /dev/null || break; sleep 0.2; done
65 if kill -0 $PID 2> /dev/null; then stop; RC=alive; else wait $PID 2> /dev/null; RC=$?; PID=; fi
66}
67get() { # get FORM URL: prints the status (000 = no answer); body in $T/body
68 svsync "$S" "$T/rids.md" "$T/storage" "$T/store" "$PORT" || { echo "svsync failed" >&2; echo 000; return; }
69 if [ "$1" = json ]; then curl -s -o "$T/body" --max-time 60 -w "%{http_code}" -H "Accept: application/json" "$2"
70 else curl -s -o "$T/body" --max-time 60 -w "%{http_code}" "$2"; fi
71}
72isjson() { python3 -c "import json,sys; json.load(open(sys.argv[1],\"rb\"))" "$T/body" 2> /dev/null && echo valid || echo invalid; }
73alive() {
74 sleep 0.2
75 if kill -0 $PID 2> /dev/null && [ "$(curl -s -o /dev/null --max-time 5 -w "%{http_code}" "http://127.0.0.1:$PORT/explore")" = 200 ]; then ok "$1: server still answers"; return 0; fi
76 for _ in 1 2 3 4 5 6 7 8 9 10; do kill -0 $PID 2> /dev/null || break; sleep 0.2; done
77 if kill -0 $PID 2> /dev/null; then bad "$1: server runs but does not answer"; return 1; fi
78 wait $PID 2> /dev/null; rc=$?; PID=
79 bad "$1: server exited rc=$rc"
80 start "$T/forged" > /dev/null || { echo "server did not start again"; exit 1; }
81 return 1
82}
83page() { # page NAME FORM URL WANT: one request, its status, JSON validity, liveness
84 local c; c=$(get "$2" "$3"); check "$c" "$4" "$1 ($2): status"
85 if [ "$2" = json ] && [ "$c" = 200 ]; then check "$(isjson)" valid "$1 (json): the JSON parses"; fi
86 alive "$1 ($2)"
87}
88# ---- fixtures (planted one group at a time, so each page meets one unusual object)
89LREF=$(python3 -c "print(\"x\"*200+\"/\"+\"y\"*200+\"/\"+\"z\"*198)")
90f_longref() { G update-ref "refs/heads/$LREF" "$BASE"; }
91u_longref() { G update-ref -d "refs/heads/$LREF"; }
92f_octopus() {
93 local ps=() i c
94 for i in $(seq 70); do c=$(G commit-tree "$BTREE" -p "$BASE" -m "side $i" < /dev/null) || return 1; ps+=(-p "$c"); done
95 OCT=$(G commit-tree "$BTREE" "${ps[@]}" -m "merge of 70" < /dev/null) && G update-ref refs/heads/oct "$OCT"
96}
97u_octopus() { G update-ref -d refs/heads/oct; }
98f_assets() {
99 local sub top c
100 sub=$(python3 -c "
101import sys
102for i in range(6000): sys.stdout.write(\"100644 blob $ABLOB\t%s%05d\n\" % (\"n\"*100, i))" | G mktree) || return 1
103 top=$(printf "100644 blob %s\ta.txt\n040000 tree %s\trelease-assets\n" "$ABLOB" "$sub" | G mktree) || return 1
104 c=$(G commit-tree "$top" -p "$BASE" -m "release with 6000 assets" < /dev/null) || return 1
105 G update-ref refs/tags/v1 "$c"
106 ASZ=$(G ls-tree -l -z "$c" -- release-assets/ | wc -c)
107}
108u_assets() { G update-ref -d refs/tags/v1; }
109f_tags() {
110 python3 -c "print(\"big tag\n\n\" + \"x\"*1039900)" > "$T/tagmsg" && G tag -a -F "$T/tagmsg" big "$BASE" || return 1
111 python3 -c "
112for i in range(8000): print(\"create refs/tags/l-%05d-%s $BASE\" % (i, \"t\" * 104))" | G update-ref --stdin && G pack-refs --all
113}
114u_tags() { G tag -d big > /dev/null; G for-each-ref "--format=delete %(refname)" "refs/tags/l-*" | G update-ref --stdin; }
115f_longname() {
116 local nb top c
117 nb=$(printf "needle\n" | G hash-object -w --stdin) || return 1
118 top=$(python3 -c "
119import sys
120sys.stdout.write(\"100644 blob $nb\t%s\n100644 blob $ABLOB\ta.txt\n\" % (\"L\"*110000))" | G mktree) || return 1
121 c=$(G commit-tree "$top" -p "$BASE" -m "a very long file name" < /dev/null) || return 1
122 G update-ref refs/heads/main "$c"
123}
124u_longname() { G update-ref refs/heads/main "$BASE"; }
125start "$T/forged" || { bad "test forged did not start"; exit 1; }
126page "baseline tree" html "$U/tree/main" 200
127f_longref || { bad "fixture longref"; exit 1; }
128check "${#LREF}" 600 "fixture: branch name bytes"
129page "longref tree" html "$U/tree/$LREF" 404
130page "longref tree" json "$U/tree/$LREF" 404
131page "longref branches" html "$U/branches" 200
132u_longref
133f_octopus || { bad "fixture octopus"; exit 1; }
134check "$(G rev-list --parents -n 1 "$OCT" | wc -w)" 71 "fixture: the merge and its 70 parents"
135page "octopus commit" html "$U/commit/$OCT" 200
136page "octopus commit" json "$U/commit/$OCT" 200
137page "octopus log" html "$U/commits/oct" 200
138u_octopus
139f_assets || { bad "fixture assets"; exit 1; }
140[ "$ASZ" -gt 1000000 ] && ok "fixture: release-assets listing is $ASZ bytes" || bad "fixture: release-assets listing is only $ASZ bytes"
141page "assets releases" html "$U/releases" 200
142page "assets releases" json "$U/releases" 200
143# 6,000 assets: the table holds 131,072 since 735a01c, so the page is a whole 200 (f0b5bd0 answered the
144# whole 500 of fincut past 64). The loop over the listing runs to its end, which is what this case is for.
145page "assets release v1" html "$U/releases/tag/v1" 200
146page "assets release v1" json "$U/releases/tag/v1" 200
147u_assets
148f_tags || { bad "fixture tags"; exit 1; }
149TSZ=$(G for-each-ref --sort=-creatordate "--format=%(refname)%1f%(objecttype)%1f%(objectname)%1f%(*objecttype)%1f%(*objectname)%1f%(creatordate:short)%1f%(creatordate:unix)%1e" refs/tags | wc -c)
150[ "$TSZ" -gt 1000000 ] && [ "$TSZ" -le 16777216 ] && ok "fixture: tag list is $TSZ bytes (over 1,000,000 passes, inside gdtl)" || bad "fixture: tag list is only $TSZ bytes"
151page "tags release big" html "$U/releases/tag/big" 200
152page "tags releases" html "$U/releases" 200
153page "tags releases" json "$U/releases" 200
154page "tags list" html "$U/tags" 200
155u_tags
156f_longname || { bad "fixture longname"; exit 1; }
157check "$(G ls-tree --name-only -z refs/heads/main | tr "\0" "\n" | awk "{ if (length(\$0) > m) m = length(\$0) } END { print m }")" 110000 "fixture: longest file name bytes"
158page "longname home" html "$U" 200
159page "longname home" json "$U" 200
160page "longname tree" html "$U/tree/main" 200
161page "longname tree" json "$U/tree/main" 200
162page "longname site search" html "http://127.0.0.1:$PORT/search?q=needle" 200
163page "longname site search" json "http://127.0.0.1:$PORT/search?q=needle" 200
164page "longname repo search" html "$U/search?q=needle" 200
165page "longname repo search" json "$U/search?q=needle" 200
166u_longname
167stop
168if [ -n "${NONEG:-}" ]; then echo "server bigrepo: $PASS passed, $FAIL failed (negative controls skipped)"; [ "$FAIL" = 0 ]; exit; fi
169# ---- negative controls: the old line back in one place; the page of that case ends the server
170neg() { # neg NAME SEDX WANTRC FORM URL
171 start "$T/mut-$1" "$2" || { bad "NEG $1: mutant did not start"; return; }
172 if cmp -s "$T/mut-$1.om" "$T/forged.om"; then bad "NEG $1: sed changed nothing"; stop; return; fi
173 check "$(diff "$T/mut-$1.om" "$T/forged.om" | grep -c "^<")" 1 "NEG $1: one line differs"
174 get "$4" "$5" > /dev/null; rcwait
175 check "$RC" "$3" "NEG $1: the old line ends the server"
176}
177f_longref; neg brbest "s/^if and gt k best le k len gbref\$/if gt k best/" 103 html "$U/tree/$LREF"; u_longref
178f_octopus
179neg brcmtids "/^fn brcmtids to void\$/,/^x = brxfind s e 32\$/s/^while lt s e bound BRBIG\$/while lt s e bound 64/" 104 html "$U/commit/$OCT"
180neg brzpar "/^fn brzpar /,/^x = brxfind s e 32\$/s/^while lt s e bound BRBIG\$/while lt s e bound 64/" 104 json "$U/commit/$OCT"
181u_octopus
182f_assets; neg dllsa "/^fn dllsa to void\$/,/^dllsa1 s i\$/s/^for i ulong n bound 16777216\$/for i ulong n/" 104 html "$U/releases/tag/v1"; u_assets
183f_tags
184neg dltags "/^fn dltags to bool\$/,/^put gdtll 0 n\$/s/^for i ulong n bound 16777216\$/for i ulong n/" 104 html "$U/releases"
185neg dlsplit "/^fn dlsplit to bool\$/,/^if eq get gdtl i 30\$/s/^for i ulong n bound 16777216\$/for i ulong n/" 104 html "$U/releases"
186u_tags
187f_longname
188neg fjfx "/^fn fjfx /,/^fjstr\$/s/^for k ulong n bound 16777216\$/for k ulong n bound 65536/" 104 json "$U"
189neg brypath "/^fn brypath /,/^fjstr\$/s/^for i ulong nl bound BRBIG\$/for i ulong nl bound 4096/" 104 json "$U/tree/main"
190neg fcolon "/^fn fcolon /,/^if eq get fxo j 58\$/s/^while lt j e bound 16777216\$/while lt j e bound 100000/" 104 html "http://127.0.0.1:$PORT/search?q=needle"
191u_longname
192echo "server bigrepo: $PASS passed, $FAIL failed"
193[ "$FAIL" = 0 ]