#!/usr/bin/env bash # Part of JoeyLib, Copyright (c) 2026 Scott Duensing, under the MIT License. # See LICENSE.md for license information. # SPDX-License-Identifier: MIT # # verify-web-save.sh - Save gate for the web port: a save outlives the page, # and each page keeps its own. # # A web program's SAVES/ is kept in the browser's IndexedDB (the SDL3 # backend mounts IDBFS there with autoPersist, so each file is written back # as it is closed, and again when the page is left), in a folder named after # the page: SAVE.html's is /SAVE/SAVES, a store of its own on a site every # page shares. SAVE (examples/save) counts its launches in SAVES/runs.dat. # Its folder is served with a second copy of its page, OTHER.html, and in # one headless Chromium OTHER.html is opened first (its own count, 1), then # SAVE.html, given time to write, opened again (reloaded), and given time # again: the count SAVE.html then holds must be 2 -- the first launch's 1 # came back from IndexedDB and the second launch added one; a store shared # with OTHER.html would say 3. Each wait covers a cold browser loading the # program (4 s once fell short). # # Usage: scripts/verify-web-save.sh # Requires: Chromium, emsdk's node; build/web/bin/SAVE (make web). set -euo pipefail repo=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd) source "$repo/scripts/lib/joeyEnv.sh" source "$repo/scripts/lib/webGate.sh" webNeed dir=$repo/build/web/bin/SAVE [ -f "$dir/SAVE.html" ] || { echo "verify-web-save: build SAVE first (make web)" >&2; exit 2; } work=$(mktemp -d -t joeylib-web-save.XXXXXX) cleanup() { webStop rm -rf "$work" } trap cleanup EXIT cp -r "$dir" "$work/site" cp "$work/site/SAVE.html" "$work/site/OTHER.html" webServe "$work/site" webDrive "OTHER.html" --step wait:8 --step open:SAVE.html --step wait:8 --step reload --step wait:8 --file "/SAVE/SAVES/runs.dat:$work/runs.dat" count=$(python3 -c "import struct, sys; print(struct.unpack('&2 exit 1 fi