interplane.Get Omega
Read in your language

interplane-forge

INTERPLANE Forge

Brought by drakestapleton

branch main Branches Tags History

interplane-forge / store / tests / compare.sh

588 lines · 47357 bytes Raw Blame History
1#!/usr/bin/env bash
2# ORACLE: host test driver (bash, curl, git, bwrap, python3 store/tests/compare.py), not product code.
3# store/tests/compare.sh: the store-reading build of this tree against main's binary reading Radicle
4# storage (interplane-native DESIGN.md step 2 acceptance), with the negative controls and mutants.
5# bash store/tests/compare.sh STORE KEY IPL_DIR
6# STORE a trial store root made by interplane-native's tools/import-radicle.sh (read only:
7# its project folders are hard-linked into a private test root, never written)
8# KEY a key to sign the fixture projects with (any Ed25519 key; it need not be the store's
9# owner; read only, the fixtures stay in the test root). compare.py pairs the owner name with
10# one key over the store's own projects, and requires every fixture page to name exactly
11# KEY's fingerprint (COMPARE_FIXTURES, COMPARE_FIXTURE_KEY)
12# env COMPARE_RSTORE: the Radicle storage MAIN and DEF read (default ~/radicle-storage-frozen/storage,
13# the read-only copy kept after the Radicle removal of 2026-11-14; ~/.radicle no longer exists), and
14# the site chrome comes from its interplane.io repository (FORGE_SITE_STORE) for every build.
15# The STORE builds serve every public line of the test root's catalog less the deny list (Drake,
16# 2026-11-14: no served list), so a project without an old id (no-alias) is served under its git:<id>
17# (C8) and can be starred (C9).
18# IPL_DIR a checkout of interplane-native at 7db470da with bin/ built (its ipl makes the fixtures)
19# env: FORGED_CPUS (default 4,5), STORE_TEST_PORT (default 18610; uses PORT..PORT+5),
20# FORGE_MAIN_COMMIT (default 4ed98366d73a435e1f8477da6902b3f6411bdba4), KEEP=1 keeps $T.
21# Builds, all from the pinned omc and one chrome unit:
22# MAIN main at FORGE_MAIN_COMMIT, default units: reads Radicle storage (the current binary)
23# DEF this tree, default units (no FORGE_STORE): must answer byte for byte as MAIN
24# STORE this tree, FORGE_STORE=<test root>, FORGE_CLONE_BASE=https://interplane.io/
25# STORE0 the same without FORGE_CLONE_BASE (the clone panel without an HTTPS line)
26# TWIN this tree, default units reading the REAL ~/.radicle/storage and RIDS.md (port and data
27# only redirected): run in the same sandbox as STORE, it must list no repository, which
28# shows that sandbox has no Radicle storage
29# MAIN and DEF read the first table of ~/handoffs/radicle/RIDS.md (less the projects the store does
30# not hold) through symlinks into the real storage, as server/tests/jsonpages.sh does, plus the
31# fixtures as bare repositories under made-up RIDs. STORE and STORE0 run under bwrap with tmpfs over
32# ~/.radicle and ~/handoffs/radicle, so Radicle storage is absent from their file system.
33# Sample rule (at least ten projects): the largest repo.git (du) of the compared projects, the fixture
34# "slice-b-fixture" (tags, an annotated tag, and paths with non-ASCII bytes; the store's own tags are
35# only under refs/namespaces/<id>/refs/tags, e.g. Hop v0.2.0..v0.5.0, counted below; the fixture is
36# the tag coverage of this gate), then the rest in order
37# of sha256(name) until there are eleven. Pages per sampled project: repo home, tree (root and the
38# first folder), blob (README or the first file, a nested file, the fixture's non-ASCII files), raw,
39# blame, commits (default and by branch), commit (head, .patch, .diff), compare (parent...head and
40# the bare form), branches, tags, archives (zip and tar.gz of the default branch, and of a tag for
41# the fixture), each HTML page also with Accept: application/json; plus /, /explore, /explore.json.
42# Every page pair MAIN/STORE must be byte-identical apart from lines that name Radicle in MAIN and
43# their replacements in STORE (store/tests/compare.py lists every such line); MAIN/DEF must be
44# byte-identical on every page, plus the patch, issue, release, profile, search and status pages.
45# Never touches 18480, 18091, ~/forge-data, ~/.radicle or the STORE folder.
46set -u
47STORE=${1:?usage: compare.sh STORE KEY IPL_DIR}
48KEY=${2:?usage: compare.sh STORE KEY IPL_DIR}
49IPLD=${3:?usage: compare.sh STORE KEY IPL_DIR}
50cd "$(dirname "$0")/../.."
51ROOT=$(pwd)
52CORES=${FORGED_CPUS:-4,5}
53P0=${STORE_TEST_PORT:-18610}
54# MAIN: the Radicle-reading binary the store build must match apart from Radicle lines: the restore
55# branch below the store work, i.e. restore-rad-free 9a4420ab (main 4ed98366 + the agent door c12ca793 +
56# the Radicle-text removal c1f107df, the live build since 2026-11-14 19:04Z, merged by RadFreeForgeAndSI).
57MAINC=${FORGE_MAIN_COMMIT:-9a4420ab61b7437bed2b64346482dd0ff0fcd59f}
58OMC=$HOME/work/flux/omega-mv/seed/out/omc
59PIN=3ad9f10f64309e7acf8a725082b28e23a2a4aeb07e98322fb4dc0fcd8fc93194
60RSTORE=${COMPARE_RSTORE:-$HOME/radicle-storage-frozen/storage}
61export FORGE_SITE_STORE=${FORGE_SITE_STORE:-$RSTORE/z399yKvnXcBQNkKoq86iBDgTvQ5QV}
62OWNER=drakestapleton
63CB=https://interplane.io/
64export LC_ALL=C
65T=$(mktemp -d /tmp/forge-storecmp.XXXXXX)
66chmod 700 "$T"
67pids=()
68pass=0; fail=0; invalid=0
69ok() { pass=$((pass+1)); echo "PASS $*"; }
70bad() { fail=$((fail+1)); echo "FAIL $*"; }
71inval() { invalid=$((invalid+1)); echo "INVALID $*"; }
72cleanup() { for p in "${pids[@]}"; do kill "$p" 2>/dev/null; done; wait 2>/dev/null; [ -n "${KEEP:-}" ] || rm -rf "$T"; }
73trap cleanup EXIT
74run() { taskset -c "$CORES" nice -n 10 "$@"; }
75[ "$(sha256sum < "$OMC" | cut -c1-64)" = "$PIN" ] || { echo "NOT_RUN: omc is not the pin"; exit 3; }
76command -v bwrap > /dev/null || { echo "NOT_RUN: bwrap missing"; exit 3; }
77[ -f "$STORE/catalog.tsv" ] || { echo "NOT_RUN: no catalog in $STORE"; exit 3; }
78for p in $(seq "$P0" $((P0 + 5))); do
79 if ss -ltn | grep -q "127.0.0.1:$p "; then echo "NOT_RUN: port $p busy"; exit 3; fi
80done
81PMAIN=$P0; PDEF=$((P0 + 1)); PSTORE=$((P0 + 2)); PSTORE0=$((P0 + 3)); PTWIN=$((P0 + 4)); PMUT=$((P0 + 5))
82echo "tree $(git rev-parse HEAD) dirty=$(git status --porcelain | wc -l) main $MAINC omc $PIN"
83echo "store $STORE catalog sha256 $(sha256sum < "$STORE/catalog.tsv" | cut -c1-64) lines $(wc -l < "$STORE/catalog.tsv")"
84# ---------------------------------------------------------------- fixtures and the two allow-lists
85mkdir -p "$T/radstorage" "$T/store/projects" "$T/ng" "$T/bin" "$T/out"
86cp server/tests/fake/rad server/tests/fake/getent "$T/bin/"
87chmod 755 "$T/bin/rad" "$T/bin/getent"
88: > "$T/bin/radfail" # the fake rad answers "not measured": no minute-stamped line to race
89: > "$T/ng/dl.log"; : > "$T/ng/access.log"
90awk 'f==0 && /^\|---/ {f=1; next} f==1 && !/^\|/ {exit} f==1 {print}' "$HOME/handoffs/radicle/RIDS.md" > "$T/rids-live.md"
91# the fixture allow-list keeps the table's header and separator lines (server/repos.om flfind needs them)
92awk '/^\| repo \| RID \| default branch/ {print; getline; print; exit}' "$HOME/handoffs/radicle/RIDS.md" > "$T/RIDS.md"
93[ "$(wc -l < "$T/RIDS.md")" = 2 ] || { echo "NOT_RUN: RIDS.md has no first table header"; exit 3; }
94: > "$T/cat-live.tsv"; : > "$T/excluded.txt"
95while IFS= read -r row; do
96 name=$(printf '%s' "$row" | awk -F'|' '{gsub(/ /,"",$2); print $2}')
97 rid=$(printf '%s' "$row" | awk -F'|' '{gsub(/ /,"",$3); print $3}')
98 line=$(awk -F'\t' -v n="$name" '$1 == n' "$STORE/catalog.tsv")
99 if [ -z "$line" ]; then echo "$name $rid not in the store catalog" >> "$T/excluded.txt"; continue; fi
100 al=$(sed -n 's/^alias //p' "$STORE/projects/$name/records/1")
101 [ "$al" = "$rid" ] || { bad "store alias of $name is $al, RIDS.md says $rid"; continue; }
102 # MAIN reads the frozen Radicle storage: a project landed in the store after the freeze has another
103 # head there, so its pages cannot be equal; it is left out with both heads named
104 sbr=$(printf '%s' "$line" | cut -f3) shead=$(printf '%s' "$line" | cut -f4)
105 rhead=$(git --git-dir="$RSTORE/${rid#rad:}" rev-parse -q --verify "refs/heads/$sbr" 2>/dev/null)
106 if [ "$shead" != "$rhead" ]; then echo "$name $rid landed after the Radicle freeze (store $sbr ${shead:0:12}, frozen ${rhead:0:12})" >> "$T/excluded.txt"; continue; fi
107 printf '%s\n' "$row" >> "$T/RIDS.md"
108 printf '%s\n' "$line" >> "$T/cat-live.tsv"
109 ln -s "$RSTORE/${rid#rad:}" "$T/radstorage/${rid#rad:}"
110 cp -al "$STORE/projects/$name" "$T/store/projects/$name"
111done < "$T/rids-live.md"
112echo "compared projects $(wc -l < "$T/cat-live.tsv") of $(wc -l < "$T/rids-live.md") live; left out: $(tr '\n' ';' < "$T/excluded.txt")"
113# measurement behind the fixture: tags and non-ASCII paths on the default branch of every public line
114ntag=0; nna=0
115while IFS=$'\t' read -r n _ br _ vis; do
116 [ "$vis" = public ] || continue
117 g=$STORE/projects/$n/repo.git
118 [ -n "$(git --git-dir="$g" for-each-ref refs/tags 'refs/namespaces/*/refs/tags/*' | head -1)" ] && ntag=$((ntag + 1))
119 git --git-dir="$g" -c core.quotepath=false ls-tree -r --name-only "refs/heads/$br" | LC_ALL=C grep -q -P '[\x80-\xff]' && nna=$((nna + 1))
120done < "$STORE/catalog.tsv"
121echo "public store projects with a tag: $ntag; with a non-ASCII path on the default branch: $nna"
122# fixture projects, made with the lane's own ipl and KEY: slice-b-fixture (tags, non-ASCII paths),
123# omega-pearl (deny list by name), pearl-alias (deny list by the withdrawn RID), pearl-twin (their
124# positive twin), no-alias (a project without an old Radicle id)
125export GIT_AUTHOR_NAME=fixture GIT_AUTHOR_EMAIL=fixture@invalid GIT_COMMITTER_NAME=fixture GIT_COMMITTER_EMAIL=fixture@invalid
126mkfix() { # mkfix NAME ALIAS(rad:... or -) KIND [rids]: KIND tags or plain; rids also lists it for MAIN
127 local n=$1 al=$2 w=$T/fxw-$1 rid
128 git init -q -b main "$w" || return 1
129 export GIT_AUTHOR_DATE=2026-11-13T00:00:00Z GIT_COMMITTER_DATE=2026-11-13T00:00:00Z
130 printf '# %s\n\nfixture for store/tests/compare.sh\n' "$n" > "$w/README.md"
131 mkdir -p "$w/docs"; printf 'one\n' > "$w/docs/a.txt"
132 git -C "$w" add -A && git -C "$w" commit -q -m "first $n" || return 1
133 if [ "$3" = tags ]; then
134 git -C "$w" tag v0.1
135 mkdir -p "$w/日本" "$w/docs/naïve résumé"
136 printf 'ファイル\n' > "$w/日本/ファイル.txt"
137 printf 'déjà vu\n' > "$w/docs/naïve résumé/café.md"
138 export GIT_AUTHOR_DATE=2026-11-13T00:01:00Z GIT_COMMITTER_DATE=2026-11-13T00:01:00Z
139 git -C "$w" add -A && git -C "$w" commit -q -m "non-ASCII paths" || return 1
140 git -C "$w" tag -a v0.2 -m "annotated v0.2"
141 printf 'two\n' >> "$w/docs/a.txt"
142 export GIT_AUTHOR_DATE=2026-11-13T00:02:00Z GIT_COMMITTER_DATE=2026-11-13T00:02:00Z
143 git -C "$w" commit -q -am "third" || return 1
144 fi
145 mkdir -p "$T/store/projects/$n"
146 git clone -q --bare "$w" "$T/store/projects/$n/repo.git" || return 1
147 "$IPLD/ipl" init "$T/store" "$n" main public "$al" "$KEY" > /dev/null 2>> "$T/ipl.err" || return 1
148 printf 'fixture %s\n' "$n" > "$T/fx-$n.ev"; printf 'note %s\n' "$n" > "$T/fx-$n.note"
149 "$IPLD/ipl" import "$T/store" "$n" main "$T/fx-$n.ev" "$T/fx-$n.note" "fx-$n" "$KEY" > /dev/null 2>> "$T/ipl.err" || return 1
150 "$IPLD/ipl" verify "$T/store" "$n" > /dev/null 2>> "$T/ipl.err" || return 1
151 if [ "${4:-}" = rids ]; then
152 rid=${al#rad:}
153 git clone -q --bare "$w" "$T/radstorage/$rid" || return 1
154 printf '| %s | %s | main | - | test only | - |\n' "$n" "$al" >> "$T/RIDS.md"
155 fi
156}
157FXRID=zSliceBFixtureTagsNonAscii1
158mkfix slice-b-fixture "rad:$FXRID" tags rids || { bad "fixture slice-b-fixture: $(tail -3 "$T/ipl.err")"; exit 1; }
159mkfix omega-pearl rad:zSliceBDenyByNameAAAAAA1 plain || { bad "fixture omega-pearl"; exit 1; }
160mkfix pearl-alias rad:z2ft64NFLsKzWttCXw6NWNbRQLggQ plain || { bad "fixture pearl-alias"; exit 1; }
161mkfix pearl-twin rad:zSliceBDenyTwinAAAAAAAAA1 plain || { bad "fixture pearl-twin"; exit 1; }
162mkfix no-alias - plain || { bad "fixture no-alias"; exit 1; }
163# (the fixture off-list, a public project kept off the served list, is gone with the served list: the
164# store build serves every public line; what must not appear is a private line (C1, mutant private)
165# or a deny-list name or old id (C6, mutant deny))
166# link fixtures (C3): real projects made by ipl, then the folder (link-project) or its repo.git
167# (link-repo) moved aside and replaced by a symlink to it
168LP=link-project; LR=link-repo
169mkfix "$LP" rad:zSliceBLinkProjectAAAAA1 plain || { bad "fixture $LP"; exit 1; }
170mkfix "$LR" rad:zSliceBLinkRepoAAAAAAAA1 plain || { bad "fixture $LR"; exit 1; }
171mv "$T/store/projects/$LP" "$T/store/projects/.lp-real"; ln -s "$T/store/projects/.lp-real" "$T/store/projects/$LP"
172mv "$T/store/projects/$LR/repo.git" "$T/store/projects/$LR/.repo-real.git"; ln -s "$T/store/projects/$LR/.repo-real.git" "$T/store/projects/$LR/repo.git"
173unset GIT_AUTHOR_DATE GIT_COMMITTER_DATE
174# a public project of the store that is not in the compared list: present in the folder only
175EXTRA=$(cut -f1 "$STORE/catalog.tsv" | grep -v -x -F -f <(cut -f1 "$T/cat-live.tsv") | head -1)
176cp -al "$STORE/projects/$EXTRA" "$T/store/projects/$EXTRA"
177EXTRALINE=$(awk -F'\t' -v n="$EXTRA" '$1 == n' "$STORE/catalog.tsv")
178fxline() { if [ -f "$T/store/projects/$1/catalog.row" ]; then cat "$T/store/projects/$1/catalog.row"; else cat "$T/store/projects/.lp-real/catalog.row"; fi; }
179# the compared catalog: the store's own lines of the live projects in RIDS.md order, then the
180# fixture; every live line is byte-for-byte a line of STORE/catalog.tsv
181{ cat "$T/cat-live.tsv"; fxline slice-b-fixture; } > "$T/cat-base.tsv"
182n_sub=$(grep -c -x -F -f "$STORE/catalog.tsv" "$T/cat-live.tsv")
183[ "$n_sub" = "$(wc -l < "$T/cat-live.tsv")" ] && ok "compared catalog lines are lines of the store's catalog ($n_sub)" || bad "compared catalog has lines the store does not ($n_sub)"
184setcat() { cp "$1" "$T/store/catalog.tsv.new" && mv "$T/store/catalog.tsv.new" "$T/store/catalog.tsv"; }
185setcat "$T/cat-base.tsv"
186# the fixtures are signed with KEY, which need not be the store's owner key: compare.py checks their
187# owner key against KEY's own fingerprint and keeps them out of the store projects' owner-key table
188export COMPARE_FIXTURES="slice-b-fixture omega-pearl pearl-alias pearl-twin no-alias $LP $LR"
189COMPARE_FIXTURE_KEY=$(ssh-keygen -lf "$KEY" | awk '{print $2}'); export COMPARE_FIXTURE_KEY
190case $COMPARE_FIXTURE_KEY in SHA256:?*) ;; *) echo "NOT_RUN: no SHA256 fingerprint of $KEY"; exit 3 ;; esac
191NCMP=$(wc -l < "$T/cat-base.tsv")
192# ---------------------------------------------------------------- builds
193mkdir -p "$T/main"
194git archive "$MAINC" | tar -x -C "$T/main"
195FORGE_SITE_REF=${FORGE_SITE_REF:-} ./run.sh chrome > /dev/null || { bad "chrome"; exit 1; }
196mkdir -p "$T/main/.build"; cp .build/chrome.om "$T/main/.build/chrome.om"
197SEDS=(-e "s|/home/drakestapleton/handoffs/radicle/RIDS.md|$T/RIDS.md|"
198 -e "s|/home/drakestapleton/.radicle/storage/|$T/radstorage/|g"
199 -e "s|^text tfzp0 \".*\"|text tfzp0 \"$T/ng/dl.log\"|"
200 -e "s|^text tfzp1 \".*\"|text tfzp1 \"$T/ng/access.log\"|"
201 -e "s|^text tfzwal \".*\"|text tfzwal \"$T/ng/wal\"|"
202 -e "s|^text tfzrad \".*\"|text tfzrad \"$T/bin/rad\"|"
203 -e "s|^text tfzspth \".*\"|text tfzspth \"$T/counts.snapshot\"|"
204 -e "s|^text tfzgent \".*\"|text tfzgent \"$T/bin/getent\"|")
205compose() { # compose DIR OUT PORT DATA [twin]: every unit of the tree in DIR (env selects the build)
206 (cd "$1" && { printf 'om2\n'; cat $(./run.sh units); }) > "$2" || return 1
207 if [ "${5:-}" = twin ]; then
208 # the real RIDS.md and the Radicle storage MAIN reads (RSTORE, the frozen copy); only the port,
209 # data and count sources move
210 sed -i -e "s|haddr4 a 2130706433 18480|haddr4 a 2130706433 $3|" -e "s|/home/drakestapleton/forge-data/|$4/|g" \
211 -e "s|/home/drakestapleton/.radicle/storage/|$RSTORE/|g" "${SEDS[@]:4}" "$2"
212 else
213 sed -i -e "s|haddr4 a 2130706433 18480|haddr4 a 2130706433 $3|" -e "s|/home/drakestapleton/forge-data/|$4/|g" "${SEDS[@]}" "$2"
214 if grep -q '2130706433 18480\|/home/drakestapleton/forge-data\|/home/drakestapleton/.radicle\|/home/drakestapleton/handoffs/radicle' "$2"; then
215 echo "compose $2: a live path or port remains"; return 1
216 fi
217 fi
218 mkdir -p "$4/logs"
219}
220build() { run "$OMC" < "$1" > "$1.bin" 2> "$1.err" && chmod 755 "$1.bin"; }
221compose "$T/main" "$T/main.om" "$PMAIN" "$T/dmain" && build "$T/main.om" || { bad "MAIN build: $(cat "$T/main.om.err" 2>/dev/null)"; exit 1; }
222compose "$ROOT" "$T/def.om" "$PDEF" "$T/ddef" && build "$T/def.om" || { bad "DEF build: $(cat "$T/def.om.err" 2>/dev/null)"; exit 1; }
223FORGE_STORE=$T/store FORGE_CLONE_BASE=$CB compose "$ROOT" "$T/store.om" "$PSTORE" "$T/dstore" && build "$T/store.om" || { bad "STORE build: $(cat "$T/store.om.err" 2>/dev/null)"; exit 1; }
224FORGE_STORE=$T/store compose "$ROOT" "$T/store0.om" "$PSTORE0" "$T/dstore0" && build "$T/store0.om" || { bad "STORE0 build: $(cat "$T/store0.om.err" 2>/dev/null)"; exit 1; }
225compose "$ROOT" "$T/twin.om" "$PTWIN" "$T/dtwin" twin && build "$T/twin.om" || { bad "TWIN build"; exit 1; }
226compose "$T/main" "$T/maintwin.om" "$PTWIN" "$T/dmaintwin" twin && build "$T/maintwin.om" || { bad "MAINTWIN build"; exit 1; }
227for b in main def store store0 twin maintwin; do echo "binary $b sha256 $(sha256sum < "$T/$b.om.bin" | cut -c1-64)"; done
228# what ./run.sh build itself makes (no test redirections): the store-reading binary holds no RIDS.md
229# path, no rad command, no node database path and no rad clone line; the default binary of the same
230# tree holds each of them. The Radicle storage path text tfstore stays in server/util.om (its
231# fkgit / fkgiti and the units that compose a historical util.om need it), so for it the check is on the
232# composed source: no line of the store-reading build uses tfstore apart from util.om's own default
233# branch of fkgit / fkgiti, which runs only while fsrcst is 0
234mkdir -p "$T/rs-store" "$T/rs-def"
235FORGE_STORE=$T/store FORGED_OUT=$T/rs-store/forged FORGED_CPUS=$CORES ./run.sh build > "$T/rs-store.log" 2>&1 || bad "run.sh build (store): $(tail -2 "$T/rs-store.log")"
236FORGED_OUT=$T/rs-def/forged FORGED_CPUS=$CORES ./run.sh build > "$T/rs-def.log" 2>&1 || bad "run.sh build (default): $(tail -2 "$T/rs-def.log")"
237echo "run.sh build: store $(sha256sum < "$T/rs-store/forged" | cut -c1-64) default $(sha256sum < "$T/rs-def/forged" | cut -c1-64)"
238for s in handoffs/radicle/RIDS.md .radicle/bin/rad node.db-wal; do
239 c=$(grep -c -a -F -- "$s" "$T/rs-store/forged"); d=$(grep -c -a -F -- "$s" "$T/rs-def/forged")
240 [ "$c" = 0 ] && [ "$d" -gt 0 ] && ok "store binary has no '$s' (default binary has $d)" || bad "store binary '$s' $c, default $d"
241done
242# the clone command 'rad clone rad:' is in neither binary since the Radicle-text removal (c1f107df; the
243# words 'rad clone' alone are a pattern server/util.om cuts out of descriptions): the store binary has none
244c=$(grep -c -a -F -- 'rad clone rad:' "$T/rs-store/forged"); [ "$c" = 0 ] && ok "store binary has no 'rad clone rad:'" || bad "store binary 'rad clone rad:' $c"
245c=$(FORGE_STORE=$T/store ./run.sh units | grep -v '^/' | grep -v '^server/util.om$' | xargs cat | grep -w tfstore | grep -c -v '^note')
246d=$(./run.sh units | grep -v '^/' | grep -v '^server/util.om$' | xargs cat | grep -w tfstore | grep -c -v '^note')
247e=$(grep -w tfstore server/util.om | grep -v '^note' | grep -c -v '^text tfstore')
248[ "$c" = 0 ] && [ "$d" -gt 0 ] && [ "$e" = 2 ] && ok "no unit of the store-reading build names tfstore (default units: $d uses); util.om uses it only in the fsrcst-0 branch of fkgit and fkgiti" || bad "tfstore uses: store units $c, default units $d, util.om $e"
249# ---------------------------------------------------------------- servers
250# the sandbox of the STORE runs: tmpfs over the Radicle storage MAIN reads (its parent folder), over
251# ~/.radicle when it still exists, and over ~/handoffs/radicle
252BW=(bwrap --die-with-parent --ro-bind / / --bind "$T" "$T" --tmpfs "$(dirname "$RSTORE")" --tmpfs "$HOME/handoffs/radicle" --dev /dev --proc /proc)
253[ -d "$HOME/.radicle" ] && BW+=(--tmpfs "$HOME/.radicle")
254waitup() { for _ in $(seq 150); do curl -s -o /dev/null "http://127.0.0.1:$1/explore" && return 0; sleep 0.2; done; return 1; }
255start() { # start NAME PORT sandbox|plain [SOCIALDIR]: the binary (or bwrap) is the background job
256 # itself, not a shell function around it, so its pid is the one stopone and cleanup kill
257 local sd=${4:-$T/soc-$1/}
258 mkdir -p "$sd"
259 if [ "$3" = sandbox ]; then
260 FORGE_SOCIAL_DIR=$sd taskset -c "$CORES" nice -n 10 "${BW[@]}" "$T/$1.om.bin" >> "$T/$1.log" 2>&1 &
261 else
262 FORGE_SOCIAL_DIR=$sd taskset -c "$CORES" nice -n 10 "$T/$1.om.bin" >> "$T/$1.log" 2>&1 &
263 fi
264 eval "PID_$1=$! PORT_$1=$2"; pids+=($!)
265 waitup "$2" || { bad "$1 did not listen on $2: $(tail -3 "$T/$1.log")"; return 1; }
266}
267stopone() { # stopone NAME: stop it and wait until its port is free
268 local v="PID_$1" w="PORT_$1"
269 kill "${!v}" 2>/dev/null; wait "${!v}" 2>/dev/null
270 for _ in $(seq 50); do ss -ltn | grep -q "127.0.0.1:${!w} " || return 0; sleep 0.1; done
271 bad "$1 still listens on ${!w} after it was stopped"
272}
273# sandbox: no Radicle storage and no RIDS.md inside, both present outside
274run "${BW[@]}" test ! -e "$RSTORE" && test ! -e "$HOME/.radicle/storage" && test -e "$RSTORE" && ok "sandbox: $RSTORE and ~/.radicle/storage absent inside, $RSTORE present outside" || bad "sandbox storage visibility"
275run "${BW[@]}" test ! -e "$HOME/handoffs/radicle/RIDS.md" && ok "sandbox: RIDS.md absent inside" || bad "sandbox RIDS.md visible"
276start twin "$PTWIN" sandbox || exit 1
277tin=$(curl -s "http://127.0.0.1:$PTWIN/explore.json" | python3 -c 'import json,sys; print(json.load(sys.stdin)["count"])')
278stopone twin
279start twin "$PTWIN" plain || exit 1
280tout=$(curl -s "http://127.0.0.1:$PTWIN/explore.json" | python3 -c 'import json,sys; print(json.load(sys.stdin)["count"])')
281stopone twin
282[ "$tin" = 0 ] && [ "$tout" -gt 0 ] && ok "a Radicle-path binary lists $tin repositories in the sandbox and $tout outside" || bad "twin in=$tin out=$tout"
283# the same in main's binary: with RIDS.md unreadable its reload traps 5 (exit 105) in freload instead of
284# serving nothing; this tree's server/main.om says 0 instead (TWIN above listened in the sandbox)
285timeout 60 taskset -c "$CORES" "${BW[@]}" "$T/maintwin.om.bin" > "$T/maintwin.log" 2>&1; rc=$?
286# measured: 4ed98366 exits 105 (trap 5 in freload); MAIN since the Radicle-text removal keeps listening
287# (timeout 124) and serves nothing; either way it never serves a repository there
288case $rc in 105|124) ok "main's binary with RIDS.md unreadable: exit $rc (105 = trap 5 in freload, 124 = still listening at the 60 s timeout); this tree's listens and serves nothing" ;; *) bad "main's binary in the sandbox exit $rc (expected 105 or 124)" ;; esac
289start main "$PMAIN" plain || exit 1
290start def "$PDEF" plain || exit 1
291start store "$PSTORE" sandbox || exit 1
292start store0 "$PSTORE0" sandbox || exit 1
293# ---------------------------------------------------------------- pages
294q() { python3 -c 'import sys, urllib.parse; print(urllib.parse.quote(sys.argv[1]))' "$1"; }
295pages=(/ /explore /explore.json)
296extra=()
297sample=$(python3 store/tests/compare.py sample "$T/cat-base.tsv" "$T/store/projects" slice-b-fixture)
298echo "sample: $(echo $sample)"
299for n in $sample; do
300 g=$T/store/projects/$n/repo.git
301 br=$(awk -F'\t' -v n="$n" '$1 == n {print $3}' "$T/cat-base.tsv")
302 r=/$OWNER/$n
303 h=$(git --git-dir="$g" rev-parse "refs/heads/$br")
304 par=$(git --git-dir="$g" rev-parse -q --verify "$h^" || true)
305 pages+=("$r" "$r.json" "$r/tree/$(q "$br")" "$r/commits" "$r/commits/$(q "$br")" "$r/commit/$h" "$r/commit/$h.patch" "$r/commit/$h.diff"
306 "$r/compare" "$r/branches" "$r/tags" "$r/archive/refs/heads/$(q "$br").zip" "$r/archive/refs/heads/$(q "$br").tar.gz")
307 [ -n "$par" ] && pages+=("$r/compare/$par...$h")
308 d=$(git --git-dir="$g" ls-tree "refs/heads/$br" | awk '$2 == "tree" {sub(/^[^\t]*\t/, ""); print; exit}')
309 [ -n "$d" ] && pages+=("$r/tree/$(q "$br")/$(q "$d")")
310 files=$(git --git-dir="$g" -c core.quotepath=false ls-tree -r --name-only "refs/heads/$br" | awk 'NR==1 || /^README/ || /\// {print}' | head -3)
311 [ "$n" = slice-b-fixture ] && files=$(git --git-dir="$g" -c core.quotepath=false ls-tree -r --name-only "refs/heads/$br")
312 while IFS= read -r f; do
313 [ -n "$f" ] || continue
314 e=$(python3 -c 'import sys, urllib.parse; print(urllib.parse.quote(sys.argv[1], safe="/"))' "$f")
315 pages+=("$r/blob/$(q "$br")/$e" "$r/raw/$(q "$br")/$e" "$r/blame/$(q "$br")/$e")
316 done <<< "$files"
317 if [ "$n" = slice-b-fixture ]; then
318 pages+=("$r/archive/refs/tags/v0.2.zip" "$r/archive/refs/tags/v0.1.tar.gz" "$r/tree/v0.2" "$r/commits/v0.1")
319 fi
320 extra+=("$r/patches" "$r/issues" "$r/releases" "$r/stargazers" "$r/search?q=a")
321done
322printf '%s\n' "${pages[@]}" > "$T/pages.txt"
323# /status, /status.json and /trending are left out: they print the time of the request (the snapshot's
324# age in seconds, the trending window's ends)
325printf '%s\n' /drakestapleton /search?q=omega "${extra[@]}" > "$T/pages-extra.txt"
326fetch() { # fetch PORT DIR LISTFILE: every page as HTML/raw and with Accept: application/json
327 mkdir -p "$2"
328 python3 store/tests/compare.py fetch "$1" "$2" "$3"
329}
330fetch "$PMAIN" "$T/out/main" "$T/pages.txt"
331fetch "$PSTORE" "$T/out/store" "$T/pages.txt"
332fetch "$PDEF" "$T/out/def" "$T/pages.txt"
333fetch "$PMAIN" "$T/out/main-x" "$T/pages-extra.txt"
334fetch "$PDEF" "$T/out/def-x" "$T/pages-extra.txt"
335fetch "$PSTORE0" "$T/out/store0" "$T/pages.txt"
336if python3 store/tests/compare.py same "$T/out/main" "$T/out/def" > "$T/main-def.txt"; then ok "DEF = MAIN byte for byte: $(tail -1 "$T/main-def.txt")"; else bad "DEF differs from MAIN: $(head -5 "$T/main-def.txt")"; fi
337if python3 store/tests/compare.py same "$T/out/main-x" "$T/out/def-x" > "$T/main-def-x.txt"; then ok "DEF = MAIN on the other pages: $(tail -1 "$T/main-def-x.txt")"; else bad "DEF differs from MAIN (other pages): $(head -5 "$T/main-def-x.txt")"; fi
338if python3 store/tests/compare.py radicle "$T/out/main" "$T/out/store" > "$T/main-store.txt"; then ok "STORE = MAIN apart from lines that name Radicle: $(tail -1 "$T/main-store.txt")"; else bad "STORE differs from MAIN beyond Radicle lines: $(grep -m5 '^BAD' "$T/main-store.txt")"; fi
339cp "$T/main-store.txt" "${STORE_TEST_DIFF:-/dev/null}" 2>/dev/null || true
340# the clone panel (its line starts <div class="clone">) never has a rad clone line, and the agent line
341# of dl/dlclone.om (forge-contribute, a Radicle patch) is not there; repository files that mention
342# rad clone (READMEs, blame) are content, not the panel
343c=$(grep -h -a '^<div class="clone">' -r "$T/out/store" "$T/out/store0" | grep -c -F 'rad clone'); d=$(grep -l -a -F 'One command for agents' -r "$T/out/store" "$T/out/store0" | wc -l); e=$(grep -h -a '^<div class="clone">' -r "$T/out/main" | grep -c -F 'rad clone')
344# (MAIN shows no rad clone line either since the Radicle-text removal; its count is printed)
345[ "$c" = 0 ] && [ "$d" = 0 ] && ok "no store clone panel has a rad clone line or the agent line (MAIN panels with rad clone: $e)" || bad "store clone panels with rad clone $c, agent lines $d, MAIN panels $e"
346c=$(grep -c -a -F "git clone ${CB}projects/slice-b-fixture/repo.git</code>" "$T/out/store/$(python3 store/tests/compare.py key "/$OWNER/slice-b-fixture" html)"); [ "$c" = 1 ] && ok "STORE clone panel: git clone ${CB}projects/slice-b-fixture/repo.git" || bad "STORE clone line count $c"
347c=$(grep -l -a -F 'Git over HTTPS' -r "$T/out/store0" | wc -l); d=$(grep -l -a -F 'Git over HTTPS' -r "$T/out/store" | wc -l); [ "$c" = 0 ] && [ "$d" -gt 0 ] && ok "STORE0 (no clone base) shows no HTTPS line; STORE shows it on $d pages" || bad "HTTPS line: store0 $c store $d"
348c=$(grep -c -a -F '"clone":{"rad":null,"rad_clone":null,"git_https":null}' "$T/out/store0/$(python3 store/tests/compare.py key "/$OWNER/slice-b-fixture.json" html)"); [ "$c" = 1 ] && ok "STORE0 JSON clone object: rad, rad_clone and git_https null" || bad "STORE0 JSON clone object ($c)"
349c=$(grep -c -a -F "\"clone\":{\"rad\":null,\"rad_clone\":null,\"git_https\":\"${CB}projects/slice-b-fixture/repo.git\"}" "$T/out/store/$(python3 store/tests/compare.py key "/$OWNER/slice-b-fixture.json" html)"); [ "$c" = 1 ] && ok "STORE JSON clone object: git_https ${CB}projects/slice-b-fixture/repo.git" || bad "STORE JSON clone object ($c)"
350# ---------------------------------------------------------------- negative controls (STORE, live reloads)
351U=http://127.0.0.1:$PSTORE
352st() { curl -s -o /dev/null -w '%{http_code}' "$U$1"; }
353excount() { curl -s "$U/explore.json" | python3 -c 'import json,sys; print(json.load(sys.stdin)["count"])'; }
354# reload: forged checks the catalog's inode, size and mtime between connections; wait for the
355# expected project count, and say how many reload lines the log gained
356reloadto() { # reloadto CATFILE WANTCOUNT
357 local before; before=$(grep -c '^forged: reloaded' "$T/store.log")
358 setcat "$1"
359 for _ in $(seq 100); do
360 curl -s -o /dev/null "$U/explore"
361 [ "$(grep -c '^forged: reloaded' "$T/store.log")" -gt "$before" ] && [ "$(excount)" = "$2" ] && return 0
362 sleep 0.2
363 done
364 return 1
365}
366# every repository URL of project N under its catalog branch (main when the catalog does not list
367# it): home, JSON, tree, blob, raw, commits, branches, tags, archive; allst adds /rad:<ALIAS>
368urls() {
369 local r=/$OWNER/$1 br f
370 br=$(awk -F'\t' -v n="$1" '$1 == n {print $3}' "$T/store/catalog.tsv"); br=${br:-main}
371 f=$(git --git-dir="$T/store/projects/$1/repo.git" ls-tree --name-only "refs/heads/$br" 2>/dev/null | head -1); f=${f:-README.md}
372 br=$(q "$br"); f=$(q "$f")
373 echo "$r $r.json $r/tree/$br $r/blob/$br/$f $r/raw/$br/$f $r/commits $r/branches $r/tags $r/archive/refs/heads/$br.zip"
374}
375allst() { local s=""; for u in $(urls "$1"); do s="$s$(st "$u") "; done; [ -n "${2:-}" ] && s="$s$(st "/rad:$2")"; echo "$s"; }
376listed() { curl -s "$U/explore.json" | python3 -c 'import json,sys; print(int(any(r["name"]==sys.argv[1] for r in json.load(sys.stdin)["repos"])))' "$1"; }
377ctl() { # ctl NAME CATFILE WANTCOUNT PROJECT WANT(404|200) [ALIAS]: one control row
378 if ! reloadto "$2" "$3"; then inval "$1: the store did not reload to $3 projects (setup)"; return 1; fi
379 local s; s=$(allst "$4" "${6:-}")
380 local want=$5; local l; l=$(listed "$4")
381 if [ "$want" = 404 ]; then
382 case "$s" in *[1235]0[0-9]*) bad "$1: $4 answered [$s] listed=$l"; return 1 ;; esac
383 [ "$l" = 0 ] || { bad "$1: $4 listed on explore"; return 1; }
384 else
385 case "$s" in *404*|*500*) bad "$1: twin $4 answered [$s]"; return 1 ;; esac
386 [ "$l" = 1 ] || { bad "$1: twin $4 not listed"; return 1; }
387 fi
388 ok "$1: $4 [$s] listed=$l"
389}
390FXA=slice-b-fixture
391grep -v -P "^$FXA\t" "$T/cat-base.tsv" > "$T/c-nofx.tsv"
392fxl=$(fxline $FXA)
393B=$NCMP; B1=$((NCMP - 1))
394printf '%s\n' "${fxl%public}private" > "$T/fxpriv"; cat "$T/c-nofx.tsv" "$T/fxpriv" > "$T/c-priv.tsv"
395ctl "C1 private line" "$T/c-priv.tsv" "$B1" $FXA 404 $FXRID
396ctl "C1 twin: the same line public" "$T/cat-base.tsv" "$B" $FXA 200 $FXRID
397ctl "C2 project in the folder, not in the catalog" "$T/cat-base.tsv" "$B" "$EXTRA" 404
398{ cat "$T/cat-base.tsv"; printf '%s\n' "$EXTRALINE"; } > "$T/c-extra.tsv"
399ctl "C2 twin: its line added" "$T/c-extra.tsv" $((B + 1)) "$EXTRA" 200
400# C3: a symlinked project folder and a symlinked repo.git (each points at a real project made by ipl)
401{ cat "$T/cat-base.tsv"; fxline "$LP"; } > "$T/c-lp.tsv"
402{ cat "$T/cat-base.tsv"; fxline "$LR"; } > "$T/c-lr.tsv"
403ctl "C3a symlinked project folder" "$T/c-lp.tsv" "$B" "$LP" 404 zSliceBLinkProjectAAAAA1
404grep -q "project $LP left out (project folder is a link or not a folder)" "$T/store.log" && ok "C3a stderr names the rule" || bad "C3a stderr"
405rm "$T/store/projects/$LP"; mv "$T/store/projects/.lp-real" "$T/store/projects/$LP"
406ctl "C3a twin: the same project in a real folder" "$T/c-lp.tsv" $((B + 1)) "$LP" 200 zSliceBLinkProjectAAAAA1
407mv "$T/store/projects/$LP" "$T/store/projects/.lp-real"; ln -s "$T/store/projects/.lp-real" "$T/store/projects/$LP"
408ctl "C3b symlinked repo.git" "$T/c-lr.tsv" "$B" "$LR" 404 zSliceBLinkRepoAAAAAAAA1
409grep -q "project $LR left out (repo.git is a link or not a folder)" "$T/store.log" && ok "C3b stderr names the rule" || bad "C3b stderr"
410rm "$T/store/projects/$LR/repo.git"; mv "$T/store/projects/$LR/.repo-real.git" "$T/store/projects/$LR/repo.git"
411ctl "C3b twin: repo.git a real folder" "$T/c-lr.tsv" $((B + 1)) "$LR" 200 zSliceBLinkRepoAAAAAAAA1
412mv "$T/store/projects/$LR/repo.git" "$T/store/projects/$LR/.repo-real.git"; ln -s "$T/store/projects/$LR/.repo-real.git" "$T/store/projects/$LR/repo.git"
413# C4: malformed catalogs fail closed; each twin is the well-formed catalog it came from
414malformed() { # malformed NAME FILE REASON
415 if ! reloadto "$2" 0; then bad "$1: the store still serves projects"; return; fi
416 local s; s=$(allst $FXA $FXRID)
417 case "$s" in *[1235]0[0-9]*) bad "$1: $FXA answered [$s]"; return ;; esac
418 grep -q "forged: catalog refused ($3" "$T/store.log" && ok "$1: no repositories [$s], stderr says $3" || bad "$1: stderr lacks '$3'"
419 ctl "$1 twin: the well-formed catalog" "$T/cat-base.tsv" "$B" $FXA 200 $FXRID
420}
421awk -F'\t' -v OFS='\t' 'NR==2 {$6="extra"} {print}' "$T/cat-base.tsv" > "$T/m-fields6.tsv"
422awk -F'\t' -v OFS='\t' 'NR==2 {NF=4} {print}' "$T/cat-base.tsv" > "$T/m-fields4.tsv"
423{ cat "$T/cat-base.tsv"; sed -n 1p "$T/cat-base.tsv"; } > "$T/m-dupline.tsv"
424l1=$(sed -n 1p "$T/cat-base.tsv"); n1=${l1%%$'\t'*}
425{ cat "$T/cat-base.tsv"; fxline "$LP" | awk -F'\t' -v OFS='\t' -v n="$n1" '{$1=n; print}'; } > "$T/m-dupname.tsv"
426{ cat "$T/cat-base.tsv"; fxline "$LP" | awk -F'\t' -v OFS='\t' -v n="${n1^^}" '{$1=n; print}'; } > "$T/m-dupcase.tsv"
427{ cat "$T/cat-base.tsv"; printf '%s\n' "$l1" | awk -F'\t' -v OFS='\t' '{$1="dup-id-other"; print}'; } > "$T/m-dupid.tsv"
428awk -F'\t' -v OFS='\t' 'NR==2 {$4="12345"} {print}' "$T/cat-base.tsv" > "$T/m-badhead.tsv"
429awk -F'\t' -v OFS='\t' 'NR==2 {$4=toupper($4)} {print}' "$T/cat-base.tsv" > "$T/m-headcase.tsv"
430head -c -1 "$T/cat-base.tsv" > "$T/m-nolf.tsv"
431awk -F'\t' -v OFS='\t' 'NR==2 {$5="public\r"} {print}' "$T/cat-base.tsv" > "$T/m-cr.tsv"
432awk -F'\t' -v OFS='\t' 'NR==2 {$1=$1 "\001"} {print}' "$T/cat-base.tsv" > "$T/m-ctl.tsv"
433awk -F'\t' -v OFS='\t' 'NR==2 {$5="Public"} {print}' "$T/cat-base.tsv" > "$T/m-vis.tsv"
434awk -F'\t' -v OFS='\t' 'NR==2 {$1="-bad"} {print}' "$T/cat-base.tsv" > "$T/m-name.tsv"
435awk -F'\t' -v OFS='\t' 'NR==2 {$3="a..b"} {print}' "$T/cat-base.tsv" > "$T/m-branch.tsv"
436awk -F'\t' -v OFS='\t' 'NR==2 {$2=substr($2,2)} {print}' "$T/cat-base.tsv" > "$T/m-id.tsv"
437{ cat "$T/cat-base.tsv"; echo; } > "$T/m-empty.tsv"
438malformed "C4a six fields" "$T/m-fields6.tsv" "not five tab-separated fields at line 2"
439malformed "C4b four fields" "$T/m-fields4.tsv" "not five tab-separated fields at line 2"
440malformed "C4c duplicate line" "$T/m-dupline.tsv" "two equal names at line $((B + 1))"
441malformed "C4d duplicate name" "$T/m-dupname.tsv" "two equal names at line $((B + 1))"
442malformed "C4e names that differ only in case" "$T/m-dupcase.tsv" "two names that differ only in case at line $((B + 1))"
443malformed "C4f duplicate id" "$T/m-dupid.tsv" "two equal ids at line $((B + 1))"
444malformed "C4g bad head" "$T/m-badhead.tsv" "head is not 40 lowercase hex digits or none at line 2"
445malformed "C4h upper-case head" "$T/m-headcase.tsv" "head is not 40 lowercase hex digits or none at line 2"
446malformed "C4i missing final line feed" "$T/m-nolf.tsv" "no final line feed"
447malformed "C4j carriage return" "$T/m-cr.tsv" "control byte at line 2"
448malformed "C4k control byte in a name" "$T/m-ctl.tsv" "control byte at line 2"
449malformed "C4l visibility Public" "$T/m-vis.tsv" "visibility is not public or private at line 2"
450malformed "C4m name rule" "$T/m-name.tsv" "name outside the name rule at line 2"
451malformed "C4n branch rule" "$T/m-branch.tsv" "branch outside the branch rule at line 2"
452malformed "C4o id of 63 digits" "$T/m-id.tsv" "id is not 64 lowercase hex digits at line 2"
453malformed "C4p empty line" "$T/m-empty.tsv" "not five tab-separated fields at line $((B + 1))"
454# unreadable catalog: a link, then absent
455ln -s "$T/cat-base.tsv" "$T/store/catalog.tsv.lnk"; mv "$T/store/catalog.tsv.lnk" "$T/store/catalog.tsv"
456for _ in $(seq 50); do curl -s -o /dev/null "$U/explore"; [ "$(excount)" = 0 ] && break; sleep 0.2; done
457[ "$(excount)" = 0 ] && grep -q "forged: catalog refused (cannot be read or is a link)" "$T/store.log" && ok "C4q catalog.tsv a link: no repositories" || bad "C4q catalog link"
458ctl "C4q twin: a regular catalog" "$T/cat-base.tsv" "$B" $FXA 200 $FXRID
459# more public lines than the old 64-row table: the well-formed catalog plus 65 more public lines. The
460# table holds FAMAX (256) rows and nothing past it refuses the whole catalog any more (2026-11-14): the
461# fixture is still served, the 65 lines (no project folder) are each left out alone
462python3 store/tests/compare.py manylines "$T/cat-base.tsv" 65 > "$T/m-65.tsv"
463cat "$T/cat-base.tsv" "$T/m-65.tsv" > "$T/c-65.tsv"
464ctl "C4r 65 public lines more than the well-formed catalog: no refusal, the fixture still served" "$T/c-65.tsv" "$B" $FXA 200 $FXRID
465grep -q "forged: catalog refused (more public" "$T/store.log" && bad "C4r stderr still has a whole-catalog refusal for too many lines" || ok "C4r no whole-catalog refusal for too many lines"
466# C5: a head the catalog names that repo.git does not have, and a head that is not the branch tip
467fxh=$(printf '%s' "$fxl" | cut -f4); fxp=$(git --git-dir="$T/store/projects/$FXA/repo.git" rev-parse "$fxh^")
468printf '%s\n' "$fxl" | awk -F'\t' -v OFS='\t' '{$4="0123456789abcdef0123456789abcdef01234567"; print}' > "$T/fxh"; cat "$T/c-nofx.tsv" "$T/fxh" > "$T/c-head.tsv"
469printf '%s\n' "$fxl" | awk -F'\t' -v OFS='\t' -v h="$fxp" '{$4=h; print}' > "$T/fxp"; cat "$T/c-nofx.tsv" "$T/fxp" > "$T/c-head2.tsv"
470ctl "C5a head repo.git does not have" "$T/c-head.tsv" "$B1" $FXA 404 $FXRID
471ctl "C5a twin" "$T/cat-base.tsv" "$B" $FXA 200 $FXRID
472ctl "C5b head that is not the branch tip" "$T/c-head2.tsv" "$B1" $FXA 404 $FXRID
473ctl "C5b twin" "$T/cat-base.tsv" "$B" $FXA 200 $FXRID
474# C6: the deny list by name (omega-pearl) and by the withdrawn RID (pearl-alias); twin pearl-twin
475{ cat "$T/cat-base.tsv"; fxline omega-pearl; fxline pearl-alias; fxline pearl-twin; } > "$T/c-deny.tsv"
476ctl "C6a deny list by name" "$T/c-deny.tsv" $((B + 1)) omega-pearl 404 zSliceBDenyByNameAAAAAA1
477ctl "C6b deny list by id (alias rad:z2ft64...)" "$T/c-deny.tsv" $((B + 1)) pearl-alias 404 z2ft64NFLsKzWttCXw6NWNbRQLggQ
478ctl "C6 twin: the same fixture, another name and id" "$T/c-deny.tsv" $((B + 1)) pearl-twin 200 zSliceBDenyTwinAAAAAAAAA1
479# C7: record 1 that no longer hashes to the catalog id (a replaced copy, not the hard link), seen
480# after the reload flag (the existing reload signal; the catalog itself does not change)
481r1=$T/store/projects/pearl-twin/records/1
482cp "$r1" "$T/r1.keep"; { cat "$T/r1.keep"; } | sed 's/^nonce \(.\)/nonce 0/' > "$T/r1.new"
483cmp -s "$T/r1.new" "$T/r1.keep" && sed -i 's/^nonce \(.\)/nonce 1/' "$T/r1.new"
484rm "$r1"; cp "$T/r1.new" "$r1"
485before=$(grep -c '^forged: reloaded' "$T/store.log"); : > "$T/dstore/reload"
486for _ in $(seq 100); do curl -s -o /dev/null "$U/explore"; [ "$(grep -c '^forged: reloaded' "$T/store.log")" -gt "$before" ] && break; sleep 0.2; done
487s=$(allst pearl-twin)
488case "$s" in *[1235]0[0-9]*) bad "C7 tampered record 1 still served [$s]" ;; *) grep -q "project pearl-twin left out (records/1 does not hash to the catalog id)" "$T/store.log" && ok "C7 tampered record 1: pearl-twin [$s], stderr names the rule (reload flag)" || bad "C7 stderr" ;; esac
489rm "$r1"; cp "$T/r1.keep" "$r1"; : > "$T/dstore/reload"
490for _ in $(seq 100); do curl -s -o /dev/null "$U/explore"; [ "$(listed pearl-twin)" = 1 ] && break; sleep 0.2; done
491[ "$(listed pearl-twin)" = 1 ] && ok "C7 twin: the original record 1 is served again after the reload flag" || bad "C7 twin"
492# C8: old links and a project without an old id
493reloadto "$T/c-deny.tsv" $((B + 1)) || inval "C8 setup"
494for n in $(cut -f1 "$T/cat-live.tsv" | head -3) $FXA; do
495 a=$(sed -n 's/^alias rad://p' "$T/store/projects/$n/records/1")
496 lm=$(curl -s -o /dev/null -w '%{http_code} %{redirect_url}' "http://127.0.0.1:$PMAIN/rad:$a/tree/main")
497 ls=$(curl -s -o /dev/null -w '%{http_code} %{redirect_url}' "$U/rad:$a/tree/main")
498 lm=${lm//$PMAIN/P}; ls=${ls//$PSTORE/P}
499 [ "$lm" = "$ls" ] && [ "${ls%% *}" = 302 ] && ok "C8 /rad:$a/tree/main answers as MAIN: $ls" || bad "C8 /rad:$a main [$lm] store [$ls]"
500done
501{ cat "$T/c-deny.tsv"; fxline no-alias; } > "$T/c-noal.tsv"
502ctl "C8 project without an old id: served under its git:<id> (every public line is served)" "$T/c-noal.tsv" $((B + 2)) no-alias 200
503w=$(python3 store/tests/expect_served.py --count "$T/store"); [ "$(excount)" = "$w" ] && ok "C8 explore.json count $w = the catalog's public lines less the deny list (expect_served.py)" || bad "C8 explore count $(excount), expect_served.py $w"
504gid=$(fxline no-alias | cut -f2)
505grep -q "forged: project no-alias left out" "$T/store.log" && bad "C8 stderr: no-alias left out" || ok "C8 stderr: no line leaves no-alias out"
506c=$(curl -s "$U/$OWNER/no-alias.json" | grep -c -F "\"rid\":\"git:$gid\""); [ "$c" = 1 ] && ok "C8 no-alias.json names rid git:<its id>" || bad "C8 no-alias.json rid (count $c)"
507s=$(st "/rad:$gid"); [ "$s" = 404 ] && ok "C8 /rad:<git id> is not a link (404)" || bad "C8 /rad:<git id> answered $s"
508# C9: star targets already in the social log (written by MAIN as rad:<RID>) resolve in STORE and
509# survive a restart; a star written by STORE on a project without an old id (no-alias, git:<id>)
510# too
511stargz() { python3 store/tests/compare.py stars "$1" "$2"; }
512ssh-keygen -q -t ed25519 -N '' -C 'throwaway social key, store/tests/compare.sh' -f "$T/k1"
513L1=$(sed -n 1p "$T/cat-live.tsv" | cut -f1); L2=$(sed -n 2p "$T/cat-live.tsv" | cut -f1)
514SM=$(python3 store/tests/compare.py signin "$PMAIN" "$T/k1")
515case "$SM" in *SIGNIN-FAILED*) inval "C9 setup: sign-in on MAIN: $SM" ;; esac
516python3 store/tests/compare.py star "$PMAIN" "$SM" "$L1" > /dev/null
517python3 store/tests/compare.py star "$PMAIN" "$SM" "$FXA" > /dev/null
518[ "$(stargz "$PMAIN" "$L1") $(stargz "$PMAIN" "$FXA")" = "1 1" ] && ok "C9 setup: MAIN wrote two stars (rad:<RID> targets)" || inval "C9 setup: MAIN stars $(stargz "$PMAIN" "$L1") $(stargz "$PMAIN" "$FXA")"
519grep -c -F "rad:${FXRID}" "$T/soc-main/social.log" > /dev/null && ok "C9 MAIN's log names rad:$FXRID" || bad "C9 MAIN log lacks rad:$FXRID"
520stopone store; rm -rf "$T/soc-store"; cp -a "$T/soc-main" "$T/soc-store"
521start store "$PSTORE" sandbox || exit 1
522reloadto "$T/c-noal.tsv" $((B + 2)) || inval "C9 setup: store reload"
523s="$(stargz "$PSTORE" "$L1") $(stargz "$PSTORE" "$FXA") $(stargz "$PSTORE" "$L2")"
524[ "$s" = "1 1 0" ] && ok "C9 STORE resolves the stars MAIN logged: $L1 1, $FXA 1, twin $L2 0" || bad "C9 STORE stars [$s] want [1 1 0]"
525SS=$(python3 store/tests/compare.py signin "$PSTORE" "$T/k1")
526case "$SS" in *SIGNIN-FAILED*) inval "C9 setup: sign-in on STORE: $SS" ;; esac
527python3 store/tests/compare.py star "$PSTORE" "$SS" no-alias > /dev/null
528s="$(stargz "$PSTORE" no-alias) $(stargz "$PSTORE" pearl-twin)"
529[ "$s" = "1 0" ] && ok "C9 STORE stars no-alias (git:<id>): no-alias 1, twin pearl-twin 0" || bad "C9 no-alias star [$s] want [1 0]"
530stopone store; start store "$PSTORE" sandbox || exit 1
531reloadto "$T/c-noal.tsv" $((B + 2)) || inval "C9 setup: store restart"
532s="$(stargz "$PSTORE" "$L1") $(stargz "$PSTORE" "$FXA") $(stargz "$PSTORE" no-alias)"
533[ "$s" = "1 1 1" ] && ok "C9 after a restart the log replays: $L1 1, $FXA 1, no-alias 1" || bad "C9 after restart [$s]"
534setcat "$T/cat-base.tsv"
535# ---------------------------------------------------------------- mutants
536# each mutant: the STORE units with one decision changed, built and started in the sandbox on PMUT;
537# its fresh unmutated baseline must pass the control first (setup failure = INVALID, not caught)
538mutant() { # mutant NAME SEDEXPR TARGETLINE CONTROLFN [APPENDFILE]
539 local m=$T/mut-$1.om
540 cp "$T/store.om" "$m"
541 [ "$(grep -c -x -F -- "$3" "$m")" = 1 ] || { inval "mutant $1: target line not found once"; return; }
542 sed -i -e "s|haddr4 a 2130706433 $PSTORE|haddr4 a 2130706433 $PMUT|" -e "s|$T/dstore/|$T/dmut/|g" -e "$2" "$m"
543 grep -q -x -F -- "$3" "$m" && { inval "mutant $1: sed did not change the target"; return; }
544 [ -n "${5:-}" ] && cat "$5" >> "$m"
545 if ! run "$OMC" < "$m" > "$m.bin" 2> "$m.err"; then inval "mutant $1 did not compile: $(cat "$m.err")"; return; fi
546 chmod 755 "$m.bin"
547 mkdir -p "$T/dmut/logs"
548 "$4" "$1"
549}
550# control functions: each starts the mutant, sets the catalog, and returns via pass/fail counters
551mctl() { # mctl MUTANT CATFILE PROJECT: caught when PROJECT is served (200 on its home)
552 FORGE_SOCIAL_DIR=$T/soc-mut/ taskset -c "$CORES" nice -n 10 "${BW[@]}" "$T/mut-$1.om.bin" > "$T/mut-$1.log" 2>&1 &
553 eval "PID_mut=$! PORT_mut=$PMUT"; pids+=($!)
554 if ! waitup "$PMUT"; then inval "mutant $1 did not listen: $(tail -2 "$T/mut-$1.log")"; stopone mut; return; fi
555 # a mutant that no longer serves the well-formed catalog (the fixture's home 200) is INVALID, not caught
556 setcat "$T/cat-base.tsv"; local s=404
557 for _ in $(seq 50); do curl -s -o /dev/null "http://127.0.0.1:$PMUT/explore"; s=$(curl -s -o /dev/null -w '%{http_code}' "http://127.0.0.1:$PMUT/$OWNER/$FXA"); [ "$s" = 200 ] && break; sleep 0.2; done
558 if [ "$s" != 200 ]; then inval "mutant $1 does not serve the well-formed catalog ($FXA answered $s)"; stopone mut; return; fi
559 setcat "$2"; s=404
560 for _ in $(seq 50); do curl -s -o /dev/null "http://127.0.0.1:$PMUT/explore"; s=$(curl -s -o /dev/null -w '%{http_code}' "http://127.0.0.1:$PMUT/$OWNER/$3"); [ "$s" = 200 ] && break; sleep 0.2; done
561 stopone mut; setcat "$T/cat-base.tsv"
562 [ "$s" = 200 ] && ok "mutant $1 caught: it serves $3 (200), the unmutated build answers 404" || bad "mutant $1 survived: $3 answered $s"
563}
564m_private() { mctl "$1" "$T/c-priv.tsv" $FXA; }
565m_scan() { mctl "$1" "$T/cat-base.tsv" "$EXTRA"; }
566m_link() { mctl "$1" "$T/c-lr.tsv" "$LR"; }
567m_deny() { mctl "$1" "$T/c-deny.tsv" omega-pearl; }
568m_head() { mctl "$1" "$T/c-head.tsv" $FXA; }
569m_dup() { mctl "$1" "$T/m-dupname.tsv" $FXA; }
570m_nolf() { mctl "$1" "$T/m-nolf.tsv" $FXA; }
571# fresh baselines: the unmutated STORE refuses each of these (rows above), checked again here
572for c in "$T/c-priv.tsv:$FXA" "$T/cat-base.tsv:$EXTRA" "$T/c-lr.tsv:$LR" "$T/c-deny.tsv:omega-pearl" "$T/c-head.tsv:$FXA" "$T/m-dupname.tsv:$FXA" "$T/m-nolf.tsv:$FXA"; do
573 f=${c%%:*}; n=${c#*:}; setcat "$f"
574 for _ in $(seq 30); do curl -s -o /dev/null "$U/explore"; sleep 0.1; done
575 s=$(st "/$OWNER/$n"); [ "$s" = 404 ] && ok "baseline: unmutated STORE answers 404 for $n under $(basename "$f")" || bad "baseline $n under $(basename "$f") answered $s"
576done
577setcat "$T/cat-base.tsv"
578mutant private 's/^ret xstxeq s4 e tfspub$/ret true/' 'ret xstxeq s4 e tfspub' m_private
579mutant scan 's/^n = xscatrd$/n = xscatsc/' 'n = xscatrd' m_scan store/tests/mutant-scan.om
580mutant link 's/^r = lstat fpth 0 get fpthl 0 fstb 0 128$/r = stat fpth 0 get fpthl 0 fstb 0 128/' 'r = lstat fpth 0 get fpthl 0 fstb 0 128' m_link
581mutant deny 's/^if fdeny k$/if false/' 'if fdeny k' m_deny
582mutant head 's/^if not xsheadok k$/if false/' 'if not xsheadok k' m_head
583mutant dup 's/^r = xsdup p e$/r = ulong 0/' 'r = xsdup p e' m_dup
584mutant nolf 's/^if and gt ln 0 ne get fxo sub ln 1 10$/if false/' 'if and gt ln 0 ne get fxo sub ln 1 10' m_nolf
585echo "STORE stderr: $(grep -a -o 'forged: catalog refused ([^)]*)' "$T/store.log" | wc -l) catalog refusals, $(grep -a -o 'forged: project [^ ]* left out' "$T/store.log" | wc -l) projects left out, $(grep -a -o 'forged: reloaded' "$T/store.log" | wc -l) reloads"
586[ -n "${KEEP:-}" ] && echo "kept $T"
587echo "RESULT pass=$pass fail=$fail invalid=$invalid"
588[ "$fail" = 0 ] && [ "$invalid" = 0 ]