#!/usr/bin/env bash # Behaviour gate for the Space Taxi simulation. # # Runs every hook level through stsim and compares the per-tick trace # against a golden capture. A refactor that changes nothing observable # leaves all seventeen traces byte-identical; anything else is a regression. # # H, W, T and X ride the C64's own attract recordings (the ones checked # against VICE traces). The other thirteen ride synthesised fixtures from # gateStreams.h -- a regression gate only, not evidence of C64 fidelity. # # gate.sh capture [dir] record goldens from the CURRENT tree # gate.sh check [dir] compare the current tree against them, or, with # none captured, against gateHashes.txt (the md5 # of each golden trace, the committed reference) # gate.sh hashes print one md5 per level (compact reference) # # Capture from a tree you trust, refactor, then check. The rides run on the # game's level bake, so build the game first (gateLib.sh finds it). set -u here=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) mode=${1:-check} dir=${2:-$here/golden} source "$here/gateLib.sh" case "$mode" in capture) mkdir -p "$dir" for p in $pairs; do l=${p%%:*}; n=${p##*:} "$here/stsim" "$levels/level$n.dat" "$l" "$ticks" > "$dir/demo$l.jsonl" 2>/dev/null printf ' %s: %s ticks\n' "$l" "$(wc -l < "$dir/demo$l.jsonl")" done echo "gate: captured to $dir" ;; check) fail=0 for p in $pairs; do l=${p%%:*}; n=${p##*:} got=$(mktemp) "$here/stsim" "$levels/level$n.dat" "$l" "$ticks" > "$got" 2>/dev/null if [ -f "$dir/demo$l.jsonl" ]; then if cmp -s "$dir/demo$l.jsonl" "$got"; then printf ' %s: IDENTICAL (%s ticks)\n' "$l" "$(wc -l < "$got")" else echo " $l: *** DIFFERS ***" diff "$dir/demo$l.jsonl" "$got" | head -3 fail=1 fi else want=$(awk -v l="$l" '$1 == l { print $2 }' "$here/gateHashes.txt") have=$(md5sum < "$got" | cut -d' ' -f1) if [ "$have" = "$want" ]; then printf ' %s: IDENTICAL (%s ticks, md5 as gateHashes.txt)\n' "$l" "$(wc -l < "$got")" else echo " $l: *** DIFFERS *** (md5 $have, gateHashes.txt ${want:-has none}; capture goldens from a trusted tree to see where)" fail=1 fi fi rm -f "$got" done [ $fail -eq 0 ] && echo "gate: PASS" || echo "gate: FAIL" # The cel census rides the same recordings: a cel a ride displays that # its manifest does not bake is a mid-ride interpreted sprite. "$here/celGate.sh" || fail=1 exit $fail ;; hashes) for p in $pairs; do l=${p%%:*}; n=${p##*:} h=$("$here/stsim" "$levels/level$n.dat" "$l" "$ticks" 2>/dev/null | md5sum | cut -d' ' -f1) printf '%s %s\n' "$l" "$h" done ;; *) sed -n '2,20p' "$0" exit 2 ;; esac