SPB Git

Repository Public

run-sim.sh 3.2 KB 44 lines shellscript

1#!/usr/bin/env bash2# Author: Simon-Pierre Boucher — contact@spboucher.ai3# File: Scripts/run-sim.sh4# Description: Runs the self-test of « SP Mail Dev » in an iOS Simulator against the local dev backend (through the replay proxy, so that AI5# generations are answered from a recording). Captures the SIMULATOR screen only. Only the simulator booted here is shut down again.6#7# Usage: Scripts/run-sim.sh [--shot out.png] [--device <udid>]8#   Needs: Scripts/build.sh ios Debug, the dev backend (started here through Scripts/dev-backend.sh; SPMAIL_DEV_PORT / SPMAIL_DEV_DB / SPMAIL_REPLAY_PORT / SPMAIL_AI_STUB_PORT / SPMAIL_FAKE_APNS_PORT). The device defaults to Build/sim-iphone.udid.9set -euo pipefail10cd "$(dirname "$0")/.."11APP="${SPMAIL_DD:-$HOME/Library/Developer/SPMail/DerivedData}/Build/Products/Debug-iphonesimulator/SP Mail Dev.app"; BUNDLE=ai.spboucher.spmail.ios.dev12SHOT=""; UDID="$(cat Build/sim-iphone.udid 2>/dev/null || true)"13while [ $# -gt 0 ]; do case "$1" in --shot) SHOT="$2"; shift 2;; --device) UDID="$2"; shift 2;; *) echo "unknown argument $1"; exit 2;; esac; done14[ -d "$APP" ] || { echo "build first: Scripts/build.sh ios Debug"; exit 1; }15[ -n "$UDID" ] || { echo "no simulator: pass --device <udid> (xcrun simctl list devices)"; exit 1; }16Scripts/dev-backend.sh start >/dev/null   # one launcher: backend + AI stub + fake APNs (no-op when it already answers)17node Scripts/dev-bootstrap.mjs up >/dev/null18# shellcheck disable=SC109119source Build/dev-env.sh20BOOTED=021if ! xcrun simctl list devices booted | grep -q "$UDID"; then xcrun simctl boot "$UDID"; BOOTED=1; xcrun simctl bootstatus "$UDID" >/dev/null; fi22RPORT="${SPMAIL_REPLAY_PORT:-8822}"23SPMAIL_REPLAY_PORT="$RPORT" node Scripts/dev-replay-proxy.mjs > Build/replay-proxy.log 2>&1 &24PROXY=$!25cleanup() { kill $PROXY 2>/dev/null || true; xcrun simctl terminate "$UDID" "$BUNDLE" >/dev/null 2>&1 || true; if [ $BOOTED = 1 ]; then xcrun simctl shutdown "$UDID" >/dev/null 2>&1 || true; fi; }26trap cleanup EXIT27sleep 128xcrun simctl uninstall "$UDID" "$BUNDLE" >/dev/null 2>&1 || true   # a clean container: no stale cache, no stale report29xcrun simctl install "$UDID" "$APP"30xcrun simctl launch "$UDID" "$BUNDLE" -spmBaseURL "http://localhost:$RPORT" -spmDevToken "$SPMAIL_TEST_TOKEN" -spmSelfTest YES -spmNoPrompts YES >/dev/null31DATA="$(xcrun simctl get_app_container "$UDID" "$BUNDLE" data)/Library/Application Support"32SHOTS=""33for _ in $(seq 1 900); do34  P="$(cat "$DATA/SPMail-selftest-progress.txt" 2>/dev/null || true)"35  if [ -n "$SHOT" ] && [[ "$P" == reader || "$P" == studio-editor || "$P" == unified || "$P" == composer || "$P" == next-* ]] && [[ "$SHOTS" != *" $P"* ]]; then36    SHOTS="$SHOTS $P"; sleep 1.537    xcrun simctl io "$UDID" screenshot "${SHOT%.png}-$P.png" >/dev/null 2>&1 && echo "saved ${SHOT%.png}-$P.png"38  fi39  [ "$P" = done ] && break40  sleep 0.541done42cp "$DATA/SPMail-selftest.json" Build/selftest-ios.json 2>/dev/null || { echo "no self-test report (progress: ${P:-none})"; exit 1; }43/usr/bin/python3 -c 'import json,sys; r=json.load(open("Build/selftest-ios.json")); [print(("  ✓ " if s["ok"] else "  ✗ ")+s["step"]+("" if s["ok"] else " — "+s["detail"])) for s in r["steps"]]; print("iOS self-test:", r["passed"], "/", r["total"], "OK" if r["ok"] else "FAILED"); sys.exit(0 if r["ok"] else 1)'44
Files main
Menu

Theme