interplane.Get Omega
Read in your language

interplane-forge

INTERPLANE Forge

Brought by drakestapleton

branch main Branches Tags History

interplane-forge / galaxy / tests / live.sh

113 lines · 6110 bytes Raw Blame History
1#!/bin/sh
2# galaxy/tests/live.sh: gate for live.om (the page that keeps itself current).
3# OMC=/abs/seed/out/omc sh galaxy/tests/live.sh
4# Replays recorded stream bytes through the daemon (it reads stdin when given an argument) and
5# requires the page it writes to equal, byte for byte, the page the filter prints for the feed a
6# reader would write by hand from the same events. Dates are checked against `date -u`. Pacing is
7# checked on stream time: 10 s after a publish is held, 30 s is published.
8# Negative controls: a mutant that reads "open" where the floor shows "moving" must not match, and
9# a mutant without the 30 s rule must publish the held event.
10set -u
11HERE=$(cd "$(dirname "$0")" && pwd)
12G=$HERE/..
13OMC=${OMC:-$HOME/work/flux/omega-mv/seed/out/omc}
14PIN=3ad9f10f64309e7acf8a725082b28e23a2a4aeb07e98322fb4dc0fcd8fc93194
15T=$(mktemp -d) || exit 2
16trap 'rm -rf "$T"' EXIT
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; }
22
23got=$(sha256sum "$OMC" 2>/dev/null | cut -d' ' -f1)
24if [ "$got" != "$PIN" ]; then
25 echo "compiler pin mismatch: $got" >&2
26 exit 2
27fi
28cat "$G/page.om" "$G/live.om" | "$OMC" >"$T/live" 2>"$T/live.err"
29eq "live compile exit" "$?" 0
30cat "$G/page.om" "$G/cli.om" | "$OMC" >"$T/cli" 2>"$T/cli.err"
31eq "cli compile exit" "$?" 0
32chmod +x "$T/live" "$T/cli"
33
34# 1. replay: two events (a full one, then a patch that replaces generated and machine)
35mkdir "$T/a" && cp "$HERE/stars.tsv" "$T/a/"
36(cd "$T/a" && "$T/live" replay <"$HERE/stream.sse")
37eq "replay exit" "$?" 0
38asof=$(date -u -d @1794260414 '+%Y-%m-%d %H:%M')
39sed "s/@ASOF@/$asof/" "$HERE/live-expect.tsv" >"$T/expect.tsv"
40"$T/cli" <"$T/expect.tsv" >"$T/expect.html"
41if cmp -s "$T/a/index.html" "$T/expect.html"; then ok "replayed page equals the hand-written feed's page"; else no "replayed page equals the hand-written feed's page"; fi
42printf 'css\n' | "$T/cli" >"$T/expect.css"
43if cmp -s "$T/a/galaxy.css" "$T/expect.css"; then ok "stylesheet written"; else no "stylesheet written"; fi
44eq "no temporary file left" "$(ls "$T/a" | grep -c 'tmp$')" 0
45eq "ten cells" "$(grep -o "class='cell'" "$T/a/index.html" | wc -l | tr -d ' ')" 10
46
47# 2. bad input after good input changes nothing: a cut-off event, junk, and a 2,000,000-byte line,
48# then an event that carries only a generated second 60 s on. Pacing holds the bad events, so that
49# last event is what publishes the figures as the bad input left them: only the minute may change.
50mkdir "$T/b" && cp "$HERE/stars.tsv" "$T/b/"
51{ cat "$HERE/stream.sse"
52 printf 'data: {"stations":[{"id":"intake"\n\n'
53 printf 'data: not json at all\n\n\000\001\002\n'
54 awk 'BEGIN { printf "data: {\"x\":\""; for (i = 0; i < 2000000; i++) printf "a"; printf "\"}\n\n" }'
55 printf 'data: {"generated":1794260474}\n\n'; } >"$T/bad.sse"
56(cd "$T/b" && "$T/live" replay <"$T/bad.sse")
57eq "bad input exit" "$?" 0
58sed "s/@ASOF@/$(date -u -d @1794260474 '+%Y-%m-%d %H:%M')/" "$HERE/live-expect.tsv" | "$T/cli" >"$T/expect-b.html"
59if cmp -s "$T/b/index.html" "$T/expect-b.html"; then ok "bad input changes no figure (published after it)"; else no "bad input changes no figure (published after it)"; fi
60
61# 3. no stations yet: nothing is published
62mkdir "$T/c"
63printf 'data: {"generated":5,"machine":{"gpu_w":1}}\n\n' | (cd "$T/c" && "$T/live" replay)
64eq "patch before any stations exit" "$?" 0
65eq "nothing published before the stations are known" "$(ls "$T/c" | grep -c '^index.html$')" 0
66
67# 4. dates against date -u (epoch, leap days, year ends, a far year)
68for n in 0 86399 951782400 951868799 1709164800 1735689599 1735689600 1794260414 4102444800 4107542399; do
69 mkdir "$T/d$n"
70 printf 'data: {"generated":%s,"stations":[{"id":"intake","name":"x","moving":1,"done24":1}]}\n\n' "$n" | (cd "$T/d$n" && "$T/live" replay)
71 want="Read from the Spark $(date -u -d "@$n" '+%Y-%m-%d %H:%M') UTC"
72 eq "date of $n" "$(grep -o 'Read from the Spark [0-9: -]* UTC' "$T/d$n/index.html")" "$want"
73done
74
75# 5. pacing by the stream's own generated second
76ev() { printf 'data: {"generated":%s,"machine":{"gpu_w":%s}}\n\n' "$1" "$2"; }
77first='data: {"generated":1000000,"machine":{"gpu_w":10},"stations":[{"id":"intake","name":"x","moving":1,"done24":1}]}'
78gpu() { grep -o '<dt>GPU, watts</dt><dd>[0-9]*' "$1" | grep -o '[0-9]*$'; }
79mkdir "$T/p1"
80{ printf '%s\n\n' "$first"; ev 1000010 99; } >"$T/p1.sse"
81(cd "$T/p1" && "$T/live" replay <"$T/p1.sse")
82eq "an event 10 s after a publish is held" "$(gpu "$T/p1/index.html")" 10
83mkdir "$T/p2"
84{ printf '%s\n\n' "$first"; ev 1000010 99; ev 1000029 98; ev 1000030 55; ev 1000031 77; } | (cd "$T/p2" && "$T/live" replay)
85eq "an event 30 s after a publish is published and the next one held" "$(gpu "$T/p2/index.html")" 55
86mkdir "$T/p3"
87{ printf '%s\n\n' "$first"; ev 999000 7; } | (cd "$T/p3" && "$T/live" replay)
88eq "an event whose generated second went backwards is published" "$(gpu "$T/p3/index.html")" 7
89
90# negative control: read "open" instead of "moving"; the replayed page must no longer match
91sed 's/^text vkmov "moving"$/text vkmov "open"/' "$G/live.om" >"$T/mutant.om"
92if cmp -s "$G/live.om" "$T/mutant.om"; then
93 no "mutant differs from source"
94else
95 cat "$G/page.om" "$T/mutant.om" | "$OMC" >"$T/mutant" 2>/dev/null && chmod +x "$T/mutant"
96 mkdir "$T/m" && cp "$HERE/stars.tsv" "$T/m/"
97 (cd "$T/m" && "$T/mutant" replay <"$HERE/stream.sse")
98 if cmp -s "$T/m/index.html" "$T/expect.html"; then no "mutant reading open is caught"; else ok "mutant reading open is caught"; fi
99fi
100
101# negative control: drop the 30 s rule; the event held in case 5 must then be on the page
102sed 's/^if ge sub g l 30$/if true/' "$G/live.om" >"$T/mutant2.om"
103if cmp -s "$G/live.om" "$T/mutant2.om"; then
104 no "mutant2 differs from source"
105else
106 cat "$G/page.om" "$T/mutant2.om" | "$OMC" >"$T/mutant2" 2>/dev/null && chmod +x "$T/mutant2"
107 mkdir "$T/m2"
108 (cd "$T/m2" && "$T/mutant2" replay <"$T/p1.sse")
109 eq "mutant without the 30 s rule publishes the held event" "$(gpu "$T/m2/index.html")" 99
110fi
111
112echo "RESULT pass=$pass fail=$fail"
113[ "$fail" -eq 0 ]