Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/interplane-forge/blob/main/server/tests/translate.sh # interplane-forge INTERPLANE Forge Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `interplane-forge / server / tests / translate.sh` 207 lines ยท 15179 bytes Raw Blame History 1 #!/usr/bin/env bash 2 # server/tests/translate.sh: gate for "readers translate with their own tools" (server/tr.om). 3 # bash server/tests/translate.sh (spark; FORGED_CPUS default 12-14; FORGE_TEST_PORT default 18495) 4 # bash server/tests/translate.sh --live the same response checks against https://interplane.io 5 # forged translates nothing and stores no translation. This gate proves the pages are safe to hand to 6 # any translator (the browser's own, an extension, a model the reader runs): 7 # 1. every response (HTML, JSON, plain text, raw files, errors, redirects) carries a 8 # Content-Security-Policy with script-src 'none', and no page holds a script or event attribute; 9 # 2. every HTML page: , every pre/code/kbd/samp inside translate="no", no hash or 10 # Radicle id in text a translator may change (oracle: server/tests/translate_check.py, Python's 11 # own HTML parser, not the Omega code under test); 12 # 3. a hostile translator that rewrites every translatable text node with commands, fake hashes 13 # and markup leaves every protected string, every link target and every hash/id byte-identical; 14 # 4. the hints change nothing else: each page's
minus the hints is byte-identical to the same 15 # page from this head built with the hint pass taken out of fsend0 (the send path before server/tr.om); 16 # 5. ?format=text answers text/plain with the same CSP, inline code in backticks, no markup; 17 # Negative controls (each must FAIL for its reason): a fixture page with a bare hash; a forged built 18 # without the translate="no" attribute (tftrno emptied); a forged whose page CSP lacks 19 # script-src 'none'; a hostile run on the fixture page; a hint pass that adds visible text (check 4). 20 # Positive control: a change to a page's words, made in both builds, passes check 4. Read-only on real storage; never 18480, 21 # ~/forge-data or 18091. 22 set -u 23 cd "$(dirname "$0")/../.." 24 ROOT=$(pwd) 25 CORES=${FORGED_CPUS:-12-14} 26 PORT=${FORGE_TEST_PORT:-18495} 27 OMC=$HOME/work/flux/omega-mv/seed/out/omc 28 PY=/usr/bin/python3 29 CHK=$ROOT/server/tests/translate_check.py 30 export GIT_ALLOW_PROTOCOL=file GIT_NO_LAZY_FETCH=1 GIT_TERMINAL_PROMPT=0 31 T=$(mktemp -d) 32 pid= 33 pass=0; fail=0 34 ok() { pass=$((pass+1)); echo "PASS $*"; } 35 bad() { fail=$((fail+1)); echo "FAIL $*"; } 36 cleanup() { [ -n "$pid" ] && kill "$pid" 2>/dev/null; wait 2>/dev/null; [ -n "${KEEP:-}" ] && echo "kept $T" || rm -rf "$T"; } 37 trap cleanup EXIT 38 # pages: owner/repo pages of real public repositories plus the shared pages; "raw" ones are files 39 R1=drakestapleton/aienux 40 R2=drakestapleton/interplane-forge 41 PAGES="explore $R1 $R2 $R1/tree/main $R1/blob/main/README.md $R2/blob/main/README.md $R1/commits $R1/branches $R1/releases $R1/patches $R1/issues search?q=omega no-such-owner/no-such-repo" 42 RAWS="$R1/raw/main/README.md $R1.json explore.json" 43 44 # hdrcsp FILE: the Content-Security-Policy values of a saved header block, one per line 45 hdrcsp() { tr -d '\r' < "$1" | sed -n 's/^[Cc]ontent-[Ss]ecurity-[Pp]olicy: //p'; } 46 # cspok FILE WHAT: exactly one CSP header and it says script-src 'none' 47 cspok() { 48 local n 49 n=$(hdrcsp "$1" | wc -l) 50 if [ "$n" -lt 1 ]; then bad "$2: no Content-Security-Policy"; return 1; fi 51 if hdrcsp "$1" | grep -qv "script-src 'none'"; then bad "$2: a CSP without script-src 'none': $(hdrcsp "$1" | head -1)"; return 1; fi 52 ok "$2: CSP has script-src 'none'" 53 } 54 # fetch URLBASE PATH OUT [curl args]: body OUT, headers OUT.h, prints the status 55 fetch() { local u=$1 p=$2 o=$3; shift 3; curl -s --max-time 30 -o "$o" -D "$o.h" -w '%{http_code}' "$@" "$u/$p"; } 56 57 # respchecks URLBASE TAG [curl args]: checks 1, 2, 3 and 5 on every page of PAGES and RAWS 58 respchecks() { 59 local u=$1 tg=$2; shift 2 60 local i=0 p st f 61 for p in $PAGES; do 62 i=$((i+1)); f=$T/$tg-$i.html 63 st=$(fetch "$u" "$p" "$f" "$@") 64 case $st in 200|404) ;; *) bad "$tg $p: HTTP $st"; continue ;; esac 65 cspok "$f.h" "$tg $p ($st)" 66 if "$PY" "$CHK" check "$f" > "$f.chk"; then ok "$tg $p: hints ($(cut -d' ' -f3- "$f.chk"))"; else bad "$tg $p: $(head -3 "$f.chk" | tr '\n' ' ')"; fi 67 if "$PY" "$CHK" hostile "$f" "$f.hostile" > "$f.hos"; then ok "$tg $p: $(cut -d' ' -f3- "$f.hos")"; else bad "$tg $p: $(head -3 "$f.hos" | tr '\n' ' ')"; fi 68 echo "$p $f" >> "$T/$tg.list" 69 done 70 for p in $RAWS; do 71 i=$((i+1)); f=$T/$tg-$i.raw 72 st=$(fetch "$u" "$p" "$f" "$@") 73 [ "$st" = 200 ] || { bad "$tg $p: HTTP $st"; continue; } 74 cspok "$f.h" "$tg $p" 75 done 76 # a redirect (rad: shortcut) and a POST refusal carry the policy too 77 st=$(fetch "$u" "login" "$T/$tg-post" -X POST "$@"); cspok "$T/$tg-post.h" "$tg POST /login ($st)" 78 # 5. the plain-text form 79 f=$T/$tg-text.txt 80 st=$(fetch "$u" "$R1?format=text" "$f" "$@") 81 [ "$st" = 200 ] || bad "$tg $R1?format=text: HTTP $st" 82 cspok "$f.h" "$tg $R1?format=text" 83 ct=$(tr -d '\r' < "$f.h" | sed -n 's/^[Cc]ontent-[Tt]ype: //p') 84 [ "$ct" = "text/plain; charset=utf-8" ] && ok "$tg text: content type $ct" || bad "$tg text: content type '$ct'" 85 grep -qE '`[^`]+`' "$f" && ok "$tg text: inline code in backticks" || bad "$tg text: no inline code in backticks" 86 grep -qE '<(p|div|a|span|code|pre|table|section|main|h[1-6])[ >]' "$f" && bad "$tg text: HTML markup left in the text" || ok "$tg text: no HTML markup" 87 head -1 "$f" | grep -q '^Interplane page as plain text' && ok "$tg text: preface line" || bad "$tg text: no preface" 88 grep -q '^# ' "$f" && ok "$tg text: README headings as #" || bad "$tg text: no # heading" 89 # file names in the breadcrumb (bay 1 finding 1 at `099a4b0b`) and the footer link keeps the query (finding 3) 90 f=$T/$tg-crumbs.html; fetch "$u" "$R1/blob/main/README.md" "$f" "$@" > /dev/null 91 grep -q '

