#!/usr/bin/env bash # # Pilot check: go-loose consuming the shared contract. # # This is the test that decides whether the consolidation is real. It loads go-loose's # *actual* index.html and its *actual* hand-written style.css, with only the theme # origin substituted exactly as go-loose's server does it, and then asks the question # that matters: # # Do the components shipped by go-bananas change the attributes that go-loose's own # CSS already keys on, so go-loose is themed without a single edit to its stylesheet? # # If that is true, adoption is one and one \n') open(os.path.join(out, 'index.html'), 'w').write(html) # go-loose serves its own files under /assets/, so they belong in site/assets/ rather # than at the site root. Getting this wrong 404s every one of them while leaving the # page looking merely unstyled. assets = os.path.join(out, 'assets') os.makedirs(assets, exist_ok=True) for name in ('style.css', 'app.js', 'account.js', 'roles.js', 'profile.js'): p = os.path.join(src, name) if os.path.exists(p): open(os.path.join(assets, name), 'w').write(open(p).read()) PY sed "s#from '/rt/v1/components.js'#from '$THEME_ORIGIN/rt/v1/components.js'#" \ "$ROOT/hack/pilot-go-loose.js" > "$WORK/site/pilot.js" echo "==> starting the theme service on :$THEME_PORT" # The selector fetches contract.json, and this page is on a different origin from the # service. A cross-origin module fetch and a JSON fetch both need the consuming # origin in CORS_ALLOWED_ORIGINS; a same-origin deployment needs nothing here. That is # the one setting adopting the contract requires, and setting it here is what proves it # is sufficient. DATABASE_PATH="$WORK/pilot.db" \ BANANAS_ENVIRONMENT=development \ BANANAS_AUTH_MODE=dev \ BANANAS_PUBLIC_BASE_URL="$THEME_ORIGIN" \ BANANAS_HTTP_ADDR=":$THEME_PORT" \ BANANAS_SDK_DIR="$WORK/site/assets" \ BANANAS_CORS_ALLOWED_ORIGINS="http://localhost:$PORT" \ "$WORK/go-bananas" >"$WORK/theme.log" 2>&1 & THEME_PID=$! for _ in $(seq 1 40); do curl -fsS -m 2 "http://localhost:$THEME_PORT/healthz" >/dev/null 2>&1 && break sleep 0.25 done echo "==> serving go-loose's page on :$PORT" (cd "$WORK/site" && exec python3 -m http.server "$PORT") >"$WORK/site.log" 2>&1 & SERVER_PID=$! for _ in $(seq 1 40); do curl -fsS -m 2 "http://localhost:$PORT/index.html" >/dev/null 2>&1 && break sleep 0.25 done echo "==> driving the page" "$CHROME" \ --headless --no-sandbox --disable-gpu \ --virtual-time-budget=12000 \ --dump-dom "http://localhost:$PORT/index.html" \ >"$WORK/dom.html" 2>"$WORK/chrome.log" result="$(python3 - "$WORK/dom.html" <<'PY' import re, sys dom = open(sys.argv[1]).read() m = re.search(r'id="pilot"[^>]*>(.*?)', dom, re.S) print(m.group(1).strip() if m else "") PY )" if [[ -z "$result" ]]; then echo "PILOT FAIL: the page recorded nothing, so the check did not run." >&2 echo "the reporter most likely threw; diagnostics follow." >&2 echo "--- browser console ---" >&2 grep -iE 'CONSOLE.*(error|Uncaught|violates|refused)' "$WORK/chrome.log" | head -5 >&2 || true echo "--- dom size / page head ---" >&2 wc -c <"$WORK/dom.html" >&2 || true head -c 300 "$WORK/dom.html" >&2 || true echo >&2 echo "--- static server 404s ---" >&2 grep -oE 'GET /[^"]*" 404' "$WORK/site.log" | head -5 >&2 || true echo "--- pilot element ---" >&2 grep -o 'id="pilot"[^<]*' "$WORK/dom.html" | head -2 >&2 || true echo "--- theme service log (last 5) ---" >&2 tail -5 "$WORK/theme.log" >&2 || true fi echo echo "$result" [[ "$result" == PILOT\ PASS* ]]