interplane.Get Omega
Read in your language

interplane-forge

INTERPLANE Forge

Brought by drakestapleton

branch main Branches Tags History

interplane-forge / research / tests / publication.sh

231 lines · 11373 bytes Raw Blame History
1#!/bin/sh
2# Private real forged + publisher + agent-cload fixture. No production pause hook or live data.
3set -eu
4cd "$(dirname "$0")/../.."
5ROOT=$PWD
6OMC=$HOME/work/flux/omega-mv/seed/out/omc
7T=$(mktemp -d /tmp/research-publication.XXXXXX)
8PORT=${RESEARCH_PUBLICATION_PORT:-19467}
9PID=; PUB=; HTTP=; AGENT=
10cleanup(){ for p in "$PID" "$PUB" "$HTTP" "$AGENT"; do [ -z "$p" ] || kill "$p" 2>/dev/null || :; done; rm -rf "$T"; }
11trap cleanup EXIT HUP INT TERM
12pass=0; fail=0
13ok(){ pass=$((pass+1)); echo "PASS publication $*"; }
14bad(){ fail=$((fail+1)); echo "FAIL publication $*"; }
15check(){ if "$@"; then ok "$*"; else bad "$*"; fi; }
16mkdir -p "$T/reg/show" "$T/reg/text" "$T/data/research/ask" "$T/data/research/add" "$T/social" "$T/slwork"
17cp research/registry/catalog.tsv "$T/reg/catalog.tsv"
18cp research/registry/text/*.txt "$T/reg/text/"
19printf 'answer stays\n' > "$T/data/research/ask/keep.html"
20printf 'queue stays\n' > "$T/data/research/add/queue"
21O=$T/data/research
22C=$T/corpus
23fixture(){
24 printf 'Body for ATOMIC-%s.\n' "$1" > "$T/text"
25 digest=$(sha256sum "$T/text" | cut -d' ' -f1)
26 cp "$T/text" "$T/reg/text/fixture.$digest.txt"
27 { printf 'O\tid\tfixture-author\nO\tname\tFixture Author\nO\tadded-by\tdid:key:zFixture\nO\tvia\tzenodo\nO\tchecked\t2026-11-11\n'
28 printf 'W\tfixture\t\t2026-11-11\tpreprint\tZenodo\t\t\t1\t1\t0\tcc-by-4.0\tATOMIC-%s\n' "$1"
29 printf 'C\tfixture\tFixture Author\nP\tfixture\tzenodo\tdid:key:zFixture\t2026-11-11\thttps://zenodo.org/records/1\t1\nT\tfixture\t%s\n' "$digest"
30 } > "$T/reg/show/fixture.tsv"
31}
32publish(){ sh research/publish.sh "$O" "$C" "$T/reg" >> "$T/publish.log" 2>&1; }
33fixture OLD
34publish
35old=$(readlink "$O/current")
36cp "$O/current/index.json" "$T/old.json"
37cp "$C" "$T/old.corpus"
38check test "$(readlink "$O/w")" = current/w
39check test "$(readlink -f "$C")" = "$(readlink -f "$O/current/corpus.txt")"
40grep -Ev '^#| research\.(html|json|bib|txt|css)$' research/tests/fixtures/base-sha256.txt > "$T/legacy.sha"
41if (cd "$O/w" && sha256sum -c "$T/legacy.sha") > "$T/legacy.log"; then ok '48 frozen work documents byte exact'; else bad 'legacy byte drift'; fi
42# Test-only source seams, named and asserted once. Production source contains neither FIFO nor env hook.
43mkfifo "$T/publish-go" "$T/http-ready" "$T/http-go" "$T/agent-ready" "$T/agent-go"
44{ echo om2; cat $(./run.sh units); } > "$T/composed.om"
45python3 - "$T" "$ROOT" "$PORT" <<'PY'
46import sys
47from pathlib import Path
48p=Path(sys.argv[1]); root=sys.argv[2]; port=sys.argv[3]
49s=Path('research/publish.sh').read_text()
50s=s.replace('cd "$(dirname "$0")/.."', 'cd "'+root+'"')
51needle='# ATOMIC_PUBLIC_COMMIT:'
52assert s.count(needle)==1
53s=s.replace(needle, 'printf ready > "'+str(p)+'/publish-ready"\nread -r go < "'+str(p)+'/publish-go"\n'+needle)
54(p/'paused-publish.sh').write_text(s)
55s=(p/'composed.om').read_text().replace('text tfdata "/home/drakestapleton/forge-data/"', 'text tfdata "'+str(p)+'/data/"').replace('18480',port)
56# Only /research.json is paused, after rxhas and before fsend3 opens the returned path.
57needle='if not rxhas\nret 404\nend\nput fobl 0 0'
58assert s.count(needle)==1
59pause='''if fpeq txpj
60x = pgpause
61end
62'''
63s=s.replace(needle, 'if not rxhas\nret 404\nend\n'+pause+'put fobl 0 0')
64def seam(prefix):
65 return '''text pgready "'''+str(p)+'/'+prefix+'''-ready"
66text pggo "'''+str(p)+'/'+prefix+'''-go"
67text pgbyte "x"
68fn pgpause to long
69b = new uchar 1 0
70fd = fopen pgready 0 len pgready 1 0
71if lt fd 0
72ret fd
73end
74r = write int fd pgbyte 0 1
75r = fclose int fd
76fd = fopen pggo 0 len pggo 0 0
77if lt fd 0
78ret fd
79end
80r = read int fd b 0 1
81r = fclose int fd
82ret r
83end
84'''
85s+='\n'+seam('http')
86(p/'server.om').write_text(s)
87needle='for i ulong ulong k bound 4096\nffilc get v i\nend\nffilc 47'
88assert s.count(needle)==1
89(p/'mutant.om').write_text(s.replace(needle,'for i ulong len txcur bound 16\nffilc get txcur i\nend\nffilc 47'))
90s=Path('research/agent.om').read_text().replace('fn main to int','fn pgoldmain to int')
91needle='fd = fopen cpa 0 get cpl 0 524288 0\nif lt fd 0\nret false\nend\n'
92assert s.count(needle)==1
93s=s.replace(needle,needle+'pgr = pgpause\n')
94s+='\n'+seam('agent')+'''fn main to int
95put cpl 0 argp 2
96r = cload
97w = write 1 gc 0 get gcl 0
98ret 0
99end
100'''
101(p/'agent-read.om').write_text(s)
102PY
103"$OMC" < "$T/server.om" > "$T/server"; chmod 700 "$T/server"
104"$OMC" < "$T/mutant.om" > "$T/mutant"; chmod 700 "$T/mutant"
105"$OMC" < "$T/agent-read.om" > "$T/agent-read"; chmod 700 "$T/agent-read"
106FORGE_SOCIAL_DIR="$T/social/" INTERPLANE_SALVAGE_DIR="$T/slwork/" "$T/server" > "$T/server.log" 2>&1 & PID=$!
107for i in $(seq 1 60); do curl -s -o /dev/null "http://127.0.0.1:$PORT/" && break; sleep .1; done
108get(){ curl --fail -s "http://127.0.0.1:$PORT$1"; }
109get /research/fixture.json > "$T/served.json"
110check grep -q ATOMIC-OLD "$T/served.json"
111# Exercise the real forged research route and fsend3, not just its generated files. Curl writes
112# response bodies directly to disk: no shell/text normalization can hide a transport byte change.
113legacy_count=0
114mkdir "$T/legacy-http"
115while read -r expected leaf; do
116 case "$leaf" in
117 *.html) url=/research/${leaf%.html} ;;
118 *.json|*.bib) url=/research/$leaf ;;
119 *) bad "unexpected legacy oracle leaf $leaf"; continue ;;
120 esac
121 legacy_count=$((legacy_count+1))
122 if curl --fail -s --proxy '' --noproxy '*' --max-time 10 "http://127.0.0.1:$PORT$url" -o "$T/legacy-http/$leaf"; then
123 actual=$(sha256sum "$T/legacy-http/$leaf" | cut -d ' ' -f1)
124 if [ "$actual" = "$expected" ]; then ok "legacy HTTP bytes $url"; else bad "legacy HTTP byte drift $url expected=$expected actual=$actual"; fi
125 else
126 bad "legacy HTTP fetch $url"
127 fi
128done < "$T/legacy.sha"
129check test "$legacy_count" = 48
130for pair in '/research current/index.html' '/research.bib current/works.bib' '/research.txt current/agents.txt' '/assets/research.css current/research.css' '/research/authors/fixture-author current/a/fixture-author.html' '/research/add current/add.html' '/research/doi current/doi.html' '/research/fixture current/w/fixture.html' '/research/fixture.bib current/w/fixture.bib'; do
131 set -- $pair
132 get "$1" > "$T/route-body"
133 check cmp -s "$T/route-body" "$O/$2"
134done
135# Pin an HTTP path, and have the actual agent cload open the same old corpus inode.
136get /research.json > "$T/delayed.json" & HTTP=$!
137dd if="$T/http-ready" of=/dev/null bs=1 count=1 2>/dev/null
138"$T/agent-read" unused "$C" > "$T/delayed.corpus" & AGENT=$!
139dd if="$T/agent-ready" of=/dev/null bs=1 count=1 2>/dev/null
140fixture NEW
141sh "$T/paused-publish.sh" "$O" "$C" "$T/reg" >> "$T/publish.log" 2>&1 & PUB=$!
142for i in $(seq 1 100); do [ ! -f "$T/publish-ready" ] || break; kill -0 "$PUB"; sleep .1; done
143check test -f "$T/publish-ready"
144check test "$(readlink "$O/current")" = "$old"
145check cmp -s "$T/old.corpus" "$C"
146check cmp -s "$T/old.json" "$O/current/index.json"
147printf 'go\n' > "$T/publish-go"
148wait "$PUB"; PUB=
149new=$(readlink "$O/current")
150check test "$new" != "$old"
151check test -f "$O/$old/index.json"
152printf x > "$T/http-go"; printf x > "$T/agent-go"
153wait "$HTTP"; HTTP=; wait "$AGENT"; AGENT=
154check cmp -s "$T/old.json" "$T/delayed.json"
155check cmp -s "$T/old.corpus" "$T/delayed.corpus"
156get /research/fixture.json > "$T/new.json"
157check grep -q ATOMIC-NEW "$T/new.json"
158check grep -q ATOMIC-NEW "$C"
159# A new HTTP selection sees new bytes too, then delayed fsend3 consumes its pinned path.
160get /research.json > "$T/current.json" & HTTP=$!
161dd if="$T/http-ready" of=/dev/null bs=1 count=1 2>/dev/null
162printf x > "$T/http-go"; wait "$HTTP"; HTTP=
163check cmp -s "$O/current/index.json" "$T/current.json"
164fixture INTERRUPTED
165rm "$T/publish-ready"
166sh "$T/paused-publish.sh" "$O" "$C" "$T/reg" >> "$T/publish.log" 2>&1 & PUB=$!
167for i in $(seq 1 100); do [ ! -f "$T/publish-ready" ] || break; kill -0 "$PUB"; sleep .1; done
168check test -f "$T/publish-ready"
169kill -KILL "$PUB"; wait "$PUB" 2>/dev/null || :; PUB=
170check test "$(readlink "$O/current")" = "$new"
171get /research/fixture.json > "$T/after-kill.json"
172check cmp -s "$T/new.json" "$T/after-kill.json"
173check grep -q ATOMIC-NEW "$C"
174check test "$(cat "$O/ask/keep.html")" = 'answer stays'
175check test "$(cat "$O/add/queue")" = 'queue stays'
176# Restart completes a full generation without deleting any path a prior request pinned.
177publish
178check test -f "$O/$old/index.json"
179check test -f "$O/$new/index.json"
180check grep -q ATOMIC-INTERRUPTED "$C"
181# Actual HTTP negative control: replace only the pinned path with current/<leaf>.
182kill "$PID"; wait "$PID" 2>/dev/null || :; PID=
183FORGE_SOCIAL_DIR="$T/social/" INTERPLANE_SALVAGE_DIR="$T/slwork/" "$T/mutant" > "$T/mutant.log" 2>&1 & PID=$!
184for i in $(seq 1 60); do curl -s -o /dev/null "http://127.0.0.1:$PORT/" && break; sleep .1; done
185cp "$O/current/index.json" "$T/mutant-before.json"
186get /research.json > "$T/mutant-delayed.json" & HTTP=$!
187dd if="$T/http-ready" of=/dev/null bs=1 count=1 2>/dev/null
188fixture MUTANT
189publish
190printf x > "$T/http-go"; wait "$HTTP"; HTTP=
191if cmp -s "$T/mutant-before.json" "$T/mutant-delayed.json"; then bad 'A5 HTTP unpinned mutant escaped';
192elif cmp -s "$O/current/index.json" "$T/mutant-delayed.json"; then ok 'A5 HTTP unpinned mutant caught: late open crossed generation';
193else bad 'A5 HTTP mutant failed for unrelated reason'; fi
194# Text identity is selected with metadata. Neither a missing T nor '-' may reuse slug-only text.
195printf 'STALE-SLUG-ONLY\n' > "$T/reg/text/fixture.txt"
196sed '/^T[[:space:]]/d' "$T/reg/show/fixture.tsv" > "$T/no-t"
197cp "$T/no-t" "$T/reg/show/fixture.tsv"
198publish
199if grep -q '^@@.*fixture' "$C"; then bad 'missing T reused stale text'; else ok 'missing T omits foreign text'; fi
200printf 'T\tfixture\t-\n' >> "$T/reg/show/fixture.tsv"
201publish
202if grep -q '^@@.*fixture' "$C"; then bad 'T sentinel reused stale text'; else ok 'T sentinel omits foreign text'; fi
203# A cache whose content no longer matches its identity cannot activate a generation.
204fixture DIGEST
205printf 'tampered cache\n' > "$T/reg/text/fixture.$digest.txt"
206accepted=$(readlink "$O/current")
207rc=0; publish || rc=$?
208check test "$rc" = 1
209check test "$(readlink "$O/current")" = "$accepted"
210check grep -q 'text cache digest mismatch' "$T/publish.log"
211fixture VALID
212# Hostile BibTeX encoded commands are neutralized; the 48-file oracle above excludes drift.
213"$OMC" < research/build.om > "$T/build"; chmod 700 "$T/build"
214{ printf 'M\twbib\tescape\nW\tescape\t\t2026-01-01\tpreprint\tZenodo\t\t\t1\t1\t0\tcc\t^^5cinput{evil}~^^5cwrite18{evil}\n'; } | "$T/build" > "$T/escape.bib"
215if grep -Eq '\^|~|\\input|\\write18' "$T/escape.bib"; then bad 'encoded TeX command survives'; else ok 'caret pair and active tilde neutralized'; fi
216# T identity: duplicate or malformed identities cannot emit even a prefix of a document.
217for kind in duplicate short upper extra; do
218 sed '/^T[[:space:]]/d' "$T/reg/show/fixture.tsv" > "$T/t-catalog"
219 case $kind in
220 duplicate) printf 'T\tfixture\t%s\nT\tfixture\t%s\n' "$digest" "$digest" >> "$T/t-catalog" ;;
221 short) printf 'T\tfixture\tabc\n' >> "$T/t-catalog" ;;
222 upper) printf 'T\tfixture\t%s\n' "$(printf '%s' "$digest" | tr a-f A-F)" >> "$T/t-catalog" ;;
223 extra) printf 'T\tfixture\t%s\textra\n' "$digest" >> "$T/t-catalog" ;;
224 esac
225 { printf 'M\tmerge\n'; cat "$T/t-catalog"; } > "$T/bad-t"
226 rc=0; "$T/build" < "$T/bad-t" > "$T/bad-t.out" || rc=$?
227 check test "$rc" = 4
228 check test ! -s "$T/bad-t.out"
229done
230echo "PUBLICATION_RESULT pass=$pass fail=$fail"
231[ "$fail" = 0 ]