Something went wrong. Try again.
Backend environment for match hosting for lance.blue
Something went wrong. Try again.
Shell
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107#!/usr/bin/env bash# The boot screen is two frames stitched to look like one, and every way it# comes apart is silent - the page still loads, the match still starts, and# what a player sees is only wrong if you happen to be looking:## - the string drifts. It lives twice, in index.html for the frame we serve# and in msg.json for the frame the client builds. Nothing links them.# - the key is misspelled. The client merges msg.json over its built-in table# per key, so a typo is not an error, it is upstream's default coming back.# - lang.js moves. It has to run before the loader stub reads the language;# after it, the file is fetched for whatever locale the browser asked for# and the string only reaches English browsers.# - a file 404s. The insignia is a background-image and the faces are# @font-face - a missing one is a blank box and a fallback face, not a log# line.## None of this is reachable without a browser, so what is checked here is that# the pieces exist, agree with each other, and are wired in the right order.set -uo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"WEB="$ROOT/suramadu/web"HTML="$WEB/index.html"MSG="$WEB/javascript/nls/en/msg.json"
pass=0; fail=0check() { if "${@:2}"; then echo "ok $1"; pass=$((pass+1)); else echo "FAIL $1"; fail=$((fail+1)); fi; }
for f in "$HTML" "$MSG" "$WEB/lang.js" "$WEB/fonts.css" "$WEB/theme.css" "$WEB/insignia.svg"; do [ -s "$f" ] || { echo "FAIL ${f#"$ROOT"/} is missing or empty"; exit 1; }done
# --- the string exists once per frame, and they agree ------------------------
check "msg.json parses" python3 -c "import json,sys; json.load(open(sys.argv[1]))" "$MSG"
# The key upstream looks up. Spelled any other way this file is inert.check "msg.json carries dialog.startingDialog" python3 - "$MSG" <<'PY'import json, sysmsg = json.load(open(sys.argv[1], encoding="utf-8"))sys.exit(0 if isinstance(msg.get("dialog.startingDialog"), str) and msg["dialog.startingDialog"].strip() else 1)PY
check "the two frames say the same thing" python3 - "$MSG" "$HTML" <<'PY'import json, re, sys
msg = json.load(open(sys.argv[1], encoding="utf-8"))["dialog.startingDialog"]html = open(sys.argv[2], encoding="utf-8").read()
m = re.search(r'<p class="lb-status">([^<]*)</p>', html)if m is None: print("index.html has no <p class=\"lb-status\"> to compare against") sys.exit(1)if m.group(1).strip() != msg.strip(): print("index.html: %r" % m.group(1).strip()) print("msg.json : %r" % msg.strip()) print("The first frame and the second would say different things.") sys.exit(1)PY
# The client asks for javascript/nls/<tag>/msg.json with the tag lang.js pins,# so the directory name and that string are one fact stored in two places.check "lang.js pins the tag the shipped directory is named for" bash -c ' tag=$(grep -o "setItem(\"webswingLang\", \"[a-zA-Z-]*\")" "$1/lang.js" | sed -E "s/.*\"webswingLang\", \"([a-zA-Z-]*)\".*/\1/") [ -n "$tag" ] && [ -f "$1/javascript/nls/$tag/msg.json" ]' _ "$WEB"
# --- wiring ------------------------------------------------------------------
check "lang.js runs before the loader stub" bash -c ' l=$(grep -n "\"lang.js\"" "$1" | cut -d: -f1) s=$(grep -n "webswing-loader-stub.js" "$1" | cut -d: -f1) [ -n "$l" ] && [ -n "$s" ] && [ "$l" -lt "$s" ]' _ "$HTML"
check "fonts.css is linked, and before theme.css asks for the family" bash -c ' f=$(grep -n "\"fonts.css\"" "$1" | cut -d: -f1) t=$(grep -n "\"theme.css\"" "$1" | cut -d: -f1) [ -n "$f" ] && [ -n "$t" ] && [ "$f" -lt "$t" ]' _ "$HTML"
# --- every asset referenced is an asset we ship ------------------------------
check "the faces fonts.css declares are all here" bash -c ' status=0 while IFS= read -r ref; do [ -f "$1/$ref" ] || { echo "fonts.css wants $ref, which is not in web/"; status=1; } done < <(grep -o "url(\"[^\"]*\")" "$1/fonts.css" | sed -E "s/url\(\"(.*)\"\)/\1/") exit $status' _ "$WEB"
check "the insignia theme.css draws is here" bash -c ' status=0 while IFS= read -r ref; do [ -f "$1/$ref" ] || { echo "theme.css wants $ref, which is not in web/"; status=1; } done < <(grep -o "url(\"[^\"]*\")" "$1/theme.css" | sed -E "s/url\(\"(.*)\"\)/\1/") exit $status' _ "$WEB"
check "insignia.svg is an SVG" grep -q "<svg" "$WEB/insignia.svg"
# The OFL requires its text to travel with the fonts, and the whole of web/ is# what reaches the image.check "the font licence ships beside the fonts" bash -c ' ls "$1"/fonts/*.woff2 >/dev/null 2>&1 && [ -s "$1/fonts/OFL-Chakra-Petch.txt" ]' _ "$WEB"
echoecho "$pass passed, $fail failed"[ "$fail" -eq 0 ]