interplane.Get Omega
Read in your language

interplane-forge

INTERPLANE Forge

Brought by drakestapleton

branch main Branches Tags History

interplane-forge / galaxy / tests / run.sh

142 lines · 7397 bytes Raw Blame History
1#!/bin/sh
2# galaxy/tests/run.sh: gate for the galaxy filter (page.om + cli.om, the INTERPLANE front page).
3# OMC=/abs/seed/out/omc sh galaxy/tests/run.sh
4# Composes the two units, builds them with the pinned omc, runs the filter on tests/feed.tsv and
5# checks the page it prints.
6# Negative controls: a hostile input must come out escaped, and a mutant with the escape removed
7# must FAIL that same check. Exit 0 only when every check passes; 2 on a compiler pin mismatch.
8set -u
9HERE=$(cd "$(dirname "$0")" && pwd)
10G=$HERE/..
11OMC=${OMC:-$HOME/work/flux/omega-mv/seed/out/omc}
12PIN=3ad9f10f64309e7acf8a725082b28e23a2a4aeb07e98322fb4dc0fcd8fc93194
13T=$(mktemp -d) || exit 2
14trap 'rm -rf "$T"' EXIT
15SRC=$T/galaxy.om
16cat "$G/page.om" "$G/cli.om" >"$SRC"
17pass=0
18fail=0
19ok() { pass=$((pass + 1)); echo "PASS $1"; }
20no() { fail=$((fail + 1)); echo "FAIL $1"; }
21eq() { if [ "$2" = "$3" ]; then ok "$1"; else no "$1: got '$2' want '$3'"; fi; }
22count() { grep -o "$1" "$2" | wc -l | tr -d ' '; }
23
24got=$(sha256sum "$OMC" 2>/dev/null | cut -d' ' -f1)
25if [ "$got" != "$PIN" ]; then
26 echo "compiler pin mismatch: $got" >&2
27 exit 2
28fi
29"$OMC" <"$SRC" >"$T/galaxy" 2>"$T/omc.err"
30eq "compile exit" "$?" 0
31chmod +x "$T/galaxy"
32
33"$T/galaxy" <"$HERE/feed.tsv" >"$T/page.html"
34eq "page exit" "$?" 0
35eq "no script element" "$(grep -ci '<script' "$T/page.html")" 0
36eq "no inline handler" "$(grep -ci ' on[a-z]*=' "$T/page.html")" 0
37eq "stars equal R lines, less the retired-network name" "$(count "class='st " "$T/page.html")" "$(awk -F'\t' '$1=="R" && tolower($2) !~ /radicle|heartwood/' "$HERE/feed.tsv" | wc -l | tr -d ' ')"
38eq "hive cells" "$(count "class='cell'" "$T/page.html")" 10
39eq "feed names a retired network (control)" "$(grep -ci 'radicle' "$HERE/feed.tsv")" 1
40eq "no retired-network words on the page" "$(grep -ciE 'radicle|heartwood|rad:z|/rad/|rad (clone|init|sync|id|patch|auth)' "$T/page.html")" 0
41eq "its station is printed as Retired" "$(count "y='-22'>Retired</text>" "$T/page.html")" 1
42eq "merge rows equal M lines" "$(count '<li><a ' "$T/page.html")" "$(awk -F'\t' '$1=="M"' "$HERE/feed.tsv" | wc -l | tr -d ' ')"
43want=$(awk -F'\t' '$1=="K" && ($2=="waiting" || $2=="approved") {n += $3} END {print n + 0}' "$HERE/feed.tsv")
44eq "ring dots equal waiting plus approved" "$(count "class='pl'" "$T/page.html")" "$want"
45eq "headline present" "$(grep -c 'NVIDIA hardware compatible. CUDA not required.' "$T/page.html")" 1
46eq "scope line present" "$(grep -c 'Other chips: not run.' "$T/page.html")" 1
47
48"$T/galaxy" <"$HERE/feed.tsv" >"$T/page2.html"
49eq "same input, same bytes" "$(sha256sum <"$T/page.html")" "$(sha256sum <"$T/page2.html")"
50
51printf 'css\n' | "$T/galaxy" >"$T/galaxy.css"
52eq "css exit" "$?" 0
53eq "css has no markup" "$(grep -c '<' "$T/galaxy.css")" 0
54eq "css types no colour" "$(grep -Eci '#[0-9a-f]{3,8}[;}]|rgba?\(|hsla?\(' "$T/galaxy.css")" 0
55
56# hostile input: every field carries markup and a quote. <u> and <em> never occur in the page itself.
57printf 'K\tdelivered\t<script>x</script>\nS\t<u>a b\t1\t1\nR\t"><script>alert(1)</script>\tcore\nM\t<em>r\t'"'"'onx\t<script>\n' >"$T/evil.tsv"
58"$T/galaxy" <"$T/evil.tsv" >"$T/evil.html"
59eq "hostile exit" "$?" 0
60eq "hostile input stays text" "$(grep -ci '<script\|<u>\|<em>' "$T/evil.html")" 0
61eq "hostile quote cannot close an attribute" "$(grep -c "='[^']*'onx" "$T/evil.html")" 0
62
63# an apostrophe prints as an apostrophe (&#39;), never as a double quote
64printf "R\tDrake's\tcore\n" >"$T/apos.tsv"
65"$T/galaxy" <"$T/apos.tsv" >"$T/apos.html"
66eq "apostrophe exit" "$?" 0
67eq "apostrophe stays an apostrophe" "$(grep -c '<title>Drake&#39;s</title>' "$T/apos.html")" 1
68
69# a cut at 64 bytes never splits a UTF-8 character: 63 'a' then a 2-byte e-acute prints 63 'a'
70awk 'BEGIN { printf "R\t"; for (i = 0; i < 63; i++) printf "a"; printf "\303\251zz\tcore\n" }' >"$T/utf8.tsv"
71"$T/galaxy" <"$T/utf8.tsv" >"$T/utf8.html"
72eq "UTF-8 cut exit" "$?" 0
73eq "UTF-8 cut keeps whole characters" "$(LC_ALL=C grep -c '<title>a\{63\}</title>' "$T/utf8.html")" 1
74
75# empty input: the page still renders and says what it could not read
76: | "$T/galaxy" >"$T/empty.html"
77eq "empty exit" "$?" 0
78eq "empty says not read" "$(count 'not read' "$T/empty.html")" 5
79
80# limits (review probes of head 37ec0fb6 gave an empty page: exit 104 past 4,096 lines, 103 on a
81# 60,000-byte name). The page must still print, with the documented caps.
82{ printf 'K\tdelivered\t9\n'; awk 'BEGIN { for (i = 0; i < 5000; i++) print "x" }'; } >"$T/lines.tsv"
83"$T/galaxy" <"$T/lines.tsv" >"$T/lines.html"
84eq "5,001 lines exit" "$?" 0
85eq "5,001 lines still print the figure" "$(grep -c '<dd>9</dd>' "$T/lines.html")" 1
86awk 'BEGIN { printf "R\t"; for (i = 0; i < 60000; i++) printf "a"; printf "\tcore\n" }' >"$T/long.tsv"
87"$T/galaxy" <"$T/long.tsv" >"$T/long.html"
88eq "60,000-byte name exit" "$?" 0
89eq "60,000-byte name is cut to 64" "$(grep -o '<title>a*</title>' "$T/long.html" | tr -d '<>/title\n' | wc -c | tr -d ' ')" 64
90q=$(awk 'BEGIN { for (i = 0; i < 64; i++) printf "\""; }')
91{ awk -v q="$q" 'BEGIN { for (i = 0; i < 500; i++) print "R\t" q "\tcore" }'
92 awk -v q="$q" 'BEGIN { for (i = 0; i < 13; i++) print "M\t" q "\t" q "\t" q q q }'; } >"$T/worst.tsv"
93"$T/galaxy" <"$T/worst.tsv" >"$T/worst.html"
94eq "worst case exit" "$?" 0
95eq "at most 400 stars drawn" "$(count "class='st " "$T/worst.html")" 400
96eq "legend still counts all 500" "$(grep -c '<b>500</b> public projects' "$T/worst.html")" 1
97eq "at most 12 merges drawn" "$(count '<li><a ' "$T/worst.html")" 12
98# 679686 is the proven bound (OutputBound.lean, Wolfram: 679686 < 2^20)
99if [ "$(wc -c <"$T/worst.html")" -le 679686 ]; then ok "worst case within the proven bound"; else no "worst case within the proven bound"; fi
100LEAN=${LEAN:-$HOME/.elan/bin/lean}
101if [ -x "$LEAN" ]; then
102 eq "Lean checks the bound, no axioms" "$("$LEAN" "$HERE/../OutputBound.lean" 2>&1 | grep -c 'does not depend on any axioms')" 1
103else
104 echo "NOT_RUN Lean check: no lean at $LEAN"
105fi
106
107# negative control: remove the '<' escape; the hostile check above must now fail
108sed 's/^if eq c 60$/if eq c 0/' "$SRC" >"$T/mutant.om"
109if cmp -s "$SRC" "$T/mutant.om"; then
110 no "mutant differs from source"
111else
112 "$OMC" <"$T/mutant.om" >"$T/mutant" 2>/dev/null && chmod +x "$T/mutant"
113 "$T/mutant" <"$T/evil.tsv" >"$T/mutant.html"
114 if [ "$(grep -ci '<script\|<u>\|<em>' "$T/mutant.html")" -gt 0 ]; then
115 ok "mutant without the escape is caught"
116 else
117 no "mutant without the escape is caught"
118 fi
119fi
120
121# negative control: put the old 4,096-line loop limit back; the 5,001-line case must trap again
122sed 's/^while lt s lim bound 65536$/while lt s lim bound 4096/' "$SRC" >"$T/mutant2.om"
123"$OMC" <"$T/mutant2.om" >"$T/mutant2" 2>/dev/null && chmod +x "$T/mutant2"
124"$T/mutant2" <"$T/lines.tsv" >/dev/null 2>&1
125eq "mutant with the old line limit traps 4" "$?" 104
126
127# negative control: remove the UTF-8 back-off; the cut must now split the e-acute
128sed 's/^e = sub e 1$/e = sub e 0/' "$SRC" >"$T/mutant3.om"
129if cmp -s "$SRC" "$T/mutant3.om"; then
130 no "mutant3 differs from source"
131else
132 "$OMC" <"$T/mutant3.om" >"$T/mutant3" 2>/dev/null && chmod +x "$T/mutant3"
133 "$T/mutant3" <"$T/utf8.tsv" >"$T/mutant3.html"
134 if [ "$(LC_ALL=C grep -c '<title>a\{63\}</title>' "$T/mutant3.html")" -eq 0 ]; then
135 ok "mutant without the UTF-8 back-off is caught"
136 else
137 no "mutant without the UTF-8 back-off is caught"
138 fi
139fi
140
141echo "RESULT pass=$pass fail=$fail"
142[ "$fail" -eq 0 ]