interplane.Get Omega
Read in your language

interplane-forge

INTERPLANE Forge

Brought by drakestapleton

branch main Branches Tags History

interplane-forge / research / tests / run.sh

121 lines · 11348 bytes Raw Blame History
1#!/bin/sh
2# research/tests/run.sh: gates for the research builder and the research agent. Private temp dir,
3# no port, no model call, nothing under ~/forge-data. Refuses any compiler but the pin (exit 2).
4# sh research/tests/run.sh -> RESULT pass=N fail=0
5# Negative controls: a builder with the "<" escape removed must print the planted markup; an agent
6# given a queue line whose id is not hex must write nothing for it.
7set -u
8export LC_ALL=C
9cd "$(dirname "$0")/../.."
10OMC=$HOME/work/flux/omega-mv/seed/out/omc
11PIN=3ad9f10f64309e7acf8a725082b28e23a2a4aeb07e98322fb4dc0fcd8fc93194
12[ "$(sha256sum "$OMC" | cut -d' ' -f1)" = "$PIN" ] || { echo "omc is not the pin"; exit 2; }
13T=$(mktemp -d /tmp/research-gate.XXXXXX)
14trap 'rm -rf "$T"' EXIT HUP INT TERM
15pass=0; fail=0
16ok() { pass=$((pass + 1)); echo "PASS $*"; }
17bad() { fail=$((fail + 1)); echo "FAIL $*"; }
18is() { if [ "$1" = "$2" ]; then ok "$3 ($1)"; else bad "$3: want $2, got $1"; fi; }
19C=research/registry/catalog.tsv
20"$OMC" < research/build.om > "$T/build" && chmod 700 "$T/build" && ok "builder compiles" || bad "builder does not compile"
21"$OMC" < research/agent.om > "$T/agent" && chmod 700 "$T/agent" && ok "agent compiles" || bad "agent does not compile"
22gen() { { printf 'M\t%s\t%s\n' "$1" "${2:-}"; cat "${3:-$C}"; } | "$T/build"; }
23
24# ---- the registry as published
25gen slugs > "$T/slugs"
26is "$(wc -l < "$T/slugs" | tr -d ' ')" "$(grep -c '^W ' $C)" "one slug per work"
27gen index > "$T/index.html"; gen json > "$T/index.json"
28python3 -I - "$T/index.json" "$C" > "$T/totals" 2>&1 <<'PY'
29import json, sys
30d = json.load(open(sys.argv[1])); rows = [l.rstrip("\n").split("\t") for l in open(sys.argv[2])]
31w = [r for r in rows if r[0] == "W"]
32print(len(d["works"]) == len(w), sum(x["versions"] for x in d["works"]) == sum(1 for r in rows if r[0] == "V"),
33 len(d["relations"]) == sum(1 for r in rows if r[0] == "E"), sum(1 for x in d["works"] if x["on_orcid"]) == sum(1 for r in w if r[10] == "1"),
34 all(x["doi"] == r[6] and x["slug"] == r[1] for x, r in zip(d["works"], w)))
35PY
36is "$(cat "$T/totals")" "True True True True True" "index.json agrees with the registry: works, versions, relations, ORCID marks, DOIs"
37n=0; badj=0; miss=0
38while read -r s; do
39 gen work "$s" > "$T/w.html" || miss=$((miss + 1))
40 gen wjson "$s" > "$T/w.json" || miss=$((miss + 1))
41 gen wbib "$s" > "$T/w.bib" || miss=$((miss + 1))
42 python3 -I -c 'import json,sys; json.load(open(sys.argv[1]))' "$T/w.json" 2> /dev/null || badj=$((badj + 1))
43 grep -q "href='https://doi.org/" "$T/w.html" || miss=$((miss + 1))
44 [ -s research/registry/text/$s.txt ] || miss=$((miss + 1))
45 n=$((n + 1))
46done < "$T/slugs"
47is "$badj $miss" "0 0" "every work builds its page, JSON and BibTeX, links its DOI and has full text ($n works)"
48is "$(cat "$T/index.html" "$T/w.html" | grep -c -i -E '<script|javascript:| on[a-z]+=|style=')" 0 "no script, handler or inline style in the pages"
49NAVL="<a href='/open/'>Open builds</a><a href='/salvage/'>Bring your build</a></nav>"
50is "$(grep -c -F "$NAVL" "$T/index.html")" 1 "the index header links to the shelf and the submission page"
51is "$(grep -c -F "$NAVL" "$T/w.html")" 1 "a work page header links to them too"
52gen css > "$T/css"; is "$(grep -c -i -E '#[0-9a-f]{3,8}[;} ]|rgb\(|hsl\(' "$T/css")" 0 "the stylesheet takes every colour from the tokens"
53rc=0; gen work no-such-work > /dev/null 2>&1 || rc=$?; is "$rc" 3 "an unknown slug is refused"
54rc=0; gen nonsense > /dev/null 2>&1 || rc=$?; is "$rc" 2 "an unknown mode is refused"
55rc=0; gen work '../x' > /dev/null 2>&1 || rc=$?; is "$rc" 3 "a slug with a path in it is refused"
56
57# ---- escaping, with a planted hostile row
58{ printf 'O\tname\tA <b>"name"</b>\nO\torcid\t0000-0000-0000-0000\nH\tt1\tThread <i>\tBlurb\n'
59 printf 'W\tevil\tt1\t2026-01-01\tpreprint\tZenodo\t10.1/a\t10.1/b\t1\t1\t0\tcc\tTitle <script>alert(1)</script> "q" \\ end\n'
60 printf 'S\tevil\tSummary & <img src=x onerror=1>\nA\tevil\tAbstract </p><script>\nC\tevil\tAn {Author}\nL\tevil\treferences\tjavascript:alert(1)\nL\tevil\treferences\thttps://example.org/a"b\n'; } > "$T/evil.tsv"
61gen work evil "$T/evil.tsv" > "$T/evil.html"; gen wjson evil "$T/evil.tsv" > "$T/evil.json"; gen wbib evil "$T/evil.tsv" > "$T/evil.bib"
62is "$(grep -c -E '<script|<img|<b>|<i>' "$T/evil.html")" 0 "planted markup is escaped in the page"
63grep -q '&lt;script&gt;alert(1)&lt;/script&gt;' "$T/evil.html" && ok "the planted title is shown as text" || bad "the planted title is missing"
64is "$(grep -c 'javascript:' "$T/evil.html")" 0 "a link that is not https is not written"
65python3 -I -c 'import json,sys; d=json.load(open(sys.argv[1])); sys.exit(0 if "<script>alert(1)</script>" in d["work"]["title"] and "\\" in d["work"]["title"] else 1)' "$T/evil.json" && ok "the JSON twin carries the same title, validly escaped" || bad "the JSON twin is wrong"
66is "$(grep -c '[{}].*Author' "$T/evil.bib")" 1 "BibTeX drops braces inside a value"
67# negative control: the builder without the "<" escape prints the markup
68sed 's/^em tlt$/emb 60/' research/build.om | "$OMC" > "$T/mutant" 2> /dev/null && chmod 700 "$T/mutant"
69{ printf 'M\twork\tevil\n'; cat "$T/evil.tsv"; } | "$T/mutant" > "$T/mutant.html"
70[ "$(grep -c '<script' "$T/mutant.html")" -ge 1 ] && ok "NEG a builder without the escape is caught by the same check" || bad "NEG the mutant was not caught"
71
72# ---- the agent, without a model: a question none of whose words is in the works needs no model call
73mkdir -m 700 "$T/ask" "$T/state"
74{ printf '@@\talpha\tThe Alpha Work\nThe quick brown fox jumps over the lazy dog near the river bank.\n@@\tbeta\tBeta Notes\nA second work about lanterns and harbours.\n'; } > "$T/corpus"
75A=00000000000000000000000000000001; B=00000000000000000000000000000002
76{ printf '%s\tzzqqxx vvwwkk?\n' "$A"; printf 'NOT-A-HEX-ID-NOT-A-HEX-ID-NOT-A-H\tlanterns\n'; printf 'short\n'; printf '%s\t<b>zzqqxx</b> & "vvwwkk"\n' "$B"; } > "$T/ask/queue"
77rc=0; "$T/agent" "$T/ask/" "$T/corpus" "$T/state/offset" once || rc=$?
78is "$rc" 0 "the agent handles the queue and exits"
79is "$(cat "$T/state/offset")" "$(wc -c < "$T/ask/queue" | tr -d ' ')" "the saved offset is the end of the queue"
80grep -q 'No passage in the published work matches' "$T/ask/$A.html" 2> /dev/null && ok "a question with no matching word gets the fixed answer, no model" || bad "no fixed answer"
81python3 -I -c 'import json,sys; d=json.load(open(sys.argv[1])); sys.exit(0 if d["status"]=="answered" and d["sources"]==[] and d["question"]=="<b>zzqqxx</b> & \"vvwwkk\"" else 1)' "$T/ask/$B.json" && ok "the answer JSON is valid and carries the question exactly" || bad "answer JSON wrong"
82is "$(grep -c '<b>' "$T/ask/$B.html")" 0 "the question is escaped in the answer page"
83is "$(grep -c -F "$NAVL" "$T/ask/$B.html")" 1 "the answer page header links to the shelf and the submission page"
84is "$(ls "$T/ask" | grep -c -v -E "^($A|$B)\.(html|json)$|^queue$")" 0 "NEG a line whose id is not hex, and a short line, wrote nothing"
85cp "$T/ask/$A.html" "$T/first"; rc=0; "$T/agent" "$T/ask/" "$T/corpus" "$T/state/offset" once || rc=$?
86cmp -s "$T/first" "$T/ask/$A.html" && ok "a second run changes nothing" || bad "a second run rewrote an answer"
87rc=0; "$T/agent" "$T/ask" "$T/corpus" "$T/state/offset" once || rc=$?; is "$rc" 2 "an ask folder without the final slash is refused"
88# one-word questions of 65 and 200 bytes (route.om allows up to 300) must not stop the agent: before
89# the isstop guard they trapped 4, which leaves the offset before the line, so the restarted service
90# trapped on it again for ever
91L=00000000000000000000000000000003; M=00000000000000000000000000000004
92printf '%s\t%s\n%s\t%s\n' "$L" "$(printf 'q%.0s' $(seq 65))" "$M" "$(printf 'q%.0s' $(seq 200))" >> "$T/ask/queue"
93rc=0; "$T/agent" "$T/ask/" "$T/corpus" "$T/state/offset" once || rc=$?
94is "$rc $(cat "$T/state/offset")" "0 $(wc -c < "$T/ask/queue" | tr -d ' ')" "long one-word questions are handled and the offset passes them"
95is "$(grep -l 'No passage in the published work matches' "$T/ask/$L.html" "$T/ask/$M.html" 2> /dev/null | wc -l | tr -d ' ')" 2 "the long-word questions get the fixed answer"
96# a question with bytes that are not UTF-8 (forged passes %FF through): the answer JSON must still be
97# UTF-8 JSON; a well-formed character is kept, each stray byte becomes "?"
98U=00000000000000000000000000000005; printf '%s\tzzqqxx \377\376 vvwwkk \303\251\355\240\200\n' "$U" >> "$T/ask/queue"
99rc=0; "$T/agent" "$T/ask/" "$T/corpus" "$T/state/offset" once || rc=$?
100python3 -I -c 'import json,sys; d=json.load(open(sys.argv[1], encoding="utf-8")); sys.exit(0 if d["question"]=="zzqqxx ?? vvwwkk \u00e9???" else 1)' "$T/ask/$U.json" 2> /dev/null && ok "a question with stray bytes gives UTF-8 JSON, each stray byte a ?" || bad "the answer JSON is not UTF-8 or the question changed"
101# New author, metadata, intake and local DOI boundaries. Each module reports its own RESULT.
102. research/tests/authors.sh
103. research/tests/prompt.sh
104if sh research/tests/sync.sh; then ok "public metadata sync fixture module"; else bad "sync fixture module"; fi
105if sh research/tests/intake.sh; then ok "signed shelf intake fixture module"; else bad "intake fixture module"; fi
106if RESEARCH_TEST_PORT=19465 RESEARCH_INTAKE_FAULT=writefail sh research/tests/intake.sh; then ok "A3 truthful recoverable partial shelf acceptance"; else bad "A3 partial acceptance module"; fi
107rc=0; RESEARCH_TEST_PORT=19466 RESEARCH_INTAKE_MUTANT=A3 sh research/tests/intake.sh > "$T/a3-negative.log" 2>&1 || rc=$?
108if [ "$rc" = 1 ] && grep -q 'FAIL intake A3 SHELF_EFFECT_AFTER_QUEUE_REFUSAL' "$T/a3-negative.log" && ! grep -q '^omc:' "$T/a3-negative.log"; then ok "MUTANT A3 caught as shelf effect after queue refusal"; else cat "$T/a3-negative.log"; bad "A3 negative control wrong reason"; fi
109if sh research/tests/review.sh; then ok "review A/B transactional and authority regression module"; else bad "review A/B regression module"; fi
110if sh research/tests/json.sh; then ok "strict JSON numeric decoder module"; else bad "JSON numeric decoder module"; fi
111if sh research/tests/bundles.sh; then ok "per-bundle requester eligibility and duplicate-licence module"; else bad "bundle eligibility module"; fi
112if sh research/tests/profile-round4.sh; then ok "lossless profile association and cross-copy takedown helper module"; else bad "profile/evidence layout module"; fi
113if sh research/tests/overlap.sh; then ok "exact DOI/ORCID overlap workflow in both input orders"; else bad "DOI/ORCID overlap module"; fi
114if sh research/tests/binding-control.sh; then ok "stale cache binding oracle and executable reuse mutant"; else bad "stale binding module"; fi
115if sh research/tests/refresh-transport.sh; then ok "direct refresh, repeated PDF, literal transport and final removal module"; else bad "refresh/transport module"; fi
116if sh research/tests/publication.sh; then ok "atomic public-generation and reader/crash module"; else bad "public generation module"; fi
117if sh research/tests/passages.sh; then ok "lossless UTF8 passages and request reconstruction module"; else bad "UTF8 passage module"; fi
118if sh research/tests/decode.sh; then ok "bounded decoder process-tree module"; else bad "bounded decoder module"; fi
119if bash tools/doi/tests/run.sh; then ok "local DOI fixture module (real deposit NOT_RUN)"; else bad "DOI fixture module"; fi
120echo "RESULT pass=$pass fail=$fail"
121[ "$fail" = 0 ]