interplane.Get Omega
Read in your language

interplane-forge

INTERPLANE Forge

Brought by drakestapleton

branch main Branches Tags History

interplane-forge / research / tests / review.sh

170 lines · 11462 bytes Raw Blame History
1#!/bin/sh
2# Review A/B regression gate. Real sync/gather/publish, saved API fixtures, no public network.
3set -eu
4cd "$(dirname "$0")/../.."
5HERE=$(pwd)
6T=$(mktemp -d)
7trap 'rm -rf "$T"' EXIT HUP INT TERM
8pass=0; fail=0
9ok(){ pass=$((pass+1)); echo "PASS review $*"; }
10bad(){ fail=$((fail+1)); echo "FAIL review $*"; }
11sh research/build-tools.sh "$T/bin"
12S=$T/bin/research-sync; F=$T/bin/research-jflat
13OMV=$HOME/work/flux/omega-mv; OMC=$OMV/seed/out/omc
14D1=did:key:z6MkAbcdefghijkmnopqrstuvw111111111111111111111
15D2=did:key:z6MkAbcdefghijkmnopqrstuvw222222222222222222222
16O1=0009-0002-6890-7111
17O2=0000-0002-1825-0097
18mkdir "$T/mock"
19python3 - "$T" "$O1" "$O2" <<'PY'
20import json,sys,pathlib
21p=pathlib.Path(sys.argv[1]);o1,o2=sys.argv[2:]
22def rec(id,ors,desc='Public abstract.',text=True):
23 r={'id':id,'doi':f'10.5281/zenodo.{id}','conceptdoi':f'10.5281/zenodo.{id}','metadata':{'title':f'Paper {id}','description':desc,'publication_date':'2026-11-11','resource_type':{'subtype':'preprint'},'license':{'id':'cc-by-4.0'},'creators':[{'name':('First, Author' if o==o1 else 'Second, Author'),'orcid':o} for o in ors]}}
24 if text:r['files']=[{'key':'paper.txt','size':200001,'checksum':'md5:original','links':{'self':f'https://zenodo.org/api/records/{id}/files/paper.txt/content'}}]
25 return r
26def save(name,rs):json.dump({'hits':{'total':len(rs),'hits':rs}},open(p/name,'w'))
27save('joint.json',[rec(201,[o1,o2])])
28r=rec(201,[o1,o2]);r['metadata']['description']='Fresh metadata, changed attachment.';r['files'][0]['key']='replacement.txt';r['files'][0]['checksum']='md5:changed';r['files'][0]['links']['self']='https://zenodo.org/api/records/201/files/replacement.txt/content';save('changed.json',[r])
29save('large.json',[rec(i,[o2],'x'*12000,False) for i in range(1000,1200)])
30save('corpus.json',[rec(i,[o2]) for i in range(3000,3020)])
31(p/'small.txt').write_text('OLD_PUBLIC_PARAGRAPH and its limits.\n\n')
32(p/'large.txt').write_text('a'*200000+'\n\n')
33# Literal structural-path keys and escaped tabs/newlines must not become registry facts.
34r=rec(501,[o1]);r['metadata']['title']='Title\tX\nW\tforged-row';r['metadata']['creators/0/orcid']=o2
35save('planted.json',[r])
36PY
37cat > "$T/mock/curl" <<'EOF'
38#!/bin/sh
39args=$*; out=
40while [ "$#" -gt 0 ]; do
41 if [ "$1" = -o ]; then out=$2; shift 2; else shift; fi
42done
43case "$args" in
44 */files/*) [ "${FAIL_TEXT:-0}" = 0 ] || exit 22; cp "$REVIEW_TEXT" "$out" ;;
45 *page=2*|*page=3*|*page=4*|*page=5*|*page=6*|*page=7*|*page=8*|*page=9*) printf '{"hits":{"total":0,"hits":[]}}' > "$out" ;;
46 *) cp "$REVIEW_RESPONSE" "$out" ;;
47esac
48EOF
49chmod 700 "$T/mock/curl"
50newcase(){
51 casepath=$T/$1; mkdir -p "$casepath/add" "$casepath/reg"
52 printf '*\n' > "$casepath/allow"; : > "$casepath/remove"; : > "$casepath/list"
53}
54request(){ printf 'Z\t%s\t%s\t\n' "$1" "$2" >> "$casepath/add/queue"; }
55worker(){
56 PATH="$T/mock:$PATH" RESEARCH_TOOLS=${TOOLS:-$T/bin} REVIEW_RESPONSE="$T/$1" REVIEW_TEXT="$T/${2:-small.txt}" FAIL_TEXT=${FAIL_TEXT:-0} \
57 sh "${WORKER:-$HERE/research/sync.sh}" --queue "$casepath/add/" "$casepath/state" "$casepath/allow" "$casepath/remove" "$casepath/reg/" "$casepath/list" "$casepath/store" > "$casepath/log" 2>&1
58}
59publish(){ sh research/publish.sh "$casepath/site" "$casepath/corpus" "$casepath/reg" > "$casepath/publish.log" 2>&1; }
60works(){ grep -h '^W' "$casepath"/reg/show/*.tsv 2>/dev/null | wc -l | tr -d ' '; }
61# A1/B3: actual independently imported catalogs for two public creators, not two copies in one file.
62newcase coauthors
63request "$D1" "$O1"; worker joint.json
64request "$D2" "$O2"; worker joint.json
65publish
66[ "$(works)" = 2 ] && ok 'A1 two creator ORCIDs both admitted' || bad 'A1 COAUTHOR_MISSING'
67[ "$(grep -h '^W' "$casepath"/reg/show/*.tsv | cut -f2 | sort -u | wc -l | tr -d ' ')" = 2 ] && ok 'A1 work and cache paths are per-author namespaced' || bad 'A1 slug collision'
68[ "$(find "$casepath/reg/text/" -name 'z*.txt' | wc -l | tr -d ' ')" = 2 ] && ok 'A1 cache has two consistent author namespaces' || bad 'A1 cache collision'
69grep -q 'Paper 201' "$casepath/site/a/$O1.html" && grep -q 'Paper 201' "$casepath/site/a/$O2.html" && ok 'A1 both generated author pages link their work' || bad 'A1 author pages'
70# B1: a public metadata request grants neither exclusive custody nor personal identity.
71request "$D2" "$O1"; worker joint.json; publish
72! find "$casepath/reg/a/" -name owner.tsv | grep -q . && ok 'B1 no owner.tsv lock is installed' || bad 'B1 ownership artifact'
73grep -q "$D2" "$casepath/site/a/$O1.html" && grep -q 'no ownership' "$casepath/site/a/$O1.html" && ok 'B1 second key is requester, not owner or author' || bad 'B1 REQUESTER_BLOCKED'
74printf '%s\n' "$D1" > "$casepath/remove"
75request "$D2" "$O1"; worker joint.json; publish
76[ "$(works)" = 2 ] && ok 'B1 removing hostile first requester does not block another key' || bad 'B1 stale custody after takedown'
77printf '%s\n' "$O2" >> "$casepath/remove"
78worker joint.json; publish
79[ "$(works)" = 1 ] && [ ! -e "$casepath/site/a/$O2.html" ] && ok 'A1 unrelated takedown still publishes after shared-record imports' || bad 'A1 takedown blocked'
80# A2: an individually valid 200-record import must not become unpublishable active state.
81newcase metadata-capacity
82request "$D1" "$O1"; worker joint.json; publish
83request "$D2" "$O2"; worker large.json
84[ "$(works)" = 1 ] && grep -q 'PUBLICATION_CAPACITY_OR_VALIDATION' "$casepath/log" && ok 'A2 large valid metadata refused before activation' || bad 'A2 ACTIVE_UNPUBLISHABLE'
85publish
86printf '%s\n' "$O1" > "$casepath/remove"; worker joint.json; publish
87[ "$(works)" = 0 ] && ok 'A2 unrelated removal remains publishable after rejected metadata' || bad 'A2 metadata blocks takedown'
88newcase corpus-capacity
89request "$D1" "$O1"; worker joint.json
90request "$D2" "$O2"; worker corpus.json large.txt
91[ "$(works)" = 1 ] && grep -q 'corpus exceeds' "$casepath/log" && ok 'A2 aggregate corpus overflow refused transactionally' || bad 'A2 corpus capacity not isolated'
92printf '%s\n' "$O1" > "$casepath/remove"; worker joint.json; publish
93[ "$(works)" = 0 ] && ok 'A2 removal still publishes after corpus refusal' || bad 'A2 corpus blocks takedown'
94# B5: replacement metadata plus a failed fetch must not retain the old paragraph.
95newcase refresh
96request "$D1" "$O1"; worker joint.json; publish
97grep -q OLD_PUBLIC_PARAGRAPH "$casepath/corpus" && ok 'B5 seeded a real cached paragraph' || bad 'B5 seed missing'
98request "$D1" "$O1"; FAIL_TEXT=1 worker changed.json; publish
99! grep -q OLD_PUBLIC_PARAGRAPH "$casepath/corpus" && grep -q 'Fresh metadata' "$casepath/site/w/"*.html && ok 'B5 changed file plus failed fetch publishes metadata only' || bad 'B5 STALE_TEXT_REUSED'
100# B4: policy overflow and nonregular/read failures are errors, not absence of policy.
101old=$(readlink "$casepath/reg/current")
102python3 - "$casepath/remove" "$D1" <<'PY'
103import sys
104open(sys.argv[1],'w').write('#'*65536+'\n'+sys.argv[2]+'\n')
105PY
106if worker joint.json; then bad 'B4 policy overflow accepted'; else
107 [ "$(readlink "$casepath/reg/current")" = "$old" ] && grep -q POLICY_READ "$casepath/log" && ok 'B4 overflow aborts without replacing derived catalog' || bad 'B4 overflow failed open'
108fi
109rm "$casepath/remove"; mkdir "$casepath/remove"
110if worker joint.json; then bad 'B4 directory policy accepted'; else
111 [ "$(readlink "$casepath/reg/current")" = "$old" ] && grep -q POLICY_READ "$casepath/log" && ok 'B4 policy type/read error fails closed' || bad 'B4 read error changed active state'
112fi
113rmdir "$casepath/remove"
114python3 - "$casepath/remove" "$D1" <<'PY'
115import sys
116open(sys.argv[1],'w').write('#'*65000+'\n'+sys.argv[2]+'\n')
117PY
118worker joint.json; publish
119[ "$(works)" = 0 ] && ok 'B4 removal before boundary is applied' || bad 'B4 removal missed'
120# JSON flattener/key and field injection: only true structural creator fields can match.
121"$F" < "$T/planted.json" > "$T/planted.flat"
122"$S" zenodo "$O1" "$D1" 2026-11-11 planted < "$T/planted.flat" > "$T/planted.tsv" 3> "$T/planted.texts" 2> "$T/planted.log"
123[ "$(grep -c '^W' "$T/planted.tsv")" = 1 ] && ! grep -q '^W[[:space:]]forged-row' "$T/planted.tsv" && ok 'metadata tab/newline values cannot plant registry facts' || bad 'metadata line injection'
124"$S" zenodo "$O2" "$D1" 2026-11-11 planted < "$T/planted.flat" > "$T/planted-no.tsv" 3> "$T/planted-no.texts" 2> "$T/planted-no.log"
125[ ! -s "$T/planted-no.tsv" ] && grep -q 'does not name ORCID' "$T/planted-no.log" && ok 'escaped path key cannot impersonate creator ORCID' || bad 'metadata structural-key injection'
126# Distinct executable negative controls. A compiler/setup failure is not a caught mutant.
127mutbin(){
128 mkdir -p "$T/$1"
129 { echo om2; cat "$OMV/om/tls/sha2.om" "$T/$1.om"; } | "$OMC" > "$T/$1/research-sync"
130 chmod 700 "$T/$1/research-sync"; ln -s "$F" "$T/$1/research-jflat"
131}
132sed 's/^zauthor$/mkslug vala tl valb tl/' research/sync.om > "$T/no-namespace.om"; mutbin no-namespace
133newcase mutant-coauthors
134request "$D1" "$O1"; TOOLS=$T/no-namespace worker joint.json
135request "$D2" "$O2"; TOOLS=$T/no-namespace worker joint.json
136[ "$(works)" = 1 ] && grep -q PUBLICATION_CAPACITY "$casepath/log" && ok 'MUTANT A1 caught as COAUTHOR_MISSING, not compiler error' || bad 'A1 namespace control not caught'
137# Publication bypass is the erroneous admission; the unchanged publisher must expose it.
138sed -e "s|^HERE=.*|HERE=$HERE|" -e 's/^validate() {/validate() { return 0;/' research/sync.sh > "$T/no-capacity.sh"
139newcase mutant-capacity
140request "$D1" "$O1"; WORKER=$T/no-capacity.sh worker joint.json
141request "$D2" "$O2"; WORKER=$T/no-capacity.sh worker large.json
142rc=0; publish || rc=$?
143if [ "$rc" = 4 ] && grep -q 'publish.sh: capacity: author catalog exceeds builder input 262143 bytes' "$casepath/publish.log" && [ "$(works)" -gt 1 ]; then
144 ok 'MUTANT A2 caught as ACTIVE_UNPUBLISHABLE with exact author-catalog capacity diagnostic'
145else bad 'A2 capacity control wrong reason'; cat "$casepath/publish.log"; fi
146# Reintroduce exclusive-public-requester authority for a fixture owner, not an authentication error.
147python3 - research/sync.om "$T/exclusive.om" "$D1" <<'PY'
148import sys
149s=open(sys.argv[1]).read().replace('text kmode1 "zenodo"','text ktowner "'+sys.argv[3]+'"\ntext ktlock "refused EXCLUSIVE_CUSTODY"\ntext kmode1 "zenodo"')
150a=s.index('emb ty\nemb 9',s.index('fn qline '));s=s[:a]+'if eq ty 90\nif not argeq 7 ktowner\nqrefuse ktlock\nret\nend\nend\n'+s[a:];open(sys.argv[2],'w').write(s)
151PY
152mutbin exclusive
153newcase mutant-custody
154request "$D1" "$O1"; TOOLS=$T/exclusive worker joint.json
155request "$D2" "$O1"; TOOLS=$T/exclusive worker joint.json
156! grep -rq "$D2" "$casepath/reg/a/" && grep -q EXCLUSIVE_CUSTODY "$casepath/log" && ok 'MUTANT B1 caught as REQUESTER_BLOCKED' || bad 'B1 custody control not caught'
157sed 's/if ne get rerr 0 0/if false/g' research/sync.om > "$T/no-policy-error.om"; mutbin no-policy-error
158newcase mutant-policy
159request "$D1" "$O1"; worker joint.json
160python3 - "$casepath/remove" "$D1" <<'PY'
161import sys
162open(sys.argv[1],'w').write('#'*65536+'\n'+sys.argv[2]+'\n')
163PY
164old=$(readlink "$casepath/reg/current")
165TOOLS=$T/no-policy-error worker joint.json
166[ "$(readlink "$casepath/reg/current")" != "$old" ] && [ "$(works)" = 1 ] && ok 'MUTANT B4 caught as POLICY_FAIL_OPEN' || bad 'B4 policy control not caught'
167# The old slug-alias purge mutant is superseded by immutable T identities. The executable
168# stale-binding control is in tests/binding-control.sh and covers the shared direct/queue binder.
169echo "REVIEW_RESULT pass=$pass fail=$fail"
170[ "$fail" = 0 ]