pcbjam/scripts/update-baseline-screenshots.sh

82 lines
2.3 KiB
Shell
Raw Normal View History

#!/bin/bash
# Update baseline screenshots from test results
# Only copies:
# - NEW screenshots (not in baseline)
# - Screenshots with SIGNIFICANT differences (>5% size change) when --all flag used
#
# Usage:
# ./update-baseline-screenshots.sh # Only copy NEW screenshots
# ./update-baseline-screenshots.sh --all # Copy new + significantly different
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
TESTS_DIR="$SCRIPT_DIR/../tests"
COPY_ALL=0
THRESHOLD=5 # Percent threshold for "significant" difference
while [ $# -gt 0 ]; do
case "$1" in
--all) COPY_ALL=1; shift ;;
*) shift ;;
esac
done
refactor: collapse dual-mode plumbing — the DOM port is the only WASM build The canvas (wxUniversal) mode is gone (wxwidgets submodule); remove every piece of side-by-side plumbing so there is exactly one build and one test flow: - scripts/build-wxuniversal-wasm.sh -> scripts/build-wx-wasm.sh; no --dom/--enable-universal; builds into build-wasm/wxwidgets - build-wasm-test.sh: no DOM_BUILD / apps-dom rsync mirror / PORT=dom; apps build straight into tests/apps (Makefile.wasm PORT conditionals collapsed; wx.js + wx-dom.js always pre-js) - docker/build.sh, build-kicad-target.sh, env.sh: WX_PORT / -dom / -universal suffixes removed; kicad builds to kicad-<app>, outputs to output/; wx.js/wx-dom.js copied from the real source path (/workspace/wxwidgets/build/wasm — the old build-wasm path never existed and silently failed) - setup-kicad-wasm.sh: single target dir; the perl wx-dom.js injection is gone — the 7 checked-in kicad pages now reference wx-dom.js directly - playwright configs serve apps/; fixtures drop the test-results/dom and logs/wxwidgets/dom namespacing; boot.spec asserts wxDomPort unconditionally; pcbnew.spec uses one reference image; appearance.spec assertions unconditional - compare/update-baseline-screenshots.sh: --port removed - tests/gal-regression/wasm/Makefile: links build-wasm/wxwidgets and carries wx-dom.js as a second pre-js — the gal-webgl suite (30 specs) now actually builds and runs here (it needed host-side boost+glm via scripts/deps; the bundle had been missing, timing the whole spec out) - tests: clickCanvas() dispatches via page.mouse (DOM widgets legitimately cover the canvas; locator actionability refused the click); the comprehensive spec drives wxChoice through its native <select> (browser-owned popup cannot be coordinate-clicked) - docs: README/CLAUDE.md/build.md script names and dirs; features/wx-dom-port README reframed (DOM is THE port), visual-notes bugs 26-28; FindwxWidgets.cmake config label drops 'wasmuniv' - wxwidgets submodule -> 9dbacc9448 (DOM-only port, fork diff shrunk) Gate: full wx e2e suite 292 passed / 1 skipped / 0 failed — first run ever with the gal-webgl specs green (28 scenarios + load + sequential). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-12 10:18:16 +02:00
SOURCE_DIR="$TESTS_DIR/test-results"
DEST_DIR="$TESTS_DIR/baseline-screenshots"
if [ $COPY_ALL -eq 1 ]; then
echo "Mode: Copy NEW + SIGNIFICANTLY DIFFERENT screenshots"
else
echo "Mode: Copy NEW screenshots only (use --all to include significant changes)"
fi
if [ ! -d "$SOURCE_DIR" ]; then
echo "Error: test-results directory not found at $SOURCE_DIR"
echo "Run 'npm test' first to generate screenshots"
exit 1
fi
mkdir -p "$DEST_DIR"
new_count=0
updated_count=0
for src_file in "$SOURCE_DIR"/*.png; do
[ -f "$src_file" ] || continue
filename=$(basename "$src_file")
dest_file="$DEST_DIR/$filename"
if [ ! -f "$dest_file" ]; then
# NEW: Screenshot doesn't exist in baseline
echo "NEW: $filename"
cp "$src_file" "$dest_file"
((new_count++))
elif [ $COPY_ALL -eq 1 ]; then
# Check if significantly different
src_size=$(stat -f%z "$src_file" 2>/dev/null || stat -c%s "$src_file")
dest_size=$(stat -f%z "$dest_file" 2>/dev/null || stat -c%s "$dest_file")
if [ "$dest_size" -eq 0 ]; then
diff_pct=100
else
diff=$((src_size - dest_size))
diff=${diff#-} # Absolute value
diff_pct=$((diff * 100 / dest_size))
fi
if [ "$diff_pct" -ge "$THRESHOLD" ]; then
echo "UPDATED ($diff_pct% diff): $filename"
cp "$src_file" "$dest_file"
((updated_count++))
fi
fi
done
echo ""
echo "=== Summary ==="
echo "New screenshots added: $new_count"
if [ $COPY_ALL -eq 1 ]; then
echo "Significantly changed: $updated_count"
fi
echo "Total in baseline: $(ls -1 "$DEST_DIR"/*.png 2>/dev/null | wc -l | tr -d ' ')"