interplane-forge
INTERPLANE Forge
Brought by drakestapleton
interplane-forge / research / tests / overlap.sh
| 1 | #!/bin/sh |
| 2 | set -eu |
| 3 | cd "$(dirname "$0")/../.." |
| 4 | T=$(mktemp -d) |
| 5 | trap 'rm -rf "$T"' EXIT HUP INT TERM |
| 6 | pass=0; fail=0 |
| 7 | ok(){ pass=$((pass+1)); echo "PASS overlap $*"; } |
| 8 | bad(){ fail=$((fail+1)); echo "FAIL overlap $*"; } |
| 9 | sh research/build-tools.sh "$T/bin" |
| 10 | S=$T/bin/research-sync; F=$T/bin/research-jflat |
| 11 | D1=did:key:z6MkAbcdefghijkmnopqrstuvw111111111111111111111 |
| 12 | D2=did:key:z6MkAbcdefghijkmnopqrstuvw222222222222222222222 |
| 13 | O=0009-0002-6890-7111 |
| 14 | mkdir -p "$T/mock" "$T/add" "$T/reg"; printf '*\n' > "$T/allow"; : > "$T/remove"; : > "$T/list" |
| 15 | python3 - "$T" "$O" <<'PY' |
| 16 | import json,sys,pathlib |
| 17 | p=pathlib.Path(sys.argv[1]);o=sys.argv[2] |
| 18 | for label in ['DOI_OLD','ORCID_NEW']: |
| 19 | r={'id':201,'doi':'10.5281/zenodo.201','conceptdoi':'10.5281/zenodo.201','metadata':{'title':'Shared work','description':label+' metadata','publication_date':'2026-11-11','resource_type':{'subtype':'preprint'},'license':{'id':'cc-by-4.0'},'creators':[{'name':'Public, Author','orcid':o}]},'files':[{'key':'paper.txt','size':123,'links':{'self':'https://zenodo.org/api/records/201/files/paper.txt/content'}}]} |
| 20 | json.dump(r,open(p/(label+'.record'),'w'));json.dump({'hits':{'total':1,'hits':[r]}},open(p/(label+'.search'),'w')) |
| 21 | (p/(label+'.txt')).write_text(label+' public text.\n\n') |
| 22 | PY |
| 23 | cat > "$T/mock/curl" <<'EOF' |
| 24 | #!/bin/sh |
| 25 | url=; out=; page=1 |
| 26 | while [ "$#" -gt 0 ]; do |
| 27 | case $1 in |
| 28 | -o|--output) out=$2; shift 2;; |
| 29 | --url) url=$2; shift 2;; |
| 30 | --data-urlencode) case $2 in page=*) page=${2#page=};; esac; shift 2;; |
| 31 | https://*) url=$1; shift;; |
| 32 | *) shift;; |
| 33 | esac |
| 34 | done |
| 35 | case $url in |
| 36 | */files/*) cp "$BODY" "$out";; |
| 37 | */api/records/201) cp "$RECORD" "$out";; |
| 38 | */api/records) if [ "$page" = 1 ]; then cp "$SEARCH" "$out"; else printf '{"hits":{"total":0,"hits":[]}}' > "$out"; fi;; |
| 39 | *) echo 'fixture unexpected URL' >&2; exit 22;; |
| 40 | esac |
| 41 | EOF |
| 42 | chmod 700 "$T/mock/curl" |
| 43 | worker(){ |
| 44 | PATH="$T/mock:$PATH" RESEARCH_TOOLS=$T/bin RECORD="$T/$1.record" SEARCH="$T/$1.search" BODY="$T/$1.txt" \ |
| 45 | sh research/sync.sh --queue "$T/add/" "$T/state" "$T/allow" "$T/remove" "$T/reg/" "$T/list" "$T/store" > "$T/log" 2>&1 |
| 46 | } |
| 47 | publish(){ sh research/publish.sh "$T/site" "$T/corpus" "$T/reg" > "$T/pub.log" 2>&1; } |
| 48 | request(){ printf 'Z\t%s\t%s\t%s\n' "$1" "$O" "$2" >> "$T/add/queue"; } |
| 49 | assert_current(){ |
| 50 | wanted=$1 |
| 51 | grep -q "$wanted metadata" "$T/site/w/"*.html && grep -q "$wanted public text" "$T/corpus" || return 1 |
| 52 | other=DOI_OLD; [ "$wanted" != DOI_OLD ] || other=ORCID_NEW |
| 53 | ! grep -q "$other public text" "$T/corpus" |
| 54 | } |
| 55 | request "$D1" 10.5281/zenodo.201; worker DOI_OLD |
| 56 | request "$D2" ''; worker ORCID_NEW; publish |
| 57 | assert_current ORCID_NEW && grep '^P' "$T/reg/show/$O.tsv" | grep -q "$D2" && ok 'later ORCID requester wins before removal with its matching metadata/text' || bad 'A4 LATER_REQUESTER_LOST' |
| 58 | printf '%s\n' "$D1" > "$T/remove" |
| 59 | request "$D2" ''; worker ORCID_NEW; publish |
| 60 | assert_current ORCID_NEW && grep '^P' "$T/reg/show/$O.tsv" | grep -q "$D2" && ok 'D1 DOI / D2 ORCID / remove D1 / D2 resync preserves D2' || bad 'A4 REMOVED_BUNDLE_POISON' |
| 61 | # Replay the exact retained raw pair in both concatenation orders through gather and publish. |
| 62 | for order in doi-first orcid-first; do |
| 63 | if [ "$order" = doi-first ]; then cat "$T/reg/a/$O/doi-201.tsv" "$T/reg/a/$O/zenodo.tsv" > "$T/raw"; else cat "$T/reg/a/$O/zenodo.tsv" "$T/reg/a/$O/doi-201.tsv" > "$T/raw"; fi |
| 64 | view=$T/view-$order; mkdir -p "$view/show"; cp research/registry/catalog.tsv "$view/catalog.tsv" |
| 65 | ln -s "$(readlink -f "$T/reg/text")" "$view/text" |
| 66 | "$S" gather "$T/remove" "$T/list" < "$T/raw" > "$view/show/$O.tsv" |
| 67 | sh research/publish.sh "$T/site-$order" "$T/corpus-$order" "$view" > "$T/pub-$order.log" 2>&1 |
| 68 | grep -q 'ORCID_NEW metadata' "$T/site-$order/w/"*.html && grep -q 'ORCID_NEW public text' "$T/corpus-$order" && ! grep -q 'DOI_OLD public text' "$T/corpus-$order" && ok "eligible selection and cache binding independent of input order $order" || bad "A4 order $order" |
| 69 | done |
| 70 | # A source-specific removal can fall back only with the old source's own immutable cache. |
| 71 | printf '%s\n' "$D2" > "$T/remove"; worker ORCID_NEW; publish |
| 72 | assert_current DOI_OLD && grep '^P' "$T/reg/show/$O.tsv" | grep -q "$D1" && ok 'requester fallback preserves old metadata and its own old text' || bad 'A4 FALLBACK_TEXT_MISMATCH' |
| 73 | printf '10.5281/zenodo.201\n' > "$T/remove"; worker ORCID_NEW; publish |
| 74 | [ "$(grep -h '^W' "$T/reg"/show/*.tsv | wc -l | tr -d ' ')" = 0 ] && ! grep -qE 'DOI_OLD public text|ORCID_NEW public text' "$T/corpus" && ok 'explicit work DOI takedown suppresses all requester copies' || bad 'A4 work takedown bypass' |
| 75 | echo "OVERLAP_RESULT pass=$pass fail=$fail" |
| 76 | [ "$fail" = 0 ] |