Files
Accessibility ModandClaude Opus 5 c841bcc68d testbed: stop destroying the player's save
The documented way to run the testbed began with

    rm -rf ~/AppData/Roaming/LOVE/Alchemist

which is the player's actual playthrough. It was written down as the
official procedure in four places, so every run of the test suite ate a
real save -- including twice in the session that produced the previous
commit. Reported by Talon.

The testbed does genuinely need an empty save directory: it drives a new
game from the main menu through the prologue, which has already happened
in any real save. So tests/run-testbed.sh MOVES the save aside (never
deletes it), runs, discards the test run's directory and moves the real
one back. Restore is on an EXIT trap plus INT/TERM, so it also happens on
a failed run, a crash and Ctrl-C. If the restore itself fails it says so
loudly and leaves the backup on disk rather than pressing on.

This cannot live inside the mod: love.load calls config.initialize,
keybindings.initialize and user.initialize long before main.lua reaches
require("accessibility").initialize(), so by the time any of our Lua runs
the save directory has already been read. The swap has to happen around
the process.

The rm -rf is removed from all four docs that carried it, each replaced
with the script and the reason not to clear that directory by hand --
being written down as procedure is what made it recur.

accessibility/.gitattributes forces LF on *.sh, or a Windows checkout
hands bash a \r and the script dies. It sits inside accessibility/ on
purpose: a top-level one would show up in the game-file footprint check,
which still reads `main.lua | 1 +`.

Verified with a marker file in a populated save directory: 38 checks, 0
failures, marker intact, no leftover backup directories.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-02 02:59:34 +02:00

86 lines
2.7 KiB
Bash

#!/usr/bin/env bash
#
# Run the accessibility testbed against a clean save, WITHOUT destroying the
# player's real one.
#
# The testbed drives a fresh playthrough from the main menu, so it needs the
# LOVE save directory empty -- otherwise "Continue" appears, the new-game flow
# differs, and the prologue it navigates has already happened. That clean-out
# used to be a bare `rm -rf` in the docs, which silently ate a real save every
# time someone ran the tests.
#
# This cannot be done from inside the mod: love.load() reads config, keybindings
# and user data long before main.lua reaches our entry point, so by the time any
# Lua of ours runs the save directory has already been read. It has to happen
# around the process.
#
# So: MOVE the save aside (never delete it), run, then move it back. The test
# run's own save directory is discarded, leaving the tree exactly as it was.
#
# Usage: accessibility/tests/run-testbed.sh [extra love args...]
set -uo pipefail
LOVE="${LOVE:-C:/Program Files/LOVE/lovec.exe}"
GAME_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
# LOVE writes to <appdata>/LOVE/<t.identity>; conf.lua sets identity "Alchemist".
SAVE_DIR="${APPDATA:-$HOME/AppData/Roaming}/LOVE/Alchemist"
BACKUP_DIR="${SAVE_DIR}.a11y-backup.$$"
restored=0
restore() {
# Idempotent: this runs from the EXIT trap and possibly from a signal trap.
if [ "$restored" -eq 1 ]; then
return
fi
restored=1
# Throw away whatever the test run created, but only if we know it is ours
# (i.e. we successfully moved the real save out of the way first).
if [ -d "$BACKUP_DIR" ]; then
rm -rf "$SAVE_DIR"
if mv "$BACKUP_DIR" "$SAVE_DIR"; then
echo "[testbed] real save restored to $SAVE_DIR"
else
# Loud, and non-destructive: the save is still on disk, just parked.
echo "[testbed] !! COULD NOT RESTORE YOUR SAVE." >&2
echo "[testbed] !! It is safe at: $BACKUP_DIR" >&2
echo "[testbed] !! Move it back to: $SAVE_DIR" >&2
exit 1
fi
else
# There was no save to begin with; don't leave the test run's one behind
# to be mistaken for a real save later.
rm -rf "$SAVE_DIR"
fi
}
# Checked BEFORE anything is moved, so a bad LOVE path can't leave the save
# parked under a backup name.
if [ ! -f "$LOVE" ]; then
echo "[testbed] LOVE not found at: $LOVE" >&2
echo "[testbed] set LOVE=/path/to/lovec.exe" >&2
exit 1
fi
trap restore EXIT
trap 'restore; exit 130' INT TERM
if [ -e "$SAVE_DIR" ]; then
if ! mv "$SAVE_DIR" "$BACKUP_DIR"; then
echo "[testbed] could not move the save aside; refusing to run rather than" >&2
echo "[testbed] risk your save. Is the game still open?" >&2
exit 1
fi
echo "[testbed] real save parked at $BACKUP_DIR"
else
echo "[testbed] no existing save to protect"
fi
"$LOVE" "$GAME_DIR" --a11y-test "$@"
status=$?
exit $status