interplane-forge
INTERPLANE Forge
Brought by drakestapleton
interplane-forge / galaxy / tests / run.sh
| 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. |
| 8 | set -u |
| 9 | HERE=$(cd "$(dirname "$0")" && pwd) |
| 10 | G=$HERE/.. |
| 11 | OMC=${OMC:-$HOME/work/flux/omega-mv/seed/out/omc} |
| 12 | PIN=3ad9f10f64309e7acf8a725082b28e23a2a4aeb07e98322fb4dc0fcd8fc93194 |
| 13 | T=$(mktemp -d) || exit 2 |
| 14 | trap 'rm -rf "$T"' EXIT |
| 15 | SRC=$T/galaxy.om |
| 16 | cat "$G/page.om" "$G/cli.om" >"$SRC" |
| 17 | pass=0 |
| 18 | fail=0 |
| 19 | ok() { pass=$((pass + 1)); echo "PASS $1"; } |
| 20 | no() { fail=$((fail + 1)); echo "FAIL $1"; } |
| 21 | eq() { if [ "$2" = "$3" ]; then ok "$1"; else no "$1: got '$2' want '$3'"; fi; } |
| 22 | count() { grep -o "$1" "$2" | wc -l | tr -d ' '; } |
| 23 | |
| 24 | got=$(sha256sum "$OMC" 2>/dev/null | cut -d' ' -f1) |
| 25 | if [ "$got" != "$PIN" ]; then |
| 26 | echo "compiler pin mismatch: $got" >&2 |
| 27 | exit 2 |
| 28 | fi |
| 29 | "$OMC" <"$SRC" >"$T/galaxy" 2>"$T/omc.err" |
| 30 | eq "compile exit" "$?" 0 |
| 31 | chmod +x "$T/galaxy" |
| 32 | |
| 33 | "$T/galaxy" <"$HERE/feed.tsv" >"$T/page.html" |
| 34 | eq "page exit" "$?" 0 |
| 35 | eq "no script element" "$(grep -ci '<script' "$T/page.html")" 0 |
| 36 | eq "no inline handler" "$(grep -ci ' on[a-z]*=' "$T/page.html")" 0 |
| 37 | eq "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 ' ')" |
| 38 | eq "hive cells" "$(count "class='cell'" "$T/page.html")" 10 |
| 39 | eq "feed names a retired network (control)" "$(grep -ci 'radicle' "$HERE/feed.tsv")" 1 |
| 40 | eq "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 |
| 41 | eq "its station is printed as Retired" "$(count "y='-22'>Retired</text>" "$T/page.html")" 1 |
| 42 | eq "merge rows equal M lines" "$(count '<li><a ' "$T/page.html")" "$(awk -F'\t' '$1=="M"' "$HERE/feed.tsv" | wc -l | tr -d ' ')" |
| 43 | want=$(awk -F'\t' '$1=="K" && ($2=="waiting" || $2=="approved") {n += $3} END {print n + 0}' "$HERE/feed.tsv") |
| 44 | eq "ring dots equal waiting plus approved" "$(count "class='pl'" "$T/page.html")" "$want" |
| 45 | eq "headline present" "$(grep -c 'NVIDIA hardware compatible. CUDA not required.' "$T/page.html")" 1 |
| 46 | eq "scope line present" "$(grep -c 'Other chips: not run.' "$T/page.html")" 1 |
| 47 | |
| 48 | "$T/galaxy" <"$HERE/feed.tsv" >"$T/page2.html" |
| 49 | eq "same input, same bytes" "$(sha256sum <"$T/page.html")" "$(sha256sum <"$T/page2.html")" |
| 50 | |
| 51 | printf 'css\n' | "$T/galaxy" >"$T/galaxy.css" |
| 52 | eq "css exit" "$?" 0 |
| 53 | eq "css has no markup" "$(grep -c '<' "$T/galaxy.css")" 0 |
| 54 | eq "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. |
| 57 | printf '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" |
| 59 | eq "hostile exit" "$?" 0 |
| 60 | eq "hostile input stays text" "$(grep -ci '<script\|<u>\|<em>' "$T/evil.html")" 0 |
| 61 | eq "hostile quote cannot close an attribute" "$(grep -c "='[^']*'onx" "$T/evil.html")" 0 |
| 62 | |
| 63 | # an apostrophe prints as an apostrophe ('), never as a double quote |
| 64 | printf "R\tDrake's\tcore\n" >"$T/apos.tsv" |
| 65 | "$T/galaxy" <"$T/apos.tsv" >"$T/apos.html" |
| 66 | eq "apostrophe exit" "$?" 0 |
| 67 | eq "apostrophe stays an apostrophe" "$(grep -c '<title>Drake'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' |
| 70 | awk '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" |
| 72 | eq "UTF-8 cut exit" "$?" 0 |
| 73 | eq "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" |
| 77 | eq "empty exit" "$?" 0 |
| 78 | eq "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" |
| 84 | eq "5,001 lines exit" "$?" 0 |
| 85 | eq "5,001 lines still print the figure" "$(grep -c '<dd>9</dd>' "$T/lines.html")" 1 |
| 86 | awk '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" |
| 88 | eq "60,000-byte name exit" "$?" 0 |
| 89 | eq "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 |
| 90 | q=$(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" |
| 94 | eq "worst case exit" "$?" 0 |
| 95 | eq "at most 400 stars drawn" "$(count "class='st " "$T/worst.html")" 400 |
| 96 | eq "legend still counts all 500" "$(grep -c '<b>500</b> public projects' "$T/worst.html")" 1 |
| 97 | eq "at most 12 merges drawn" "$(count '<li><a ' "$T/worst.html")" 12 |
| 98 | # 679686 is the proven bound (OutputBound.lean, Wolfram: 679686 < 2^20) |
| 99 | if [ "$(wc -c <"$T/worst.html")" -le 679686 ]; then ok "worst case within the proven bound"; else no "worst case within the proven bound"; fi |
| 100 | LEAN=${LEAN:-$HOME/.elan/bin/lean} |
| 101 | if [ -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 |
| 103 | else |
| 104 | echo "NOT_RUN Lean check: no lean at $LEAN" |
| 105 | fi |
| 106 | |
| 107 | # negative control: remove the '<' escape; the hostile check above must now fail |
| 108 | sed 's/^if eq c 60$/if eq c 0/' "$SRC" >"$T/mutant.om" |
| 109 | if cmp -s "$SRC" "$T/mutant.om"; then |
| 110 | no "mutant differs from source" |
| 111 | else |
| 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 |
| 119 | fi |
| 120 | |
| 121 | # negative control: put the old 4,096-line loop limit back; the 5,001-line case must trap again |
| 122 | sed '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 |
| 125 | eq "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 |
| 128 | sed 's/^e = sub e 1$/e = sub e 0/' "$SRC" >"$T/mutant3.om" |
| 129 | if cmp -s "$SRC" "$T/mutant3.om"; then |
| 130 | no "mutant3 differs from source" |
| 131 | else |
| 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 |
| 139 | fi |
| 140 | |
| 141 | echo "RESULT pass=$pass fail=$fail" |
| 142 | [ "$fail" -eq 0 ] |