#!/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 ) 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 } clear_outputs() { rm -f "$APP/symfony/src/Entity/Todo.php" rm -f "$APP/symfony/src/Controller/TodoController.php" rm -f "$APP/symfony/src/Dto/CreateTodoDto.php" rm -f "$APP/symfony/src/Dto/UpdateTodoDto.php" rm -f "$APP/qml/TodoList.qml" } # ── Mode 1: legacy (no --with-dto) ──────────────────────────────────── clear_outputs ( 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 ) 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" # ── Mode 2: --with-dto (re-runs make:bridge:resource only) ──────────── # The entity + QML output is byte-identical between modes; only the # controller swaps and the two DTOs appear. Re-checking the unchanged # outputs would just be noise. clear_outputs ( cd "$APP/symfony" \ && bin/console make:bridge:resource Todo --with-dto --no-interaction >/dev/null ) check "$APP/symfony/src/Controller/TodoController.php" "$SCRIPT_DIR/TodoControllerWithDto.php" check "$APP/symfony/src/Dto/CreateTodoDto.php" "$SCRIPT_DIR/CreateTodoDto.php" check "$APP/symfony/src/Dto/UpdateTodoDto.php" "$SCRIPT_DIR/UpdateTodoDto.php" 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 (legacy + --with-dto modes)."