' "$f" && ok "$tg blob page: breadcrumb marked translate=no" || bad "$tg blob page: breadcrumb not marked" 92 f=$T/$tg-crumbs.txt; fetch "$u" "$R1/blob/main/README.md?format=text" "$f" "$@" > /dev/null 93 grep -qE '^`[^`]*README\.md[^`]*`$' "$f" && ok "$tg text form: breadcrumb in backticks" || bad "$tg text form: breadcrumb not in backticks" 94 f=$T/$tg-tree.txt; fetch "$u" "$R1/tree/main?format=text" "$f" "$@" > /dev/null 95 # one row per line inside the fence: name, link target, size, each apart 96 awk '/^```$/{fz=!fz; next} fz && /^README\.md <\/[^ >]*\/blob\/main\/README\.md> [0-9]+$/{f=1} fz && /^\.aien\/ <\/[^ >]*\/tree\/main\/\.aien>$/{d=1} END{exit !(f && d)}' "$f" && ok "$tg text form: file list fenced, one row per line" || bad "$tg text form: file list not fenced as rows" 97 f=$T/$tg-q.html; fetch "$u" "search?q=omega" "$f" "$@" > /dev/null 98 grep -q 'search?q=omega&format=text" rel="alternate"' "$f" && ok "$tg footer: plain-text link keeps the query" || bad "$tg footer: plain-text link drops the query" 99 f=$T/$tg-q.txt; fetch "$u" "search?q=omega&format=text" "$f" "$@" > /dev/null 100 head -1 "$f" | grep -q '^Interplane page as plain text' && ok "$tg text form of a query page" || bad "$tg text form of a query page" 101 # script-free: the HTML and the text never name a script 102 if grep -l -i '/dev/null | grep -q .; then bad "$tg: a page holds "$o.om" 125 if [ -n "$m" ]; then 126 cp "$o.om" "$o.om.0"; sed -i -e "$m" "$o.om" 127 cmp -s "$o.om.0" "$o.om" && { echo "MUTANT did not apply: $m"; exit 3; } 128 fi 129 taskset -c "$CORES" nice -n 10 "$OMC" < "$o.om" > "$o" 2> "$o.err" || { echo "BUILD FAILED $d ${m:+mutant $m}: $(cat "$o.err")"; exit 1; } 130 chmod 755 "$o" 131 } 132 start() { taskset -c "$CORES" nice -n 10 "$1" 2>> "$T/forged.err" & pid=$!; for _ in $(seq 100); do curl -s -o /dev/null "http://127.0.0.1:$PORT/explore" && return 0; sleep 0.1; done; echo "server did not start"; cat "$T/forged.err"; exit 1; } 133 stop() { kill "$pid" 2>/dev/null; wait "$pid" 2>/dev/null; pid=; } 134 L=http://127.0.0.1:$PORT 135 136 compose "$ROOT" "$T/forged" "$PORT" 137 compose "$ROOT" "$T/forged.base" "$PORT" "$NOHINT" 138 [ "$(grep -c 'ftrrun cs io' "$T/forged.base.om")" = 0 ] || { echo "FAIL the comparison build still calls ftrrun"; exit 1; } 139 echo "built head $(sha256sum < "$T/forged" | cut -c1-16), head without hints $(sha256sum < "$T/forged.base" | cut -c1-16)" 140 141 for b in / /forge/; do 142 tg=head$(echo "$b" | tr -d /) 143 start "$T/forged" 144 respchecks "$L" "$tg" -H "X-Forge-Base: $b" -H "X-Real-IP: 127.0.0.1" 145 stop 146 done 147 148 # 4. the hints change nothing else:

of every page equals the base build's minus the hints 149 start "$T/forged.base" 150 i=0 151 while read -r p f; do 152 i=$((i+1)) 153 fetch "$L" "$p" "$T/base-$i.html" -H "X-Forge-Base: /" -H "X-Real-IP: 127.0.0.1" > /dev/null 154 "$PY" "$CHK" strip "$f" "$f.strip" 155 mh=$(awk '/
/{on=0}' "$f.strip" | sha256sum | cut -c1-16) 156 mb=$(awk '/
/{on=0}' "$T/base-$i.html" | sha256sum | cut -c1-16) 157 # the counts lines move with the logs between the two reads; compare without them 158 mh2=$(awk '/
/{on=0}' "$f.strip" | grep -v '^

\(Clones\|Downloads\|Seeding\)' | sha256sum | cut -c1-16) 159 mb2=$(awk '/

/{on=0}' "$T/base-$i.html" | grep -v '^

\(Clones\|Downloads\|Seeding\)' | sha256sum | cut -c1-16) 160 if [ "$mh" = "$mb" ] || [ "$mh2" = "$mb2" ]; then ok "unchanged $p:

minus hints = base ($mh2)"; else bad "changed $p:
minus hints $mh2, base $mb2"; diff <(awk '/
/{on=0}' "$f.strip") <(awk '/
/{on=0}' "$T/base-$i.html") | head -6; fi 161 done < "$T/head.list" 162 stop 163 164 # ---- negative controls 165 fx=$T/fixture.html 166 printf '\n

Head `95d5f03` and bare `95d5f03ed369f8e2` here.

\n' > "$fx" 167 if "$PY" "$CHK" check "$fx" > "$T/neg1" 2>&1; then bad "NEG fixture with a bare hash passed the oracle"; else grep -q 'translatable text holds `95d5f03ed369f8e2`' "$T/neg1" && ok "NEG fixture with a bare hash: refused ($(head -1 "$T/neg1"))" || bad "NEG fixture refused for another reason: $(head -1 "$T/neg1")"; fi 168 if "$PY" "$CHK" hostile "$fx" "$fx.h" > "$T/neg2" 2>&1; then bad "NEG hostile on the fixture passed"; else grep -q 'hash or id lost' "$T/neg2" && ok "NEG hostile translator on the fixture changes the bare hash: caught" || bad "NEG hostile refused for another reason: $(head -1 "$T/neg2")"; fi 169 printf '\n
rad clone rad:`z3KFmLGeYdvDAgwpCgdBd1ENW7nU5`
\n' > "$T/fx2.html" 170 if "$PY" "$CHK" check "$T/fx2.html" > "$T/neg3" 2>&1; then bad "NEG fixture with an unmarked pre passed"; else grep -q '
 outside' "$T/neg3" && ok "NEG fixture with an unmarked pre: refused" || bad "NEG pre refused for another reason: $(head -1 "$T/neg3")"; fi

171

172 compose "$ROOT" "$T/forged.m1" "$PORT" 's/^text tftrno ".*"$/text tftrno " data-x=\\"no\\""/'

173 start "$T/forged.m1"

174 fetch "$L" "$R1" "$T/m1.html" -H "X-Forge-Base: /" -H "X-Real-IP: 127.0.0.1" > /dev/null

175 stop

176 if "$PY" "$CHK" check "$T/m1.html" > "$T/neg4" 2>&1; then bad "NEG forged without translate=\"no\" passed"; else ok "NEG forged without translate=\"no\": refused ($(grep -c FAIL "$T/neg4") findings, first: $(head -1 "$T/neg4" | cut -d: -f2-))"; fi

177

178 compose "$ROOT" "$T/forged.m2" "$PORT" "s/^text tfcsp \"default-src 'none'; style-src 'self'; img-src 'self'; script-src 'none'; /text tfcsp \"default-src 'none'; style-src 'self'; img-src 'self'; /"

179 start "$T/forged.m2"

180 fetch "$L" "$R1" "$T/m2.html" -H "X-Forge-Base: /" -H "X-Real-IP: 127.0.0.1" > /dev/null

181 stop

182 p0=$pass f0=$fail

183 cspok "$T/m2.html.h" "mutant" > "$T/neg5"

184 if [ "$fail" -gt "$f0" ]; then fail=$f0; pass=$p0; ok "NEG forged whose page CSP lacks script-src 'none': refused ($(cut -d: -f2- "$T/neg5"))"; else pass=$p0; bad "NEG forged without script-src 'none' passed the CSP check"; fi

185

186 # check 4's controls, on the build under test and its build without the hint pass

187 # main4 FILE: 
of a page without the counts lines, which move with the logs between two reads 188 main4() { awk '/
/{on=0}' "$1" | grep -v '^

\(Clones\|Downloads\|Seeding\)'; } 189 # same4 HINTED PLAIN: HINTED minus the hints has the same

as PLAIN 190 same4() { "$PY" "$CHK" strip "$1" "$1.strip" && [ "$(main4 "$1.strip" | sha256sum)" = "$(main4 "$2" | sha256sum)" ]; } 191 # page4 BIN OUT: R1 from that build 192 page4() { start "$1"; fetch "$L" "$R1" "$2" -H "X-Forge-Base: /" -H "X-Real-IP: 127.0.0.1" > /dev/null; stop; } 193 compose "$ROOT" "$T/forged.m3" "$PORT" 's|^text tftrsp ""$|text tftrsp "*"|' 194 page4 "$T/forged.m3" "$T/m3.html"; page4 "$T/forged.base" "$T/b3.html" 195 if ! grep -q '\*' "$T/m3.html"; then bad "NEG hint pass that adds visible text: not run, $R1 holds no hint span" 196 elif same4 "$T/m3.html" "$T/b3.html"; then bad "NEG hint pass that adds visible text (a * in every hint span) passed check 4" 197 else ok "NEG hint pass that adds visible text (a * in every hint span): caught by check 4"; fi 198 LEGIT='s|>For developers: proof and records|>Records and proof, for developers|' 199 compose "$ROOT" "$T/forged.m4" "$PORT" "$LEGIT" 200 compose "$ROOT" "$T/forged.m4b" "$PORT" "$NOHINT;$LEGIT" 201 page4 "$T/forged.m4" "$T/m4.html"; page4 "$T/forged.m4b" "$T/m4b.html" 202 if ! grep -q 'Records and proof, for developers' "$T/m4.html"; then bad "POS legitimate page change: not run, the changed words are not on $R1" 203 elif same4 "$T/m4.html" "$T/m4b.html"; then ok "POS a legitimate change to a page's words (developer heading) passes check 4" 204 else bad "POS a legitimate change to a page's words failed check 4"; fi 205 206 echo "translate.sh: pass=$pass fail=$fail (head $(git rev-parse --short HEAD); comparison: the same head without the hint pass)" 207 [ "$fail" = 0 ]