#!/usr/bin/env bash # Maker-output snapshot test. # Runs the three Phase-2/Phase-3 makers in a clean temp app and diffs # the output against the baselines in this directory. Detects silent # generator drift: any change to a maker template requires the # corresponding baseline to be updated in the same commit. set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" PROJECT_ROOT="$(cd "$SCRIPT_DIR/../../../.." && pwd)" BUNDLE="$PROJECT_ROOT/framework/php" WORK="$(mktemp -d)" trap 'rm -rf "$WORK"' EXIT INT TERM # Mirror the skeleton's tracked files into the temp dir. git -C "$PROJECT_ROOT" archive HEAD framework/skeleton/ | tar -xf - -C "$WORK" APP="$WORK/framework/skeleton" # Point the test app's path repo at the actual bundle dir (the # default '../../php' would resolve relative to /tmp). sed -i "s|\"../../php\"|\"$BUNDLE\"|" "$APP/symfony/composer.json" rm -f "$APP/symfony/composer.lock" ( cd "$APP/symfony" && composer install --no-interaction --quiet ) # Remove the existing maker outputs so the regenerators don't bail. rm -f "$APP/symfony/src/Entity/Todo.php" rm -f "$APP/symfony/src/Controller/TodoController.php" rm -f "$APP/qml/TodoList.qml" # Run every maker we cover. ( cd "$APP/symfony" \ && bin/console make:bridge:resource Todo --no-interaction >/dev/null \ && bin/console make:bridge:command MarkAllDone --no-interaction >/dev/null \ && bin/console make:bridge:window Todo --no-interaction >/dev/null ) # Compare each generated file to its snapshot baseline. fail=0 check() { local generated="$1" local baseline="$2" if ! diff -q "$generated" "$baseline" >/dev/null 2>&1; then echo "✗ snapshot mismatch: $(basename "$baseline")" >&2 diff -u "$baseline" "$generated" >&2 || true fail=1 else echo "✓ $(basename "$baseline")" fi } check "$APP/symfony/src/Entity/Todo.php" "$SCRIPT_DIR/Todo.php" check "$APP/symfony/src/Controller/TodoController.php" "$SCRIPT_DIR/TodoController.php" check "$APP/qml/TodoList.qml" "$SCRIPT_DIR/TodoList.qml" check "$APP/symfony/src/Controller/MarkAllDoneController.php" "$SCRIPT_DIR/MarkAllDoneController.php" check "$APP/qml/TodoWindow.qml" "$SCRIPT_DIR/TodoWindow.qml" if [ "$fail" -ne 0 ]; then echo "Snapshot test failed. If the change is intended, update the baselines under $SCRIPT_DIR/." >&2 exit 1 fi echo "All maker outputs match snapshots."