oxedyne/fe2o3/fe2o3_austenite/tools/gate/gate.sh
12.8 KiB, 1 run, executable
created by r1870400018:66263, which is this file's identity for as long as the history lasts, whatever it is later renamed to
download · who wrote it · its history
| 1 | #!/usr/bin/env bash |
| 2 | # The gate on one project: Typst 0.15.1 is the oracle, Austenite is compiled strict through the command line |
| 3 | # and through the wasm door, and the PDFs are compared by G1 to G12 (`g_checks.py`). Generic: it takes the |
| 4 | # project as arguments and knows no book. |
| 5 | # |
| 6 | # gate.sh <root> <main> <fontdir> <austenite-bin> <pkg> |
| 7 | # |
| 8 | # <root> the project root: typst's `--root`, the CLI's `--root` and the door's gather root |
| 9 | # <main> the entry file, relative to <root> |
| 10 | # <fontdir> the project's font directory, relative to <root> or absolute |
| 11 | # <austenite-bin> the `austenite` binary built from the tree under test |
| 12 | # <pkg> the wasm-pack output directory of the same tree |
| 13 | # |
| 14 | # Environment: GATE_TYPST (the typst binary, default /home/jason/bin/typst), GATE_OUT (the scratch parent, |
| 15 | # default ~/.cache/austenite-o4-probe/out), GATE_EXCLUDE (directories under <root> the door's gather leaves |
| 16 | # out, space separated), GATE_PACKAGES (a directory of packages the door's gather supplies through |
| 17 | # `supplyPackage`, as `tools/bench/lib/packages.mjs` describes; the CLI keeps resolving from Typst's own |
| 18 | # cache), GATE_CAP (the memory cap of each run, default 3G). |
| 19 | # |
| 20 | # What runs, in order, every run under the cap and with the account's own fonts hidden: |
| 21 | # typst compile; `austenite --eval --strict --diag-summary` twice; `door_pdf.mjs` twice, the first |
| 22 | # compiling twice on one instance; then G1, G2, G3, G4, G5, G7, G8 and G9 for the CLI's PDF and for the door's |
| 23 | # against Typst's (the door's only when it is not the CLI's byte for byte), and G12 over the five Austenite |
| 24 | # PDFs. |
| 25 | # |
| 26 | # [bio] by construction. Every PDF and raster lives in a directory made under GATE_OUT and removed on exit; page |
| 27 | # text is read from a pipe inside g_checks.py and never written; the CLI's stdout (it names the paths) goes |
| 28 | # nowhere; the stderr of every program goes only through an awk filter that keeps counts or a closed |
| 29 | # vocabulary; and the whole of stdout passes a final whitelist, so the only lines that can appear are: |
| 30 | # |
| 31 | # gate: error <usage|no-root|no-main|no-tool|scratch|typst-failed> |
| 32 | # gate: typst exit <n> |
| 33 | # gate: typst diagnostics error <n> warning <n> |
| 34 | # gate: typst pages <n|none> |
| 35 | # gate: cli exit <n> |
| 36 | # gate: cli severity error <n> warning <n> |
| 37 | # gate: cli diag-summary <error|warning> <kind> <construct|-> <n> |
| 38 | # gate: cli diag-error <kind> callee:<name> expected:<type> found:<type> file:<main|sibling|other> |
| 39 | # gate: cli pages <n|none> |
| 40 | # gate: door <ok|error> pages <n|none> kinds <none|kind:n,...> needs <n> |
| 41 | # gate: door again <ok|error> |
| 42 | # gate: door fail <bad-args|bad-pkg|no-root|no-main|no-packages|bad-package|too-large|supply|failed> |
| 43 | # gate: door pages <n|none> |
| 44 | # gate: <cli|door> checks skipped |
| 45 | # gate: door same-as-cli the door's PDF equals the CLI's byte for byte, so it has the CLI's verdicts |
| 46 | # gate: <cli|door> g1 .. g9 every line of `g_checks.py` for that check, as its docstring lists them |
| 47 | # gate: g12 ... the lines of `g_checks.py g12` |
| 48 | # gate: table <cli|door> <g1|g2|g3|g4|g5|g7|g8|g9> <green|red|measured> |
| 49 | # gate: table g12 <green|red> |
| 50 | # gate: verdict <green|red> green when every required check is green and both compiles succeeded |
| 51 | # gate: suppressed <n> lines a program printed that the whitelist dropped |
| 52 | # |
| 53 | # G3, G7 and G9 are measured and are `measured` in the table; the others are required. The exit status is 0 on |
| 54 | # `verdict green`, 1 on `verdict red`, 2 on an `error`. |
| 55 | set -u |
| 56 | |
| 57 | HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 58 | # shellcheck source=gate_lib.sh |
| 59 | . "$HERE/gate_lib.sh" |
| 60 | |
| 61 | # The lines of a program's stderr, kept as counts or a closed vocabulary (the CLI's). |
| 62 | cli_filter() { |
| 63 | awk ' |
| 64 | /^diag-summary (error|warning) [a-z_]+ ([#A-Za-z0-9_.:-]+|-) [0-9]+$/ { print "gate: cli " $0; next } |
| 65 | /^diag-error [a-z_]+ callee:[a-z0-9.-]+ expected:[a-z-]+ found:[a-z-]+ file:(main|sibling|other)$/ { print "gate: cli " $0; next } |
| 66 | /: error: / { e++; next } |
| 67 | /: warning: / { w++; next } |
| 68 | END { printf "gate: cli severity error %d warning %d\n", e + 0, w + 0 }' |
| 69 | } |
| 70 | |
| 71 | # Typst's short-format diagnostics on stdin, as counts. |
| 72 | typst_filter() { |
| 73 | awk ' |
| 74 | /: error: / || /^error: / { e++; next } |
| 75 | /: warning: / || /^warning: / { w++; next } |
| 76 | END { printf "gate: typst diagnostics error %d warning %d\n", e + 0, w + 0 }' |
| 77 | } |
| 78 | |
| 79 | # The door's own lines; anything else is counted. |
| 80 | door_filter() { |
| 81 | awk ' |
| 82 | /^door (ok|error) pages (none|[0-9]+) kinds (none|[a-z_]+:[0-9]+(,[a-z_]+:[0-9]+)*) needs [0-9]+$/ { print "gate: " $0; next } |
| 83 | /^door again (ok|error)$/ { print "gate: " $0; next } |
| 84 | /^door fail (bad-args|bad-pkg|no-root|no-main|no-packages|bad-package|too-large|supply|failed)$/ { print "gate: " $0; next } |
| 85 | { n++ } |
| 86 | END { if (n) printf "gate: suppressed %d\n", n }' |
| 87 | } |
| 88 | |
| 89 | pages_of() { |
| 90 | local n |
| 91 | n="$(pdfinfo "$1" 2>/dev/null | awk '/^Pages:/ { print $2 }')" |
| 92 | echo "${n:-none}" |
| 93 | } |
| 94 | |
| 95 | # Verdicts of the checks, by "<row> <check>", for the table and the exit status. |
| 96 | declare -A V |
| 97 | |
| 98 | # run_g <row> <check> <typst.pdf> <austenite.pdf>: the lines of one check, prefixed with its row. |
| 99 | run_g() { |
| 100 | local row="$1" chk="$2" out |
| 101 | out="$(python3 "$HERE/g_checks.py" "$chk" "$3" "$4" 2>/dev/null)" |
| 102 | printf '%s\n' "$out" | awk -v row="$row" 'NF { print "gate: " row " " $0 }' |
| 103 | V["$row $chk"]="$(printf '%s\n' "$out" | awk -v c="$chk" '$1 == c && $2 == "verdict" { v = $3 } $1 == c && $2 == "error" { v = "error" } END { print v }')" |
| 104 | } |
| 105 | |
| 106 | main() { |
| 107 | if [ $# -ne 5 ]; then |
| 108 | echo "gate: error usage" |
| 109 | return 2 |
| 110 | fi |
| 111 | local R="$1" M="$2" F="$3" BIN="$4" PKG="$5" |
| 112 | local TYPST="${GATE_TYPST:-/home/jason/bin/typst}" |
| 113 | local BASE="${GATE_OUT:-$HOME/.cache/austenite-o4-probe/out}" |
| 114 | local ROOT |
| 115 | ROOT="$(cd "$R" 2>/dev/null && pwd)" || { echo "gate: error no-root"; return 2; } |
| 116 | [ -f "$ROOT/$M" ] || { echo "gate: error no-main"; return 2; } |
| 117 | [ -x "$BIN" ] && [ -x "$TYPST" ] || { echo "gate: error no-tool"; return 2; } |
| 118 | mkdir -p "$BASE" || { echo "gate: error scratch"; return 2; } |
| 119 | # Global, not local: the trap runs after this function has returned. |
| 120 | W="$(mktemp -d "$BASE/gate.XXXXXX")" || { echo "gate: error scratch"; return 2; } |
| 121 | trap 'rm -rf "${W:?}"' EXIT |
| 122 | export GATE_SCRATCH="$W" |
| 123 | |
| 124 | local dex=() d |
| 125 | for d in ${GATE_EXCLUDE:-}; do |
| 126 | dex+=(--exclude "$d") |
| 127 | done |
| 128 | if [ -n "${GATE_PACKAGES:-}" ]; then |
| 129 | dex+=(--packages "$GATE_PACKAGES") |
| 130 | fi |
| 131 | |
| 132 | # Typst, the oracle. Run from the root so a relative <fontdir> and <main> resolve as they do for the CLI. |
| 133 | local te |
| 134 | ( cd "$ROOT" && gate_typst "$TYPST" compile --diagnostic-format short --root "$ROOT" \ |
| 135 | --font-path "$F" "$M" "$W/typst.pdf" ) 2>&1 >/dev/null | typst_filter |
| 136 | te=${PIPESTATUS[0]} |
| 137 | echo "gate: typst exit $te" |
| 138 | echo "gate: typst pages $(pages_of "$W/typst.pdf")" |
| 139 | if [ ! -s "$W/typst.pdf" ]; then |
| 140 | echo "gate: error typst-failed" |
| 141 | return 2 |
| 142 | fi |
| 143 | |
| 144 | # Austenite's command line, strict, twice. The first run's stderr is the report; the second is for G12. |
| 145 | local ce |
| 146 | ( cd "$ROOT" && gate_hidden "$BIN" --eval --strict --diag-summary --root "$ROOT" --font-path "$F" \ |
| 147 | "$M" "$W/cli1" ) 2>&1 >/dev/null | cli_filter |
| 148 | ce=${PIPESTATUS[0]} |
| 149 | echo "gate: cli exit $ce" |
| 150 | ( cd "$ROOT" && gate_hidden "$BIN" --eval --strict --diag-summary --root "$ROOT" --font-path "$F" \ |
| 151 | "$M" "$W/cli2" ) >/dev/null 2>&1 |
| 152 | echo "gate: cli pages $(pages_of "$W/cli1/document.pdf")" |
| 153 | |
| 154 | # The door, in node: the first process compiles twice on one instance, the second once on another. |
| 155 | local de |
| 156 | gate_cap node "$HERE/door_pdf.mjs" "$PKG" "$ROOT" "$M" "$F" "$W/door1.pdf" --again "$W/door2.pdf" \ |
| 157 | "${dex[@]}" 2>&1 | door_filter |
| 158 | de=${PIPESTATUS[0]} |
| 159 | gate_cap node "$HERE/door_pdf.mjs" "$PKG" "$ROOT" "$M" "$F" "$W/door3.pdf" "${dex[@]}" >/dev/null 2>&1 |
| 160 | echo "gate: door pages $(pages_of "$W/door1.pdf")" |
| 161 | |
| 162 | local row pdf g |
| 163 | for row in cli door; do |
| 164 | if [ "$row" = cli ]; then pdf="$W/cli1/document.pdf"; else pdf="$W/door1.pdf"; fi |
| 165 | if [ ! -s "$pdf" ]; then |
| 166 | echo "gate: $row checks skipped" |
| 167 | continue |
| 168 | fi |
| 169 | # The door's PDF, byte for byte the CLI's, has the CLI's verdicts: the checks are not run twice. |
| 170 | if [ "$row" = door ] && cmp -s "$W/cli1/document.pdf" "$pdf"; then |
| 171 | echo "gate: door same-as-cli" |
| 172 | for g in g1 g2 g3 g4 g5 g7 g8 g9; do |
| 173 | V["door $g"]="${V["cli $g"]:-}" |
| 174 | done |
| 175 | continue |
| 176 | fi |
| 177 | for g in g1 g2 g3 g4 g5 g7 g8 g9; do |
| 178 | run_g "$row" "$g" "$W/typst.pdf" "$pdf" |
| 179 | done |
| 180 | done |
| 181 | local out12 |
| 182 | out12="$(python3 "$HERE/g_checks.py" g12 "$W/cli1/document.pdf" "$W/cli2/document.pdf" \ |
| 183 | "$W/door1.pdf" "$W/door2.pdf" "$W/door3.pdf" 2>/dev/null)" |
| 184 | printf '%s\n' "$out12" | awk 'NF { print "gate: " $0 }' |
| 185 | V["all g12"]="$(printf '%s\n' "$out12" | awk '$1 == "g12" && $2 == "verdict" { v = $3 } $1 == "g12" && $2 == "error" { v = "error" } END { print v }')" |
| 186 | |
| 187 | # The table. A required check is green on `same` and red on anything else, a missing verdict included. |
| 188 | local red=0 v |
| 189 | [ "$ce" -eq 0 ] || red=1 |
| 190 | [ "$de" -eq 0 ] || red=1 |
| 191 | for row in cli door; do |
| 192 | for g in g1 g2 g3 g4 g5 g7 g8 g9; do |
| 193 | case "$g" in |
| 194 | g3|g7|g9) echo "gate: table $row $g measured" ;; |
| 195 | *) |
| 196 | v="${V["$row $g"]:-}" |
| 197 | if [ "$v" = same ]; then |
| 198 | echo "gate: table $row $g green" |
| 199 | else |
| 200 | echo "gate: table $row $g red" |
| 201 | red=1 |
| 202 | fi ;; |
| 203 | esac |
| 204 | done |
| 205 | done |
| 206 | if [ "${V["all g12"]:-}" = same ]; then |
| 207 | echo "gate: table g12 green" |
| 208 | else |
| 209 | echo "gate: table g12 red" |
| 210 | red=1 |
| 211 | fi |
| 212 | if [ "$red" -eq 0 ]; then echo "gate: verdict green"; return 0; fi |
| 213 | echo "gate: verdict red" |
| 214 | return 1 |
| 215 | } |
| 216 | |
| 217 | # The final whitelist, over everything main and its children wrote to either stream. |
| 218 | main "$@" 2>&1 | awk ' |
| 219 | function ok(re) { return $0 ~ ("^gate: " re "$") } |
| 220 | BEGIN { |
| 221 | N = "[0-9]+"; D2 = "-?[0-9]+\\.[0-9][0-9]"; D = "[0-9]+\\.[0-9][0-9][0-9][0-9]"; S = "[0-9]\\.[0-9][0-9][0-9]" |
| 222 | R = "(none|[0-9]+(-[0-9]+)?(,[0-9]+(-[0-9]+)?)*)" |
| 223 | K = "[a-z_]+" |
| 224 | row = "(cli|door) " |
| 225 | g[1] = "g1 pages a " N " b " N |
| 226 | g[2] = "g1 mediabox differ " N " pages " R |
| 227 | g[3] = "g1 mediabox max-deviation " D |
| 228 | g[4] = "g1 verdict (same|differs)" |
| 229 | g[5] = "g2 fonts a " N " b " N |
| 230 | g[6] = "g2 only-[ab] [A-Za-z0-9+-]+" |
| 231 | g[7] = "g2 only-[ab] other" |
| 232 | g[8] = "g2 flags a " N " b " N |
| 233 | g[9] = "g2 verdict (same|differs)" |
| 234 | g[10] = "g3 pages a " N " b " N |
| 235 | g[11] = "g3 differ " N " pages " R |
| 236 | g[12] = "g3 min-similarity (none|" S ")" |
| 237 | g[13] = "g3 verdict (same|differs)" |
| 238 | g[14] = "g4 outline a " N " b " N |
| 239 | g[15] = "g4 levels (equal|differs) first-diff (none|" N ")" |
| 240 | g[16] = "g4 titles (equal|differs) unmatched a " N " b " N |
| 241 | g[17] = "g4 titles position differ " N " of " N |
| 242 | g[18] = "g4 titles prefix-only " N |
| 243 | g[19] = "g4 verdict (same|differs)" |
| 244 | g[20] = "g5 (title|author|subject|keywords) (equal|differs|absent-both)" |
| 245 | g[21] = "g5 verdict (same|differs)" |
| 246 | g[22] = "g7 compared " N " of a " N " b " N |
| 247 | g[23] = "g7 page " N " " D |
| 248 | g[24] = "g7 max (none|" D ")" |
| 249 | g[25] = "g7 median (none|" D ")" |
| 250 | g[26] = "g8 pages a " N " b " N |
| 251 | g[27] = "g8 out-of-tolerance " N " pages " R |
| 252 | g[28] = "g8 page " N " a " N " b " N |
| 253 | g[29] = "g8 max-deviation " D |
| 254 | g[30] = "g8 empty " N " pages " R |
| 255 | g[31] = "g8 verdict (same|differs)" |
| 256 | g[32] = "g[1234578] error (unreadable|usage|scratch)" |
| 257 | g[33] = "g9 pages differ " N " pages " R |
| 258 | g[34] = "g9 page " N " (lines|blocks|words|sizes|images|links) a " N " b " N |
| 259 | g[35] = "g9 page " N " (left|right|top|bottom|pitch|height) a " D2 " b " D2 |
| 260 | g[36] = "g9 line " N " " N " y a " D2 " b " D2 " x a " D2 " b " D2 " w a " D2 " b " D2 |
| 261 | g[37] = "g9 error (unreadable|usage)" |
| 262 | ng = 37 |
| 263 | h[1] = "g12 (cli-twice|door-one-instance|door-two-instances|cli-door) (equal|differs|absent)" |
| 264 | h[2] = "g12 size cli (none|" N ") door (none|" N ")" |
| 265 | h[3] = "g12 verdict (same|differs)" |
| 266 | h[4] = "g12 error (unreadable|usage)" |
| 267 | nh = 4 |
| 268 | } |
| 269 | { |
| 270 | if (ok("error (usage|no-root|no-main|no-tool|scratch|typst-failed)")) { print; next } |
| 271 | if (ok("typst exit " N) || ok("typst diagnostics error " N " warning " N) || ok("typst pages (none|" N ")")) { print; next } |
| 272 | if (ok("cli exit " N) || ok("cli severity error " N " warning " N) || ok("cli pages (none|" N ")")) { print; next } |
| 273 | if (ok("cli diag-summary (error|warning) " K " ([#A-Za-z0-9_.:-]+|-) " N)) { print; next } |
| 274 | if (ok("cli diag-error " K " callee:[a-z0-9.-]+ expected:[a-z-]+ found:[a-z-]+ file:(main|sibling|other)")) { print; next } |
| 275 | if (ok("door (ok|error) pages (none|" N ") kinds (none|" K ":" N "(," K ":" N ")*) needs " N)) { print; next } |
| 276 | if (ok("door again (ok|error)") || ok("door pages (none|" N ")")) { print; next } |
| 277 | if (ok("door fail (bad-args|bad-pkg|no-root|no-main|no-packages|bad-package|too-large|supply|failed)")) { print; next } |
| 278 | if (ok("(cli|door) checks skipped") || ok("door same-as-cli")) { print; next } |
| 279 | for (i = 1; i <= ng; i++) if (ok(row g[i])) { print; next } |
| 280 | for (i = 1; i <= nh; i++) if (ok(h[i])) { print; next } |
| 281 | if (ok("table (cli|door) (g1|g2|g3|g4|g5|g7|g8|g9) (green|red|measured)") || ok("table g12 (green|red)")) { print; next } |
| 282 | if (ok("verdict (green|red)")) { print; next } |
| 283 | if (ok("suppressed " N)) { print; next } |
| 284 | n++ |
| 285 | } |
| 286 | END { if (n) printf "gate: suppressed %d\n", n }' |
| 287 | exit "${PIPESTATUS[0]}" |