Files
ttrpg-initiative-tracker/scripts/run-tests.sh
T
david raistrick 2c997de0da Fix undo/redo forward-state restore, harden test infra, skip-guard
Root cause: mutation writers stored oldValues only. Redo rebuilt from
current state via derived logic — wrong order, wrong content, or no-op.
Undo patched fields in place but ignored roster/array order changes.

Writers now store forward arrays (shared/turn.js):
- addParticipant: newTurnOrderIds, newCurrentTurnParticipantId
- removeParticipant: newTurnOrderIds, newCurrentTurnParticipantId
- updateParticipant: oldTurnOrderIds + newTurnOrderIds (initiative re-slot)
- reorderParticipants: newParticipants + newTurnOrderIds
- damage/heal/deathSave/stabilize/revive/deactivate_dead_monster:
  oldValues + newValues both capture full death state incl conditions

expandUndo redo uses stored forward state instead of deriving:
- add/remove: order via newTurnOrderIds
- update: initiative change re-orders both directions
- reorder: re-applies newParticipants
- death ops: restore via newValues (was HP-only, dropped status/conditions)

Missing expandUndo cases added: stabilize, revive, deactivate_dead_monster
(were default:null -> undo no-op).

Test infra (shared/tests/_helpers.js):
- Mock storage undo() real now: applies patch + flips undone flag (was no-op)
- addDoc persists log entries, getCollection returns them
- undoLast/redoLast harness helpers exercise real mechanism
- Undo tests assert against actual persisted doc, not expandUndo output

turn.undo.test.js rewritten: every op tested as undo->deepEqual before,
redo->deepEqual after-op (12 cases). Was undo-only, redo untested.
turn.deathsave.undo.test.js added: 11 death-path roundtrips.

Dead code removed:
- round-trip.test.js: skipped suite testing deleted replay-from-logs.js
  (5 skipped tests rotting). Coverage gap acknowledged in TODO.

Skip-guard added (scripts/run-tests.sh): pre-flight grep refuses to run
if any .skip/xdescribe/xit found in test dirs. No CI; this is the gate.
2026-07-06 18:09:28 -04:00

55 lines
1.7 KiB
Bash
Executable File

#!/usr/bin/env bash
# scripts/run-tests.sh — run all 3 test suites with hard timeout.
# Design spec: tests never take >60s. Hang = failure, not silent.
# Each suite gets 60s. Total cap = 180s. Exits non-zero on timeout OR failure.
set -euo pipefail
TIMEOUT_BIN=gtimeout
command -v gtimeout >/dev/null 2>&1 || TIMEOUT_BIN=timeout
if ! command -v "$TIMEOUT_BIN" >/dev/null 2>&1; then
echo "ERROR: need 'timeout' (coreutils) or 'gtimeout' (brew coreutils)" >&2
exit 2
fi
run_suite () {
local label="$1"; shift
local cmd="$1"; shift
local secs="${1:-60}"
echo "=== $label (${secs}s cap) ==="
if $TIMEOUT_BIN --signal=KILL "$secs" bash -c "$cmd"; then
echo "=== $label: PASS ==="
else
local rc=$?
if [ "$rc" -eq 137 ] || [ "$rc" -eq 124 ]; then
echo "=== $label: FAIL — timeout (${secs}s exceeded, killed) ===" >&2
else
echo "=== $label: FAIL (exit $rc) ===" >&2
fi
exit "$rc"
fi
}
# Pre-flight: refuse to run if any test is skipped/disabled.
# Skipped tests rot silently. Catch them before they hide coverage gaps.
check_for_skips () {
echo "=== skip-guard ==="
local hits
hits=$(grep -rnE '\.(skip|todo)\(|xdescribe\(|xit\(' src/tests shared/tests server/tests 2>/dev/null || true)
if [ -n "$hits" ]; then
echo "FAIL: skipped/disabled tests found:" >&2
echo "$hits" >&2
echo "" >&2
echo "Fix or delete. Do not skip." >&2
exit 1
fi
echo "=== skip-guard: PASS ==="
}
check_for_skips
run_suite "app" "CI=true npx react-scripts test --watchAll=false" 60
run_suite "shared" "npm test --workspace shared" 30
run_suite "server" "npm test --workspace server" 30
echo "=== ALL SUITES GREEN ==="