interplane.Get Omega
Read in your language

interplane-forge

INTERPLANE Forge

Brought by drakestapleton

branch main Branches Tags History

interplane-forge / server / tests / counts.sh

313 lines · 24033 bytes Raw Blame History
1#!/usr/bin/env bash
2# server/tests/counts.sh: host gates for the JSON form (forge/explore/1, forge/repo/1) and the real
3# clone / download / seeding counts of the repo home (card t_2ace6336, docs/API.md).
4# bash server/tests/counts.sh (spark; FORGED_CPUS default 12-14; ports FORGE_TEST_PORT 18487 and +1)
5# Builds two trial copies of forged: HEAD of this tree and the BASE commit (FORGE_TEST_BASE, required: there is
6# no default), with the data dir, the port, the two nginx logs, the node-db stamp, rad and
7# getent redirected into a temp dir (rad and getent are the fakes in server/tests/fake/). Fixture logs
8# hold counted lines and negative controls (our own addresses, the home address, bots, 404, POST
9# variants, a non-public RID, 304, method 3). Checks:
10# counts: HTML header and JSON equal the fixture's expected numbers; a log that grows is read from
11# where it stopped; a restart replays the journal without counting twice; a rotation (<log> moved
12# to <log>.1, new <log>) counts the rest of .1 and the new file; a torn journal batch is ignored;
13# nothing is written when the logs did not change; rad failing shows "not measured" / null; with the
14# rotated log gone, a restart keeps the counts from the journal alone.
15# JSON: valid (python3 -m json.tool) under X-Forge-Base / and /forge/, schema names, paths built
16# from the base, last_commit sha and time equal git (oracle) for every public repo, file names
17# equal git ls-tree, Accept negotiation, .json suffix, 405 on POST, 404 for denied / unknown .json.
18# HTML: every page's <main> equals the BASE build's apart from the known additions listed in
19# section 8 (the alternate link, the three count lines, and the README-first project page, whose
20# lines are compared as a sorted list after its new header and section lines are removed).
21# FORGE_TEST_MUTANT=<sed script> applies a mutant to the HEAD copy (server/tests/counts-mutants.sh).
22# Read-only on real storage; never touches 18480, ~/forge-data, the real logs or port 18091.
23set -u
24cd "$(dirname "$0")/../.."
25ROOT=$(pwd)
26CORES=${FORGED_CPUS:-12-14}
27PORT=${FORGE_TEST_PORT:-18487}
28PORTB=$((PORT + 1))
29# The base has no default: on a line that holds later page changes the edge is the wrong base and one
30# HTML check then fails for a reason that is not in the head (review of 56990a44, check 9). For
31# integrate/one the base is 5864d34282ec18914c0f2e274015ae3bafc50d47 (cb98401, the line before
32# json-counts, plus forge/simplify at 21196c82; kept in ~/work/forge/web as refs/integrate-one/counts-base).
33if [ -z "${FORGE_TEST_BASE:-}" ]; then echo "NOT_RUN: FORGE_TEST_BASE is not set: name the commit whose pages this head must equal (see the note above this line)"; exit 3; fi
34BASE=$FORGE_TEST_BASE
35# A fresh clone of the Radicle project does not hold that base (bay 6 at 3edbe5aa: NOT_RUN). Fetch the
36# objects of refs/integrate-one/counts-base from FORGE_TEST_BASE_REPO (default ~/work/forge/web; read
37# only, no ref is written here), then check again.
38if ! git rev-parse -q --verify "$BASE^{commit}" > /dev/null; then
39 BR=${FORGE_TEST_BASE_REPO:-$HOME/work/forge/web}
40 [ -d "$BR" ] && git fetch -q --no-tags "$BR" refs/integrate-one/counts-base 2> /dev/null \
41 && echo "base $BASE fetched from $BR refs/integrate-one/counts-base"
42fi
43git rev-parse -q --verify "$BASE^{commit}" > /dev/null || { echo "NOT_RUN: base $BASE is not a commit of this repository"; exit 3; }
44OMC=$HOME/work/flux/omega-mv/seed/out/omc
45PY=/usr/bin/python3
46STORE=$HOME/.radicle/storage
47R=drakestapleton/cuda-crack
48RID=z631r2JJiVT8it4tST7RK24hpowi
49DENY=z2ft64NFLsKzWttCXw6NWNbRQLggQ
50NSID=z6MkfZDue1TbaNFi3ZzcD9uiTeduPLC52ucdFVuLKZwexxhK
51T=$(mktemp -d)
52pid=; pidb=
53pass=0; fail=0
54ok() { pass=$((pass+1)); echo "PASS $*"; }
55bad() { fail=$((fail+1)); echo "FAIL $*"; }
56check() { if [ "$1" = "$2" ]; then ok "$3 ($1)"; else bad "$3: want '$2', got '$1'"; fi; }
57cleanup() { [ -n "$pid" ] && kill "$pid" 2>/dev/null; [ -n "$pidb" ] && kill "$pidb" 2>/dev/null; wait 2>/dev/null; [ -n "${KEEP:-}" ] || rm -rf "$T"; }
58trap cleanup EXIT
59mkdir -p "$T/bin" "$T/ng" "$T/data/logs" "$T/datab/logs" "$T/base"
60cp server/tests/fake/rad server/tests/fake/getent "$T/bin/"
61chmod 755 "$T/bin/rad" "$T/bin/getent"
62: > "$T/ng/wal"
63
64# ---- builds: compose like run.sh, then redirect paths and port in the test copy only
65compose() { # dir out port data
66 (cd "$1" && { printf 'om2\n'; cat $(./run.sh units); }) | sed \
67 -e "s|^text tfdata \".*\"|text tfdata \"$4/\"|" \
68 -e "s|^text tfzp0 \".*\"|text tfzp0 \"$T/ng/dl.log\"|" \
69 -e "s|^text tfzp1 \".*\"|text tfzp1 \"$T/ng/access.log\"|" \
70 -e "s|^text tfzwal \".*\"|text tfzwal \"$T/ng/wal\"|" \
71 -e "s|^text tfzrad \".*\"|text tfzrad \"$T/bin/rad\"|" \
72 -e "s|^text tfzgent \".*\"|text tfzgent \"$T/bin/getent\"|" \
73 -e "s/18480/$3/g" > "$2.om.0"
74 if [ "$1" = "$ROOT" ] && [ -n "${FORGE_TEST_MUTANT:-}" ]; then sed -e "$FORGE_TEST_MUTANT" "$2.om.0" > "$2.om"; else mv "$2.om.0" "$2.om"; fi
75 [ "$1" = "$ROOT" ] && [ -n "${FORGE_TEST_MUTANT:-}" ] && { cmp -s "$2.om.0" "$2.om" && { echo "MUTANT did not apply"; exit 3; }; echo "MUTANT: $FORGE_TEST_MUTANT"; }
76 taskset -c "$CORES" nice -n 10 "$OMC" < "$2.om" > "$2" 2> "$2.err" || { echo "BUILD FAILED $1: $(cat "$2.err")"; exit 1; }
77 chmod 755 "$2"
78}
79git archive "$BASE" | tar -x -C "$T/base"
80compose "$ROOT" "$T/forged" "$PORT" "$T/data"
81compose "$T/base" "$T/forged.base" "$PORTB" "$T/datab"
82echo "built head $(sha256sum < "$T/forged" | cut -c1-16), base $BASE $(git rev-parse --short "$BASE") $(sha256sum < "$T/forged.base" | cut -c1-16)"
83
84start() { taskset -c "$CORES" nice -n 10 "$T/forged" 2>> "$T/forged.err" & pid=$!; up "$PORT"; }
85stop() { kill "$pid" 2>/dev/null; wait "$pid" 2>/dev/null; pid=; }
86up() { for i in $(seq 100); do curl -s -o /dev/null "http://127.0.0.1:$1/explore" && return 0; sleep 0.1; done; echo "server on $1 did not start"; cat "$T/forged.err"; exit 1; }
87# get PORT BASE PATH [curl args] -> body $T/b, headers $T/h, prints the status
88# get: an HTML body is read without the send-time translation hints of server/tr.om (translate="no"
89# attributes and <span translate="no"> around hashes and ids; server/tests/translate_check.py strip),
90# so the count lines and the pages compare as text with the BASE build, which adds none
91get() {
92 local p=$1 b=$2 u=$3 c; shift 3
93 c=$(curl -s -o "$T/b" -D "$T/h" -w '%{http_code}' -H "X-Forge-Base: $b" -H "X-Real-IP: 127.0.0.1" "$@" "http://127.0.0.1:$p/$u")
94 if grep -qi '^content-type: text/html' "$T/h"; then python3 server/tests/translate_check.py strip "$T/b" "$T/b.s" && mv "$T/b.s" "$T/b"; fi
95 printf '%s' "$c"
96}
97ctype() { tr -d '\r' < "$T/h" | sed -n 's/^[Cc]ontent-[Tt]ype: //p' | tail -1; }
98jv() { jq -r "$1" "$T/b"; }
99
100# ---- fixture logs (TEST-NET addresses; 198.51.100.7 is the fake home address)
101Q='/info/refs?service=git-upload-pack'
102cat > "$T/ng/dl.log" <<EOF
1031794162545.332 203.0.113.5 200 "/rad/$RID.git$Q" "git/2.56.0"
1041794162546.100 203.0.113.6 200 "/rad/$RID.git/$NSID$Q" "git/2.43.0"
1051794162547.000 192.168.1.9 200 "/rad/$RID.git$Q" "git/2.43.0"
1061794162548.000 198.51.100.7 200 "/rad/$RID.git$Q" "git/2.43.0"
1071794162549.000 203.0.113.7 200 "/rad/$RID.git$Q" "SofyaBot/1.0 (+https://sofya.co/bot)"
1081794162550.000 203.0.113.8 404 "/rad/$RID.git$Q" "git/2.43.0"
1091794162551.000 203.0.113.9 200 "/rad/$DENY.git$Q" "git/2.43.0"
1101794162552.000 203.0.113.10 200 "/code/git/cuda-crack.git$Q" "git/2.43.0"
1111794162553.000 100.100.1.1 200 "/rad/$RID.git$Q" "git/2.43.0"
1121794162554.000 100.200.1.1 200 "/rad/$RID.git$Q" "git/2.43.0"
1131794162555.000 203.0.113.11 200 "/code/zip/cuda-crack.zip" "curl/8.5.0"
114EOF
115cat > "$T/ng/access.log" <<EOF
116127.0.0.1 - - [08/Nov/2026:05:48:05 -0600] "GET / HTTP/2.0" 301 162 "-" "curl/8.5.0"
117127.0.0.1 - - [08/Nov/2026:05:57:35 -0600] "POST /rad/$RID.git/git-upload-pack HTTP/2.0" 200 145 "-" "git/2.43.0"
118127.0.0.1 - - [08/Nov/2026:05:57:37 -0600] "POST /rad/$RID.git/git-upload-pack HTTP/2.0" 200 133032806 "-" "git/2.43.0"
119127.0.0.1 - - [08/Nov/2026:06:00:00 -0600] "POST /rad/$RID.git/$NSID/git-upload-pack HTTP/1.1" 200 65 "-" "git/2.43.0"
120127.0.0.1 - - [08/Nov/2026:06:00:01 -0600] "POST /rad/$RID.git/git-upload-pack HTTP/2.0" 404 3154 "-" "git/2.43.0"
121127.0.0.1 - - [08/Nov/2026:06:00:02 -0600] "POST /rad/$DENY.git/git-upload-pack HTTP/2.0" 200 65 "-" "git/2.43.0"
122127.0.0.1 - - [08/Nov/2026:06:00:03 -0600] "GET /rad/$RID.git$Q HTTP/2.0" 200 148 "-" "git/2.43.0"
123127.0.0.1 - - [08/Nov/2026:06:00:04 -0600] "POST /rad/$RID.git/git-upload-pack-x HTTP/2.0" 200 65 "-" "git/2.43.0"
124EOF
125A=/drakestapleton/cuda-crack
126cat > "$T/data/logs/forged.log" <<EOF
1272026-11-07T11:02:15Z start /home/drakestapleton/work/forge/web/server/forged (cpus 4-5 nice 10)
128forged: reloaded, public repos 28
1291794049338 127.0.0.1 1 / 200 13440 0
1301794049400 203.0.113.5 1 $A/archive/refs/heads/main.zip 200 1000 5
1311794049401 203.0.113.5 1 $A/archive/refs/heads/main.tar.gz 304 0 1
1321794049402 127.0.0.1 1 $A/archive/refs/heads/main.zip 200 1000 5
1331794049403 198.51.100.7 1 $A/archive/refs/heads/main.zip 200 1000 5
1341794049404 203.0.113.6 1 $A/releases/download/v1/cuda-crack-v1.zip 200 1000 5
1351794049405 203.0.113.6 3 $A/archive/refs/heads/main.zip 200 0 1
1361794049406 203.0.113.6 1 /drakestapleton/omega-pearl/archive/refs/heads/main.zip 200 1000 5
1371794049407 203.0.113.6 1 $A/tree/main 200 1000 5
138EOF
139cp "$T/data/logs/forged.log" "$T/datab/logs/forged.log"
140iso() { TZ=UTC date -u -d "@$1" +%Y-%m-%dT%H:%M:%SZ; } # oracle for the since times
141S0=$(iso 1794162545); S2=$(iso 1794049338)
142
143counts() { # base -> "fetches posts downloads archives releases seeds" from the JSON (posts and seeds: retired, null)
144 get "$PORT" "$1" "$R.json" > /dev/null
145 jq -r '[.counts.git_fetches.count, .counts.upload_pack_requests.count, .counts.downloads.count, .counts.downloads.archives, .counts.downloads.release_assets, .counts.seeds.count] | map(tostring) | join(" ")' "$T/b"
146}
147
148# A torn FIRST batch must not retain its uncommitted since marker after its bytes are discarded.
149printf 'e g 1794162545 %s\ns 0 1794000000\n' "$RID" > "$T/data/counts.log" # a since that differs from the log's: it must not survive
150start
151# ---- 1. first read of the fixtures
152check "$(counts /)" "4 null 2 1 1 null" "counts from the fixture logs (fetches downloads archives releases; posts and seeds retired)"
153check "$(jv .counts.git_fetches.since)" "$S0" "git_fetches since = first line of the download log"
154check "$(jv .counts.upload_pack_requests.since)" "null" "upload_pack: source retired, since is null"
155check "$(jv .counts.downloads.since)" "$S2" "downloads since = first access line of forged.log"
156stop; start
157check "$(counts /)" "4 null 2 1 1 null" "restart after recovery of the torn first journal batch"
158check "$(jv .counts.git_fetches.since)" "$S0" "since survives recovery of the torn first batch"
159check "$(jv .counts.seeds.as_of)" "null" "seeds: source retired, as_of is null"
160c=$(get "$PORT" /forge/ "$R"); check "$c" 200 "GET /forge/ repo home"
161grep -q 'Clones and fetches over HTTPS: <b>4</b> by visitors' "$T/b" && ok "HTML: 4 visitor fetches" || bad "HTML fetch line: $(grep -o 'Clones and fetches[^<]*<b>[^<]*' "$T/b")"
162grep -q "<b>not measured</b> <code>git-upload-pack</code> requests from all clients (the source of this count is retired)" "$T/b" && ok "HTML: upload-pack requests not measured (source retired)" || bad "HTML upload-pack line"
163grep -q "Downloads: <b>2</b> by visitors (1 source archives, 1 release assets" "$T/b" && ok "HTML: 2 downloads (1 + 1)" || bad "HTML downloads: $(grep -o 'Downloads:.\{0,80\}' "$T/b")"
164grep -q "since ${S0%%T*})" "$T/b" && grep -q "since ${S2%%T*})" "$T/b" && ok "HTML: each count names its since date" || bad "HTML since dates"
165grep -q "Seeding: <b>not measured</b> (the source of this count is retired)" "$T/b" && ok "HTML: seeding not measured (source retired)" || bad "HTML seeds"
166grep -q "<link rel=\"alternate\" type=\"application/json\" href=\"/forge/$R.json\">" "$T/b" && ok "repo home links its JSON form" || bad "repo home alternate link"
167J=$(grep -c '^e ' "$T/data/counts.log"); check "$J" 9 "journal holds the 9 counted events"
168sz=$(stat -c %s "$T/data/counts.log")
169counts / > /dev/null; check "$(stat -c %s "$T/data/counts.log")" "$sz" "nothing new in the logs: the journal is not written"
170echo "1794049500 127.0.0.1 1 $A 200 1 1" >> "$T/data/logs/forged.log"
171counts / > /dev/null; check "$(stat -c %s "$T/data/counts.log")" "$sz" "a log grew by an uncounted line: the journal is not written"
172
173# ---- 2. growth is read from where it stopped
174echo "1794162600.000 203.0.113.20 200 \"/rad/$RID.git$Q\" \"git/2.43.0\"" >> "$T/ng/dl.log"
175echo "127.0.0.1 - - [08/Nov/2026:07:00:00 -0600] \"POST /rad/$RID.git/git-upload-pack HTTP/2.0\" 200 65 \"-\" \"git/2.43.0\"" >> "$T/ng/access.log"
176echo "1794049600 203.0.113.21 1 $A/archive/refs/tags/v1.tar.gz 200 1000 5" >> "$T/data/logs/forged.log"
177check "$(counts /forge/)" "5 null 3 2 1 null" "one more line in each log counts once"
178printf '1794162601.000 203.0.113.22 200 "/rad/%s.git%s" "git' "$RID" "$Q" >> "$T/ng/dl.log"
179check "$(counts /)" "5 null 3 2 1 null" "a half-written last line is not counted yet"
180printf '/2.43.0"\n' >> "$T/ng/dl.log"
181check "$(counts /)" "6 null 3 2 1 null" "the line counts once it is complete"
182
183# ---- 3. restart: journal replay, no double count
184stop; start
185check "$(counts /)" "6 null 3 2 1 null" "restart replays the journal without counting twice"
186
187# ---- 4. rotation: rest of <log>.1, then the new <log>
188echo "1794162700.000 203.0.113.30 200 \"/rad/$RID.git$Q\" \"git/2.43.0\"" >> "$T/ng/dl.log"
189mv "$T/ng/dl.log" "$T/ng/dl.log.1"
190echo "1794249000.000 203.0.113.31 200 \"/rad/$RID.git$Q\" \"git/2.43.0\"" > "$T/ng/dl.log"
191check "$(counts /)" "8 null 3 2 1 null" "after a rotation: the rest of .1 and the new log count once each"
192check "$(jv .counts.git_fetches.since)" "$S0" "since stays the start of the oldest log read"
193stop; start
194check "$(counts /)" "8 null 3 2 1 null" "restart after the rotation"
195# ---- 5. a torn batch at the end of the journal is ignored
196printf 'e g 1794162999 %s\ne g 1794163000 %s\n' "$RID" "$RID" >> "$T/data/counts.log"
197stop; start
198check "$(counts /)" "8 null 3 2 1 null" "a journal batch without its cursor line is ignored"
199# An abandoned batch must not be committed by the NEXT real batch's cursor.
200echo "1794249001.000 203.0.113.32 200 \"/rad/$RID.git$Q\" \"git/2.43.0\"" >> "$T/ng/dl.log"
201check "$(counts /)" "9 null 3 2 1 null" "new event after a torn journal batch"
202stop; start
203check "$(counts /)" "9 null 3 2 1 null" "later cursor cannot resurrect abandoned journal events"
204# Also discard a byte-torn event line before a later append.
205printf 'e g 1794163000 z63' >> "$T/data/counts.log"
206stop; start
207check "$(counts /)" "9 null 3 2 1 null" "partial journal line is ignored"
208echo "1794249002.000 203.0.113.33 200 \"/rad/$RID.git$Q\" \"git/2.43.0\"" >> "$T/ng/dl.log"
209check "$(counts /)" "10 null 3 2 1 null" "new event after a partial journal line"
210stop; start
211check "$(counts /)" "10 null 3 2 1 null" "partial journal line cannot swallow the next event"
212# ---- 5b. the old logs are gone (rotated away and compressed): the counts stay, from the journal
213mv "$T/ng/dl.log.1" "$T/ng/dl.log.2.gone"
214stop; start
215check "$(counts /)" "10 null 3 2 1 null" "older logs gone: the counts come from the journal"
216
217# ---- 7. JSON form under both bases
218for b in / /forge/; do
219 for u in explore.json "$R.json"; do
220 c=$(get "$PORT" "$b" "$u"); check "$c" 200 "GET $b$u"
221 case "$(ctype)" in "application/json; charset=utf-8") ok "$b$u content type";; *) bad "$b$u content type '$(ctype)'";; esac
222 $PY -m json.tool "$T/b" > /dev/null && ok "$b$u is valid JSON (python3 -m json.tool)" || bad "$b$u is not valid JSON"
223 done
224 get "$PORT" "$b" explore.json > /dev/null
225 check "$(jv .schema)" "forge/explore/1" "explore schema ($b)"
226 check "$(jv .base)" "$b" "explore base ($b)"
227 check "$(jv '.repos | length')" "$(jv .count)" "explore count = number of repos ($b)"
228 check "$(jv "[.repos[] | select(.name == \"cuda-crack\")][0].path")" "${b}$R" "explore path built from the base ($b)"
229 check "$(jv "[.repos[] | select(.name == \"cuda-crack\")][0].rid")" "$RID" "explore id is the bare RID ($b)"
230 get "$PORT" "$b" "$R.json" > /dev/null
231 check "$(jv .schema)" "forge/repo/1" "repo schema ($b)"
232 check "$(jv .json)" "${b}$R.json" "repo json link ($b)"
233 check "$(jv .archives.zip)" "${b}$R/archive/refs/heads/main.zip" "repo zip link ($b)"
234 check "$(jv .clone.git_https)" "null" "no public Git URL: git_https is null ($b)"
235 check "$(jv .clone.rad_clone)" "null" "no clone command: rad_clone is null ($b)"
236 check "$(jv .clone.rad)" "$RID" "clone id is the bare RID ($b)"
237 check "$(jv .readme.raw)" "${b}$R/raw/main/README.md" "repo readme raw link ($b)"
238done
239# every public repo: last_commit sha and time equal git; the subject equals git (valid UTF-8)
240get "$PORT" / explore.json > /dev/null
241n=$(jv '.repos | length'); bad_lc=0
242for k in $(seq 0 $((n - 1))); do
243 rid=$(jv ".repos[$k].rid"); br=$(jv ".repos[$k].default_branch")
244 ref=refs/heads/$br
245 git --git-dir="$STORE/$rid" rev-parse -q --verify "$ref^{commit}" > /dev/null 2>&1 || ref=refs/namespaces/$NSID/refs/heads/$br
246 want=$(git --git-dir="$STORE/$rid" log -1 --format='%H %ct' "$ref" 2> /dev/null)
247 wsha=${want% *}; wt=$(iso "${want#* }"); wsub=$(git --git-dir="$STORE/$rid" log -1 --format=%s "$ref" 2> /dev/null)
248 got="$(jv ".repos[$k].last_commit.sha") $(jv ".repos[$k].last_commit.time")"
249 gsub=$(jv ".repos[$k].last_commit.subject")
250 if [ "$got" != "$wsha $wt" ] || [ "$gsub" != "$wsub" ]; then bad_lc=$((bad_lc+1)); echo " mismatch $(jv ".repos[$k].name"): '$got' '$gsub' vs '$wsha $wt' '$wsub'"; fi
251done
252check "$bad_lc" 0 "last_commit sha, ISO time and subject equal git for all $n public repos"
253get "$PORT" / "$R.json" > /dev/null
254check "$(jv '[.files[].name] | join("/")')" "$(git --git-dir="$STORE/$RID" ls-tree --name-only refs/heads/main | paste -sd/)" "repo files equal git ls-tree"
255check "$(jv '.files_truncated')" "false" "files_truncated false"
256# Accept negotiation
257c=$(get "$PORT" /forge/ explore -H 'Accept: application/json'); check "$c $(ctype)" "200 application/json; charset=utf-8" "/explore with Accept: application/json"
258c=$(get "$PORT" /forge/ "" -H 'Accept: application/json'); check "$(jv .schema)" "forge/explore/1" "/ with Accept: application/json"
259c=$(get "$PORT" /forge/ "$R" -H 'Accept: application/json'); check "$(jv .schema)" "forge/repo/1" "repo home with Accept: application/json"
260c=$(get "$PORT" /forge/ "$R" -H 'Accept: text/html,application/xhtml+xml,application/json;q=0.9,*/*;q=0.8'); check "$(ctype)" "text/html; charset=utf-8" "browser Accept that names text/html stays HTML"
261c=$(get "$PORT" /forge/ "$R"); check "$(ctype)" "text/html; charset=utf-8" "no Accept header stays HTML"
262# negative controls
263check "$(get "$PORT" / drakestapleton/omega-pearl.json)" 404 "NEG denied repo .json is 404"
264check "$(get "$PORT" / drakestapleton/aien-crypto.json)" 404 "NEG denied repo aien-crypto.json is 404"
265check "$(get "$PORT" / drakestapleton/no-such-repo.json)" 404 "NEG unknown repo .json is 404"
266check "$(get "$PORT" / drakestapleton/omega-pearl -H 'Accept: application/json')" 404 "NEG denied repo with Accept JSON is 404"
267check "$(get "$PORT" / "rad:$DENY.json")" 404 "NEG denied RID .json is 404"
268check "$(get "$PORT" / "$R.json/x")" 404 "NEG .json with more path is 404"
269check "$(get "$PORT" / explore.json -X POST)" 405 "NEG POST /explore.json is 405"
270check "$(get "$PORT" / "$R.json" -X POST)" 405 "NEG POST repo .json is 405"
271# since card t_6b17c31a every page with a JSON form names its own URL (server/tests/jsonpages.sh walks them all)
272get "$PORT" / "$R/tree/main" > /dev/null; grep -q "<link rel=\"alternate\" type=\"application/json\" href=\"/$R/tree/main\">" "$T/b" && ok "tree page names its own URL as the JSON alternate" || bad "tree page lacks its own JSON alternate"
273
274# ---- 8. HTML unchanged against the BASE build, apart from the known additions
275taskset -c "$CORES" nice -n 10 "$T/forged.base" 2>> "$T/forged.base.err" & pidb=$!; up "$PORTB"
276# The site icon link (ham/forge-favicon) is the third addition: every page head names <base>assets/favicon.svg.
277strip() { sed -z -e 's|<link rel="alternate" type="application/json" href="[^"]*">||' -e 's|<link rel="icon" type="image/svg+xml" href="[^"]*assets/favicon.svg">||' -e 's|\n<p class="meta">Clones and fetches over HTTPS: [^\n]*\n<p class="meta">Downloads: [^\n]*\n<p class="meta">\(Radicle\|Seeding\): [^\n]*\n||' "$1"; }
278# The fourth (one site, server/tests/sitechrome.sh): the interplane.io header and footer replace the
279# forge's, so only the page content, <main> to </main>, is compared with the base build.
280mainpart() { sed -n '/^<main[ >]/,/^<\/main>$/p' | sed '1s/^<main[^>]*>$/<main>/'; }
281# The fifth (browse/b_md.om): an HTML comment line renders nothing, where the base build showed it
282# escaped as the first or last line of a paragraph (the README language bar); removed from the base side.
283nocomment() { sed -z -e 's|<p>&lt;!-- [^\n]*--&gt;\n|<p>|g' -e 's|\n&lt;!-- [^\n]*--&gt;</p>|</p>|g'; }
284# The sixth (ForgeReadmeFirst, server/tests/readmefirst.sh): a new project header and tabs on every repo
285# page; the repo home shows the README first and keeps its old lines, unchanged, in a "For developers"
286# section; repo list rows carry a state line and keep their records; README links that leave the
287# site carry class "ext". pjpre removes the head's new section lines and the three count lines, which
288# moved from the header into that section (the base side loses them with its header; their numbers are
289# checked by the earlier sections); pjcanon, on both sides, removes the project header and tabs, the
290# explore introduction and the forge home box, reduces each repo list row to its records (link,
291# description, last commit, stars) and drops the "ext" class; the lines are then compared as sorted
292# lists, because the home moved its lines below the README. Every other line must still be equal.
293pjpre() { sed -e '/^<section class="pj-dev"/,/^<\/dl>$/d' -e '/^<p class="pj-recs">/,/^<\/section>$/d' -e '/^<p class="pj-nordme">/d' -e '/^<p class="meta">Clones and fetches over HTTPS: /d' -e '/^<p class="meta">Downloads: /d' -e '/^<p class="meta">\(Radicle\|Seeding\): /d' "$1"; }
294pjcanon() {
295 sed -E -e '/^<section class="rhead/,/^<nav class="tabs/d' -e '/^<h1>Explore repositories<\/h1>/d' -e '/^<section class="box"><h1>INTERPLANE Forge<\/h1>/d' \
296 -e 's|^<li><span class="stars" title="stars">&#9733; ([0-9]+)</span><a class="rname" href="([^"]*)">[^<]*</a><p class="desc">(.*)</p><p class="meta">Last commit: (.*)</p></li>$|ROW \2 \3 \4 \1|' \
297 -e 's|^<li class="pj-row"><a class="rname" href="([^"]*)">[^<]*</a><p class="desc">(.*)</p><p class="state [^"]*">.*</p><p class="meta">Last commit: (.*) &#183; <span class="stars" title="stars">&#9733; ([0-9]+)</span></p></li>$|ROW \1 \2 \3 \4|' \
298 -e 's| class="ext" rel="nofollow| rel="nofollow|g' -e 's|(href="mailto:[^"]*") rel="nofollow noopener noreferrer">|\1>|g' | LC_ALL=C sort
299}
300same=0; diff=0
301for b in / /forge/; do
302 for u in explore "" drakestapleton "$R" "$R/tree/main" "$R/blob/main/README.md" "$R/commits/main" "$R/branches" "$R/tags" "$R/releases" "$R/patches" "$R/issues" "search?q=forge" "$R/stargazers" "no-such" "drakestapleton/omega-pearl"; do
303 get "$PORT" "$b" "$u" > /dev/null; pjpre "$T/b" > "$T/b.pj"; strip "$T/b.pj" | mainpart | pjcanon > "$T/new"; cp "$T/b" "$T/new.raw"
304 get "$PORTB" "$b" "$u" > /dev/null; mainpart < "$T/b" | nocomment | pjcanon > "$T/old"
305 [ -s "$T/new" ] && [ -s "$T/old" ] || bad "$b$u: no <main> to compare"
306 if cmp -s "$T/new" "$T/old"; then same=$((same+1)); else diff=$((diff+1)); echo " differs: $b$u"; diff "$T/old" "$T/new" | head -5; fi
307 case "$u" in explore|"") grep -q '<link rel="alternate" type="application/json" href="' "$T/new.raw" || bad "$b$u lacks the alternate link";; esac
308 done
309done
310check "$diff" 0 "HTML content (<main>) equal to the base build on $same pages (explore and repo home after removing the additions)"
311stop
312echo "counts.sh: $pass passed, $fail failed"
313[ "$fail" = 0 ]