interplane-forge
INTERPLANE Forge
Brought by drakestapleton
interplane-forge / research / tests / review.sh
| 1 | #!/bin/sh |
| 2 | # Review A/B regression gate. Real sync/gather/publish, saved API fixtures, no public network. |
| 3 | set -eu |
| 4 | cd "$(dirname "$0")/../.." |
| 5 | HERE=$(pwd) |
| 6 | T=$(mktemp -d) |
| 7 | trap 'rm -rf "$T"' EXIT HUP INT TERM |
| 8 | pass=0; fail=0 |
| 9 | ok(){ pass=$((pass+1)); echo "PASS review $*"; } |
| 10 | bad(){ fail=$((fail+1)); echo "FAIL review $*"; } |
| 11 | sh research/build-tools.sh "$T/bin" |
| 12 | S=$T/bin/research-sync; F=$T/bin/research-jflat |
| 13 | OMV=$HOME/work/flux/omega-mv; OMC=$OMV/seed/out/omc |
| 14 | D1=did:key:z6MkAbcdefghijkmnopqrstuvw111111111111111111111 |
| 15 | D2=did:key:z6MkAbcdefghijkmnopqrstuvw222222222222222222222 |
| 16 | O1=0009-0002-6890-7111 |
| 17 | O2=0000-0002-1825-0097 |
| 18 | mkdir "$T/mock" |
| 19 | python3 - "$T" "$O1" "$O2" <<'PY' |
| 20 | import json,sys,pathlib |
| 21 | p=pathlib.Path(sys.argv[1]);o1,o2=sys.argv[2:] |
| 22 | def 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 |
| 26 | def save(name,rs):json.dump({'hits':{'total':len(rs),'hits':rs}},open(p/name,'w')) |
| 27 | save('joint.json',[rec(201,[o1,o2])]) |
| 28 | r=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]) |
| 29 | save('large.json',[rec(i,[o2],'x'*12000,False) for i in range(1000,1200)]) |
| 30 | save('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. |
| 34 | r=rec(501,[o1]);r['metadata']['title']='Title\tX\nW\tforged-row';r['metadata']['creators/0/orcid']=o2 |
| 35 | save('planted.json',[r]) |
| 36 | PY |
| 37 | cat > "$T/mock/curl" <<'EOF' |
| 38 | #!/bin/sh |
| 39 | args=$*; out= |
| 40 | while [ "$#" -gt 0 ]; do |
| 41 | if [ "$1" = -o ]; then out=$2; shift 2; else shift; fi |
| 42 | done |
| 43 | case "$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" ;; |
| 47 | esac |
| 48 | EOF |
| 49 | chmod 700 "$T/mock/curl" |
| 50 | newcase(){ |
| 51 | casepath=$T/$1; mkdir -p "$casepath/add" "$casepath/reg" |
| 52 | printf '*\n' > "$casepath/allow"; : > "$casepath/remove"; : > "$casepath/list" |
| 53 | } |
| 54 | request(){ printf 'Z\t%s\t%s\t\n' "$1" "$2" >> "$casepath/add/queue"; } |
| 55 | worker(){ |
| 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 | } |
| 59 | publish(){ sh research/publish.sh "$casepath/site" "$casepath/corpus" "$casepath/reg" > "$casepath/publish.log" 2>&1; } |
| 60 | works(){ 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. |
| 62 | newcase coauthors |
| 63 | request "$D1" "$O1"; worker joint.json |
| 64 | request "$D2" "$O2"; worker joint.json |
| 65 | publish |
| 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' |
| 69 | grep -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. |
| 71 | request "$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' |
| 73 | grep -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' |
| 74 | printf '%s\n' "$D1" > "$casepath/remove" |
| 75 | request "$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' |
| 77 | printf '%s\n' "$O2" >> "$casepath/remove" |
| 78 | worker 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. |
| 81 | newcase metadata-capacity |
| 82 | request "$D1" "$O1"; worker joint.json; publish |
| 83 | request "$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' |
| 85 | publish |
| 86 | printf '%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' |
| 88 | newcase corpus-capacity |
| 89 | request "$D1" "$O1"; worker joint.json |
| 90 | request "$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' |
| 92 | printf '%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. |
| 95 | newcase refresh |
| 96 | request "$D1" "$O1"; worker joint.json; publish |
| 97 | grep -q OLD_PUBLIC_PARAGRAPH "$casepath/corpus" && ok 'B5 seeded a real cached paragraph' || bad 'B5 seed missing' |
| 98 | request "$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. |
| 101 | old=$(readlink "$casepath/reg/current") |
| 102 | python3 - "$casepath/remove" "$D1" <<'PY' |
| 103 | import sys |
| 104 | open(sys.argv[1],'w').write('#'*65536+'\n'+sys.argv[2]+'\n') |
| 105 | PY |
| 106 | if 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' |
| 108 | fi |
| 109 | rm "$casepath/remove"; mkdir "$casepath/remove" |
| 110 | if 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' |
| 112 | fi |
| 113 | rmdir "$casepath/remove" |
| 114 | python3 - "$casepath/remove" "$D1" <<'PY' |
| 115 | import sys |
| 116 | open(sys.argv[1],'w').write('#'*65000+'\n'+sys.argv[2]+'\n') |
| 117 | PY |
| 118 | worker 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. |
| 127 | mutbin(){ |
| 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 | } |
| 132 | sed 's/^zauthor$/mkslug vala tl valb tl/' research/sync.om > "$T/no-namespace.om"; mutbin no-namespace |
| 133 | newcase mutant-coauthors |
| 134 | request "$D1" "$O1"; TOOLS=$T/no-namespace worker joint.json |
| 135 | request "$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. |
| 138 | sed -e "s|^HERE=.*|HERE=$HERE|" -e 's/^validate() {/validate() { return 0;/' research/sync.sh > "$T/no-capacity.sh" |
| 139 | newcase mutant-capacity |
| 140 | request "$D1" "$O1"; WORKER=$T/no-capacity.sh worker joint.json |
| 141 | request "$D2" "$O2"; WORKER=$T/no-capacity.sh worker large.json |
| 142 | rc=0; publish || rc=$? |
| 143 | if [ "$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' |
| 145 | else 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. |
| 147 | python3 - research/sync.om "$T/exclusive.om" "$D1" <<'PY' |
| 148 | import sys |
| 149 | s=open(sys.argv[1]).read().replace('text kmode1 "zenodo"','text ktowner "'+sys.argv[3]+'"\ntext ktlock "refused EXCLUSIVE_CUSTODY"\ntext kmode1 "zenodo"') |
| 150 | a=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) |
| 151 | PY |
| 152 | mutbin exclusive |
| 153 | newcase mutant-custody |
| 154 | request "$D1" "$O1"; TOOLS=$T/exclusive worker joint.json |
| 155 | request "$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' |
| 157 | sed 's/if ne get rerr 0 0/if false/g' research/sync.om > "$T/no-policy-error.om"; mutbin no-policy-error |
| 158 | newcase mutant-policy |
| 159 | request "$D1" "$O1"; worker joint.json |
| 160 | python3 - "$casepath/remove" "$D1" <<'PY' |
| 161 | import sys |
| 162 | open(sys.argv[1],'w').write('#'*65536+'\n'+sys.argv[2]+'\n') |
| 163 | PY |
| 164 | old=$(readlink "$casepath/reg/current") |
| 165 | TOOLS=$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. |
| 169 | echo "REVIEW_RESULT pass=$pass fail=$fail" |
| 170 | [ "$fail" = 0 ] |