interplane-forge
INTERPLANE Forge
Brought by drakestapleton
interplane-forge / research / tests / profile-round4.sh
| 1 | #!/bin/sh |
| 2 | # Round-four lossless profile/layout regressions. All state and publication are offline fixtures. |
| 3 | set -eu |
| 4 | cd "$(dirname "$0")/../.." |
| 5 | T=$(mktemp -d) |
| 6 | trap 'rm -rf "$T"' EXIT HUP INT TERM |
| 7 | sh research/build-tools.sh "$T/bin" |
| 8 | S=$T/bin/research-sync |
| 9 | OMV=${OMV:-$HOME/work/flux/omega-mv}; OMC=${OMC:-$OMV/seed/out/omc} |
| 10 | D1=did:key:z6MkAbcdefghijkmnopqrstuvw111111111111111111111 |
| 11 | D2=did:key:z6MkAbcdefghijkmnopqrstuvw222222222222222222222 |
| 12 | O=0009-0002-6890-7111 |
| 13 | : > "$T/remove"; : > "$T/list" |
| 14 | mkdir -p "$T/text" |
| 15 | printf 'Original own immutable paragraphs.\n' > "$T/text/work-a.txt" |
| 16 | printf 'New own immutable paragraphs.\n' > "$T/text/work-b.txt" |
| 17 | A=$(sha256sum "$T/text/work-a.txt" | cut -d' ' -f1) |
| 18 | B=$(sha256sum "$T/text/work-b.txt" | cut -d' ' -f1) |
| 19 | fixture() { |
| 20 | slug=$1; did=$2; name=$3; doi=$4; day=$5 |
| 21 | printf 'W\t%s\t\t%s\tpreprint\tZenodo\t10.5281/zenodo.%s\t10.5281/zenodo.%s\tv%s\t1\t0\tcc-by-4.0\t%s own title\n' "$slug" "$day" "$doi" "$doi" "$doi" "$name" |
| 22 | printf 'A\t%s\t%s own abstract\nB\t%s\t%s own byline\nP\t%s\tzenodo\t%s\t%s\thttps://zenodo.org/records/%s\t1\n' "$slug" "$name" "$slug" "$name" "$slug" "$did" "$day" "$doi" |
| 23 | printf 'O\tid\tother\nO\tname\t%s profile\nO\torcid\t%s\nO\tbio\t%s biography\nO\trecord-name\t%s recorded name\nO\tadded-by\t%s\nO\tchecked\t%s\nO\tvia\tzenodo\n' "$name" "$O" "$name" "$name" "$did" "$day" |
| 24 | } |
| 25 | fixture work-a "$D1" Original 101 2026-11-10 > "$T/raw-a" |
| 26 | fixture work-b "$D2" New 102 2026-11-11 > "$T/raw-b" |
| 27 | "$S" bind 1 "$T/text/" < "$T/raw-a" > "$T/a" 3> "$T/plan-a" |
| 28 | "$S" bind 2 "$T/text/" < "$T/raw-b" > "$T/b" 3> "$T/plan-b" |
| 29 | # Extract the actual full and withholding helpers, not a reimplementation of their logic. |
| 30 | python3 - research/sync.sh "$T/helper" <<'PY' |
| 31 | import sys |
| 32 | s=open(sys.argv[1]).read(); a=s.index('gather_one() {'); b=s.index('validate() {',a) |
| 33 | open(sys.argv[2],'w').write('set -eu\nSYNC=$1; remove=$2; shelf=$3; W=$4\n'+s[a:b]+'\ngather "$5" "${6:-}" "${7:-}"\n') |
| 34 | PY |
| 35 | prepare() { |
| 36 | root=$1 |
| 37 | mkdir -p "$root/a/other" "$root/show" "$root/text" |
| 38 | cp research/registry/catalog.tsv "$root/catalog.tsv" |
| 39 | cp research/registry/text/*.txt "$root/text/" |
| 40 | cp "$T/text/work-a.txt" "$root/text/work-a.$A.txt" |
| 41 | cp "$T/text/work-b.txt" "$root/text/work-b.$B.txt" |
| 42 | } |
| 43 | profile_oracle() { |
| 44 | python3 - "$1" "$D1" "$A" <<'PY' |
| 45 | import sys |
| 46 | rows=[x.rstrip('\n').split('\t') for x in open(sys.argv[1])] |
| 47 | w=[r for r in rows if r[0]=='W'];p=[r for r in rows if r[0]=='P'];t=[r for r in rows if r[0]=='T'] |
| 48 | o={r[1]:r[2] for r in rows if r[0]=='O'} |
| 49 | if len(w)!=1 or w[0][1]!='work-a' or w[0][-1]!='Original own title' or len(p)!=1 or p[0][3]!=sys.argv[2] or len(t)!=1 or t[0][2]!=sys.argv[3]: |
| 50 | raise SystemExit('PROFILE_FIXTURE_OR_METADATA_FAILURE') |
| 51 | if o.get('orcid')!='0009-0002-6890-7111' or o.get('name')!='Original profile' or o.get('bio')!='Original biography' or o.get('record-name')!='Original recorded name' or o.get('added-by')!=sys.argv[2] or o.get('checked')!='2026-11-10' or o.get('via')!='zenodo': |
| 52 | raise SystemExit('PROFILE_FROM_REJECTED_BUNDLE') |
| 53 | PY |
| 54 | } |
| 55 | for order in ab ba; do |
| 56 | : > "$T/remove" |
| 57 | case $order in ab) cat "$T/a" "$T/b";; ba) cat "$T/b" "$T/a";; esac > "$T/both" |
| 58 | "$S" gather "$T/remove" "$T/list" < "$T/both" > "$T/selected" |
| 59 | "$S" gather "$T/remove" "$T/list" < "$T/selected" > "$T/repeated" |
| 60 | cmp "$T/selected" "$T/repeated" |
| 61 | printf '%s\n' "$D2" > "$T/remove" |
| 62 | "$S" gather "$T/remove" "$T/list" < "$T/repeated" > "$T/own" |
| 63 | profile_oracle "$T/own" |
| 64 | root=$T/profile-$order; prepare "$root" |
| 65 | mkdir -p "$T/prev-$order" "$T/work-$order" |
| 66 | cp "$T/selected" "$T/prev-$order/other.tsv" |
| 67 | cp "$T/a" "$root/a/other/a.tsv"; cp "$T/b" "$root/a/other/b.tsv" |
| 68 | sh "$T/helper" "$S" "$T/remove" "$T/list" "$T/work-$order" "$root" "$T/prev-$order" "$root/a/other/b.tsv" |
| 69 | profile_oracle "$root/show/other.tsv" |
| 70 | sh research/publish.sh "$root/site" "$root/corpus" "$root" > "$root/publish.log" 2>&1 |
| 71 | grep -q 'Original profile' "$root/site/a/other.html" |
| 72 | ! grep -q 'New profile\|New own byline' "$root/site/a/other.html" "$root/site/w/work-a.html" "$root/site/index.html" |
| 73 | grep -q 'Original own immutable paragraphs' "$root/corpus" |
| 74 | [ ! -e "$root/site/w/work-b.html" ] |
| 75 | echo "PASS profile-round4 own association, repeated gather, actual fallback and publication order=$order" |
| 76 | done |
| 77 | # Eligibility uses the bound bundle's ORCID too, not the shared latest O profile. |
| 78 | sed 's/0009-0002-6890-7111/0000-0002-1825-0097/g' "$T/b" > "$T/other-orcid" |
| 79 | : > "$T/remove" |
| 80 | cat "$T/a" "$T/other-orcid" | "$S" gather "$T/remove" "$T/list" > "$T/orcid-selected" |
| 81 | printf '0000-0002-1825-0097\n' > "$T/remove" |
| 82 | "$S" gather "$T/remove" "$T/list" < "$T/orcid-selected" > "$T/orcid-own" |
| 83 | profile_oracle "$T/orcid-own" |
| 84 | echo 'PASS profile-round4 eligibility uses only the bundle-associated ORCID' |
| 85 | # Legacy migration is explicit: raw header-only input converts alone; ambiguous old selected |
| 86 | # multiwork must be rebuilt from raw. No shared-O reconstruction is permitted there. |
| 87 | { grep '^O' "$T/a"; grep -v '^O' "$T/a"; } > "$T/header" |
| 88 | "$S" layout raw < "$T/header" > "$T/header-layout" |
| 89 | grep -q '^N.*Original profile' "$T/header-layout" |
| 90 | rc=0; "$S" layout selected < "$T/header" > "$T/refused" 2> "$T/upgrade.err" || rc=$? |
| 91 | [ "$rc" = 1 ] && [ ! -s "$T/refused" ] && grep -q SELECTED_PROFILE_UNBOUND "$T/upgrade.err" |
| 92 | grep -v '^[NI]' "$T/selected" > "$T/old-selected" |
| 93 | rc=0; "$S" layout selected < "$T/old-selected" > "$T/refused" 2> "$T/upgrade.err" || rc=$? |
| 94 | [ "$rc" = 1 ] && [ ! -s "$T/refused" ] && grep -q SELECTED_PROFILE_UNBOUND "$T/upgrade.err" |
| 95 | cat "$T/header" "$T/b" > "$T/old-mixed" |
| 96 | rc=0; "$S" layout raw < "$T/old-mixed" > "$T/refused" 2> "$T/mixed.err" || rc=$? |
| 97 | [ "$rc" = 1 ] && [ ! -s "$T/refused" ] && grep -q MIXED_PROFILE_LAYOUT "$T/mixed.err" |
| 98 | echo 'PASS profile-round4 raw legacy alone and fail-closed selected/mixed migration' |
| 99 | # Same slug, different version AND concept DOI. Older evidence must survive even when its |
| 100 | # requester is removed. G originally follows O, as it does in the legacy repo serializer. |
| 101 | sed -e 's/work-b/work-a/g' -e 's/zenodo.102/zenodo.202/' "$T/b" | sed '/^W/s/zenodo.202\t/zenodo.102\t/2' > "$T/copy-new" |
| 102 | # Explicitly set W fields instead of relying on the surrounding source URL. |
| 103 | python3 - "$T/copy-new" <<'PY' |
| 104 | import sys |
| 105 | p=sys.argv[1];rs=[r.rstrip('\n').split('\t') for r in open(p)] |
| 106 | for r in rs: |
| 107 | if r[0]=='W':r[6]='10.5281/zenodo.202';r[7]='10.5281/zenodo.102' |
| 108 | open(p,'w').write(''.join('\t'.join(r)+'\n' for r in rs)) |
| 109 | PY |
| 110 | { sed '/^P/s/\t1$/\t0/' "$T/a"; printf 'G\twork-a\t1111111111111111111111111111111111111111\t%s\n' "$A"; } > "$T/copy-old" |
| 111 | printf 'G\twork-a\t2222222222222222222222222222222222222222\t%s\n' "$B" >> "$T/copy-new" |
| 112 | for order in old-new new-old; do |
| 113 | root=$T/cross-$order; prepare "$root"; mkdir -p "$T/cross-work-$order" |
| 114 | case $order in old-new) cp "$T/copy-old" "$root/a/other/1.tsv"; cp "$T/copy-new" "$root/a/other/2.tsv";; new-old) cp "$T/copy-new" "$root/a/other/1.tsv"; cp "$T/copy-old" "$root/a/other/2.tsv";; esac |
| 115 | cat "$root"/a/other/*.tsv > "$T/cross-both" |
| 116 | printf '10.5281/zenodo.101\n' > "$T/remove" |
| 117 | "$S" gather "$T/remove" "$T/list" < "$T/cross-both" > "$T/direct" |
| 118 | [ ! -s "$T/direct" ] |
| 119 | sh "$T/helper" "$S" "$T/remove" "$T/list" "$T/cross-work-$order" "$root" |
| 120 | cmp "$T/direct" "$root/show/other.tsv" |
| 121 | sh research/publish.sh "$root/site" "$root/corpus" "$root" > "$root/publish.log" 2>&1 |
| 122 | [ ! -e "$root/site/w/work-a.html" ] |
| 123 | ! grep -q 'Original own title\|New own title' "$root/site/index.html" |
| 124 | # Exact W/P/R/T/G multisets and original P flags are conserved by layout, with removed data. |
| 125 | printf '%s\n' "$D1" > "$T/remove" |
| 126 | : > "$T/layouts" |
| 127 | for f in "$root"/a/other/*.tsv; do "$S" layout raw < "$f" >> "$T/layouts"; done |
| 128 | python3 - "$T/cross-both" "$T/layouts" "$D1" <<'PY' |
| 129 | import collections,sys |
| 130 | read=lambda p:[l.rstrip('\n').split('\t') for l in open(p)] |
| 131 | a,b=map(read,sys.argv[1:3]); kinds={'W','P','R','T','G'} |
| 132 | x=lambda rs:collections.Counter(tuple(r) for r in rs if r[0] in kinds) |
| 133 | if x(a)!=x(b) or sum(r[0]=='W' for r in b)!=2 or not any(r[0]=='P' and r[3]==sys.argv[3] and r[-1]=='0' for r in b): |
| 134 | raise SystemExit('LAYOUT_PERFORMED_SELECTION_OR_CHANGED_PROVENANCE') |
| 135 | PY |
| 136 | printf '%s\n' "$D1" > "$T/remove" |
| 137 | sh "$T/helper" "$S" "$T/remove" "$T/list" "$T/cross-work-$order" "$root" |
| 138 | [ "$(grep '^P' "$root/show/other.tsv" | cut -f4,7)" = "$(printf '%s\t1' "$D2")" ] |
| 139 | # Prior selected new copy has lost the older DOI from its W: auxiliary raw still denies it. |
| 140 | cp "$root/show/other.tsv" "$T/prev-$order.tsv" |
| 141 | mkdir -p "$T/cross-prev-$order"; cp "$T/prev-$order.tsv" "$T/cross-prev-$order/other.tsv" |
| 142 | printf '10.5281/zenodo.101\n' > "$T/remove" |
| 143 | sh "$T/helper" "$S" "$T/remove" "$T/list" "$T/cross-work-$order" "$root" "$T/cross-prev-$order" '' |
| 144 | [ ! -s "$root/show/other.tsv" ] |
| 145 | sh research/publish.sh "$root/fallback-site" "$root/fallback-corpus" "$root" > "$root/fallback-publish.log" 2>&1 |
| 146 | [ ! -e "$root/fallback-site/w/work-a.html" ] |
| 147 | echo "PASS profile-round4 lossless layout, cross-copy explicit takedown, separate requester filter and fallback evidence order=$order" |
| 148 | done |
| 149 | # Own permission is retained separately from aggregate-closed P. Selected-only passes stay |
| 150 | # conservative, never silently reopen text after dropping the closed-copy evidence. The full |
| 151 | # raw helper above recomputes and reopens only after removing the closed requester. |
| 152 | : > "$T/remove" |
| 153 | cat "$T/copy-old" "$T/copy-new" | "$S" gather "$T/remove" "$T/list" > "$T/closed-selection" |
| 154 | [ "$(grep '^P' "$T/closed-selection" | cut -f7)" = 0 ] |
| 155 | [ "$(grep '^I' "$T/closed-selection" | cut -f3)" = 1 ] |
| 156 | printf '%s\n' "$D1" > "$T/remove" |
| 157 | "$S" gather "$T/remove" "$T/list" < "$T/closed-selection" > "$T/reopened" |
| 158 | [ "$(grep '^P' "$T/reopened" | cut -f7)" = 0 ] |
| 159 | [ "$(grep '^I' "$T/reopened" | cut -f3)" = 1 ] |
| 160 | echo 'PASS profile-round4 own permission retained; selected-only text remains conservatively withheld' |
| 161 | # Negative control 1 removes association emission only from selected gather output, leaving O. |
| 162 | # Disable the deliberate upgrade refusal only in this historical mutant so the oracle observes |
| 163 | # wrong profile data, rather than treating a setup/upgrade/compiler error as a caught defect. |
| 164 | python3 - research/sync.om "$T/lost-profile.om" <<'PY' |
| 165 | import sys |
| 166 | s=open(sys.argv[1]).read();a=s.index('fn gemit ');b=s.index('fn gemprofile ',a);q=s[a:b] |
| 167 | if q.count('gattach s\n')!=1:raise SystemExit('mutant anchor missing') |
| 168 | s=s[:a]+q.replace('gattach s\n','')+s[b:] |
| 169 | a=s.index('fn lmode ');b=s.index('note ---- bind:',a);q=s[a:b] |
| 170 | if q.count('if ne nn nw\n')!=1:raise SystemExit('upgrade mutant anchor missing') |
| 171 | s=s[:a]+q.replace('if ne nn nw\n','if false\n')+s[b:] |
| 172 | open(sys.argv[2],'w').write(s) |
| 173 | PY |
| 174 | { echo om2; cat "$OMV/om/tls/sha2.om" "$T/lost-profile.om"; } | "$OMC" > "$T/lost-profile" |
| 175 | chmod 700 "$T/lost-profile" |
| 176 | : > "$T/remove" |
| 177 | cat "$T/a" "$T/b" | "$T/lost-profile" gather "$T/remove" "$T/list" > "$T/prev-ab/other.tsv" |
| 178 | ! grep -q '^[NI]' "$T/prev-ab/other.tsv" |
| 179 | grep -q '^O.*New profile' "$T/prev-ab/other.tsv" |
| 180 | printf '%s\n' "$D2" > "$T/remove" |
| 181 | sh "$T/helper" "$T/lost-profile" "$T/remove" "$T/list" "$T/work-ab" "$T/profile-ab" "$T/prev-ab" "$T/profile-ab/a/other/b.tsv" |
| 182 | rc=0; profile_oracle "$T/profile-ab/show/other.tsv" > "$T/profile-mutant.log" 2>&1 || rc=$? |
| 183 | [ "$rc" != 0 ] && grep -q '^PROFILE_FROM_REJECTED_BUNDLE$' "$T/profile-mutant.log" |
| 184 | echo 'PASS profile-round4 MUTANT caught PROFILE_FROM_REJECTED_BUNDLE (not setup/compiler failure)' |
| 185 | # Negative control 2 changes only the real full-helper layout call back to per-file gather. |
| 186 | python3 - "$T/helper" "$T/old-helper" <<'PY' |
| 187 | import sys |
| 188 | s=open(sys.argv[1]).read();old='"$SYNC" layout raw < "$rawfile"' |
| 189 | if s.count(old)!=1:raise SystemExit('layout mutant anchor missing') |
| 190 | open(sys.argv[2],'w').write(s.replace(old,'"$SYNC" gather "$remove" "$shelf" < "$rawfile"')) |
| 191 | PY |
| 192 | printf '10.5281/zenodo.101\n' > "$T/remove" |
| 193 | sh "$T/old-helper" "$S" "$T/remove" "$T/list" "$T/cross-work-old-new" "$T/cross-old-new" |
| 194 | [ "$(grep -c '^W' "$T/cross-old-new/show/other.tsv")" = 1 ] |
| 195 | grep -q 'New own title' "$T/cross-old-new/show/other.tsv" |
| 196 | echo 'PASS profile-round4 MUTANT caught CROSS_COPY_TAKEDOWN_LOST (surviving work, not setup/compiler failure)' |
| 197 | echo 'PROFILE_ROUND4_RESULT PASS' |