#!/usr/bin/env bash set -euo pipefail # End-to-end UI run: the real panel, in the ACTIVE app, typed into with the keyboard # and clicked with the mouse. Launched through LaunchServices ("open -n") because a # background shell launch can never get a key window — macOS will not let it activate. # # ./scripts/run-e2e-ui.sh # # Builds a throwaway copy of the signed app under a separate bundle identifier # (ai.flowmaster.shotdeck.e2e) so it can run alongside the installed Redline without # touching /Applications, Ben's real captures, or his real preferences. It writes its # results to a file and exits. ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" SOURCE_APP="${ROOT}/.build/Redline.app" E2E_APP="${ROOT}/.build/RedlineE2E.app" IDENTITY="Apple Development: ben@flow-master.ai (QH2H9G2LK5)" BUNDLE_ID="ai.flowmaster.shotdeck.e2e" WORK_DIR="$(mktemp -d /tmp/redline-e2e.XXXXXX)" RESULT="${WORK_DIR}/result.txt" if [[ ! -d "${SOURCE_APP}" ]]; then echo "No ${SOURCE_APP} found. Run ./scripts/build-app.sh first." >&2 exit 1 fi # A leftover instance from an interrupted run would hold the bundle identifier and # make "open -n" a no-op. pkill -f "RedlineE2E.app/Contents/MacOS/Shotdeck" >/dev/null 2>&1 || true for _ in $(seq 1 20); do pgrep -f "RedlineE2E.app/Contents/MacOS/Shotdeck" >/dev/null 2>&1 || break sleep 0.2 done rm -rf "${E2E_APP}" ditto "${SOURCE_APP}" "${E2E_APP}" /usr/libexec/PlistBuddy -c "Set :CFBundleIdentifier ${BUNDLE_ID}" "${E2E_APP}/Contents/Info.plist" /usr/libexec/PlistBuddy -c "Set :CFBundleName Redline E2E" "${E2E_APP}/Contents/Info.plist" # A menu-bar app (LSUIElement) is never activated by LaunchServices, and macOS only # lets an active app own the key window the keyboard goes to. The test copy is a # regular app for the duration of the run; the shipped app keeps LSUIElement. /usr/libexec/PlistBuddy -c "Set :LSUIElement false" "${E2E_APP}/Contents/Info.plist" codesign --force --options runtime \ --sign "${IDENTITY}" \ --identifier "${BUNDLE_ID}" \ "${E2E_APP}" open -n "${E2E_APP}" --args --selftest e2e --root "${WORK_DIR}/storage" --result "${RESULT}" for _ in $(seq 1 120); do if [[ -f "${RESULT}" ]] && grep -qE "^E2E (PASS|FAIL)$" "${RESULT}"; then break fi sleep 0.25 done sleep 0.5 osascript -e "tell application id \"${BUNDLE_ID}\" to quit" >/dev/null 2>&1 || true if [[ ! -f "${RESULT}" ]]; then echo "E2E FAIL: no result file was written (${RESULT})" >&2 exit 1 fi cat "${RESULT}" grep -q "^E2E PASS$" "${RESULT}"