SPB Git

Repository Public

system-shots.sh 6.3 KB 87 lines shellscript

1#!/usr/bin/env bash2# Author: Simon-Pierre Boucher — contact@spboucher.ai3# File: Scripts/system-shots.sh4# Description: Captures the system-integration screens of « SP Mail Dev » in an iOS Simulator: Settings › Notifications, notification banners5# with their actions, the widget gallery and the share extension. The UI is driven by the SPMailSystemUITests bundle; this script sends a6# real message between the two staging mailboxes of the dev bootstrap, delivers the pushes the server would send with `xcrun simctl push`7# (a simulator cannot receive APNs from the fake host) and captures the SIMULATOR screen when the test asks for it. It also checks on the8# server that the « mark as read » action tapped in the banner really marked the message.9#10# Usage: Scripts/system-shots.sh <udid> <prefix> notifications|widgets|share11#   Needs: Scripts/build.sh ios Debug, the dev backend (Scripts/dev-backend.sh start), node Scripts/dev-bootstrap.mjs up.12# Environment: SPMAIL_DD, SPMAIL_SHOTS (default /tmp/spmail-next-shots/apple-system).13set -euo pipefail14cd "$(dirname "$0")/.."15UDID="$1"; PREFIX="$2"; WHAT="$3"; BUNDLE=ai.spboucher.spmail.ios.dev16DD="${SPMAIL_DD:-$HOME/Library/Developer/SPMail/DerivedData}"; OUT="${SPMAIL_SHOTS:-/tmp/spmail-next-shots/apple-system}"; mkdir -p "$OUT" Build17case "$WHAT" in notifications) TEST=testNotifications;; widgets) TEST=testWidgets;; share) TEST=testShare;; *) echo "usage: system-shots.sh <udid> <prefix> notifications|widgets|share"; exit 2;; esac18node Scripts/dev-bootstrap.mjs up >/dev/null19# shellcheck disable=SC109120source Build/dev-env.sh21TOKEN="$(node Scripts/dev-bootstrap.mjs token | tail -1)"   # a session of its own: the app's sign-out elsewhere cannot kill it22api() { curl -fsS -H "Authorization: Bearer $TOKEN" -H "X-SPMail-Client: native" -H "Content-Type: application/json" "$@"; }2324# one real message A → B to notify about (and a second one for the tap-to-open check)25send() { api -X POST -H "Idempotency-Key: shots-$RANDOM$RANDOM$RANDOM" "$SPMAIL_TEST_BASE_URL/api/v1/messages/send" -d "{\"from\":\"$SPMAIL_TEST_ADDRESS_A\",\"to\":[\"$SPMAIL_TEST_ADDRESS_B\"],\"subject\":\"$1\",\"text\":\"$2\"}" >/dev/null; }26find_mail() { # subject → "email_id thread_id" in mailbox B27  for _ in $(seq 1 40); do28    R="$(api -G "$SPMAIL_TEST_BASE_URL/api/next/search" --data-urlencode "q=subject:\"$1\"" --data-urlencode "mailboxes=$SPMAIL_TEST_MAILBOX_B" 2>/dev/null | /usr/bin/python3 -c 'import json,sys29d=json.load(sys.stdin).get("data",[])30d=[r for r in d if r.get("mailbox_id")==sys.argv[1]]31print(d[0]["email_id"], d[0].get("thread_id") or d[0]["email_id"]) if d else None' "$SPMAIL_TEST_MAILBOX_B" 2>/dev/null || true)"32    [ -n "$R" ] && [ "$R" != None ] && { echo "$R"; return 0; }; sleep 1.533  done; return 134}35payload() { # file kind category title subtitle body email thread36  /usr/bin/python3 - "$@" <<'PY'37import json, sys38f, kind, category, title, subtitle, body, mb, email, thread = sys.argv[1:10]39alert = {"title": title, "body": body}40if subtitle: alert["subtitle"] = subtitle41json.dump({"Simulator Target Bundle": "ai.spboucher.spmail.ios.dev",42           "aps": {"alert": alert, "badge": 1, "sound": "default", "thread-id": f"{mb}:{thread}", "category": category, "mutable-content": 1, "interruption-level": "active"},43           "mb": mb, "email": email, "thread": thread, "kind": kind}, open(f, "w"), ensure_ascii=False)44PY45}46if [ "$WHAT" = notifications ]; then47  RUN="$(date +%H%M%S)"48  send "Ordre du jour de jeudi $RUN" "Bonjour, voici les points à couvrir jeudi : budget, calendrier, embauches."49  send "Version révisée du rapport $RUN" "J’ai intégré vos commentaires dans la section 3."50  read -r E1 T1 <<<"$(find_mail "Ordre du jour de jeudi $RUN")"; read -r E2 T2 <<<"$(find_mail "Version révisée du rapport $RUN")"51  payload Build/push-new.json new MAIL_NEW "Apple Essai A" "Ordre du jour de jeudi $RUN" "Bonjour, voici les points à couvrir jeudi : budget, calendrier, embauches." "$SPMAIL_TEST_MAILBOX_B" "$E1" "$T1"52  payload Build/push-reminder.json reminder MAIL_REMINDER "Apple Essai A" "" "Ordre du jour de jeudi $RUN" "$SPMAIL_TEST_MAILBOX_B" "$E1" "$T1"53  payload Build/push-new2.json new MAIL_NEW "Apple Essai A" "Version révisée du rapport $RUN" "J’ai intégré vos commentaires dans la section 3." "$SPMAIL_TEST_MAILBOX_B" "$E2" "$T2"54  echo "messages: $E1 / $E2"55fi5657BOOTED=058if ! xcrun simctl list devices booted | grep -q "$UDID"; then xcrun simctl boot "$UDID"; BOOTED=1; xcrun simctl bootstatus "$UDID" >/dev/null; fi59DATA="$HOME/Library/Developer/CoreSimulator/Devices/$UDID/data"60find "$DATA/Containers/Data/Application" -name spm-marker.txt -delete 2>/dev/null || true61xcodegen generate --quiet62TEST_RUNNER_SPM_BASE_URL="$SPMAIL_TEST_BASE_URL" TEST_RUNNER_SPM_TOKEN="$TOKEN" TEST_RUNNER_SPM_SHARE_TO="$SPMAIL_TEST_ADDRESS_B" \63  xcodebuild test -project SPMail.xcodeproj -scheme SPMail-iOS-SystemShots -destination "id=$UDID" -derivedDataPath "$DD" \64  -only-testing:"SPMailSystemUITests/SystemShots/$TEST" > "Build/system-shots-$WHAT.log" 2>&1 &65XPID=$!66LAST=""67while kill -0 $XPID 2>/dev/null; do68  M="$(find "$DATA/Containers/Data/Application" -name spm-marker.txt -exec cat {} \; 2>/dev/null | head -1 || true)"69  if [ -n "$M" ] && [ "$M" != "$LAST" ]; then70    LAST="$M"; CMD="${M#* }"71    case "$CMD" in72      push:*) xcrun simctl push "$UDID" "$BUNDLE" "Build/push-${CMD#push:}.json" >/dev/null 2>&1 && echo "pushed ${CMD#push:}" ;;73      shot:*) xcrun simctl io "$UDID" screenshot "$OUT/$PREFIX-${CMD#shot:}.png" >/dev/null 2>&1 && echo "saved $OUT/$PREFIX-${CMD#shot:}.png" ;;74    esac75  fi76  sleep 0.377done78wait $XPID && echo "ui test: passed" || { echo "ui test: FAILED (Build/system-shots-$WHAT.log)"; grep -E "error:|XCTAssert|failed" "Build/system-shots-$WHAT.log" | head -8; }79if [ "$WHAT" = notifications ]; then80  SEEN="$(api -G "$SPMAIL_TEST_BASE_URL/api/next/search" --data-urlencode "q=subject:\"Ordre du jour de jeudi $RUN\"" --data-urlencode "mailboxes=$SPMAIL_TEST_MAILBOX_B" | /usr/bin/python3 -c 'import json,sys81d=[r for r in json.load(sys.stdin).get("data",[]) if r.get("mailbox_id")==sys.argv[1]]82k=d[0].get("keywords") if d else None83print("read" if k and ("$seen" in k) else "unread")' "$SPMAIL_TEST_MAILBOX_B")"84  echo "server state of the message after the banner action « Marquer comme lu »: $SEEN"85fi86[ $BOOTED = 1 ] && xcrun simctl shutdown "$UDID" >/dev/null 2>&1 || true87
Files main
Menu

Theme