Repository Public
1#!/usr/bin/env bash2# Author: Simon-Pierre Boucher — contact@spboucher.ai3# File: Scripts/mac-scenarios.sh4# Description: Drives "SP Vault Dev" on macOS through scripted scenarios (App/Shared/Model/DevScenario.swift) against5# the real local server and saves pictures the app draws of its own window into docs/screenshots.6# This is NOT a click-level UI test: the steps call the same AppModel / engine functions the buttons7# call. It exists because XCUITest on macOS needs Automation Mode (administrator authentication).8# With Automation Mode enabled, use Scripts/ui-tests.sh mac instead (same journeys, real clicks).9#10# Usage: Scripts/mac-scenarios.sh main join → recovery kit → items → copy → search → favorite/trash/restore →11# import → Security Center → lock/unlock → screenshots (dark + light)12# Scripts/mac-scenarios.sh recover recovery with the recovery key on a fresh profile (after `main`)13# Scripts/mac-scenarios.sh pair the Mac approves the iPhone simulator (XCUITest test11) and both sync14set -uo pipefail15export PATH="/opt/homebrew/bin:/usr/local/bin:$PATH"16cd "$(dirname "$0")/.."17DD="${SPV_DD:-$HOME/Library/Developer/SPVault/DerivedData}"; DIR="${SPV_UI_DIR:-/tmp/spvault-ui}"; SHOTS="$PWD/docs/screenshots"18BIN="$DD/Build/Products/Debug/SP Vault Dev.app/Contents/MacOS/SP Vault Dev"19mkdir -p "$DIR" "$SHOTS" build/logs20sim() { xcrun simctl list devices | grep -F "$1 (" | head -1 | sed -E 's/.*\(([0-9A-F-]{36})\).*/\1/'; }21scenario() { # name, profile, account, reset(0/1), appearance, timeout, steps22 local name="$1" log="$DIR/scenario-$1.log"; rm -f "$log"23 SPV_DEV_SERVER="http://localhost:8781" SPV_DEV_PROFILE="$2" SPV_DEV_PASSKEY_FILE="$DIR/passkeys-$3.json" SPV_DEV_RESET="$4" SPV_DEV_APPEARANCE="$5" \24 SPV_DEV_ALLOW_CAPTURE=1 SPV_DEV_SCENARIO="$7" SPV_DEV_SCENARIO_LOG="$log" "$BIN" > "build/logs/scenario-$name.out" 2>&1 &25 local pid=$! t=026 until grep -q "^done" "$log" 2>/dev/null || ! kill -0 $pid 2>/dev/null || [ $t -ge "$6" ]; do27 for req in "$SHOTS"/*.request; do # the app asks for a real capture of its window (screencapture -l)28 [ -e "$req" ] || continue29 build/window-shot "SP Vault Dev" "${req%.request}" >/dev/null 2>&1; rm -f "$req"30 done31 sleep 1; t=$((t+1))32 done33 sleep 1; kill -0 $pid 2>/dev/null && kill $pid 2>/dev/null # only the process started here34 echo "== scenario $name"; sed 's/^/ /' "$log" 2>/dev/null35 grep -q "^done" "$log" 2>/dev/null && ! grep -q "^FAIL" "$log"36}37prepare() {38 Scripts/dev-server.sh up || exit 139 Scripts/build.sh mac >/dev/null || { echo "macOS Debug build failed"; exit 1; }40 [ -x build/window-shot ] || swiftc -O Scripts/window-shot.swift -o build/window-shot 2>/dev/null41 [ -s "$DIR/invites.txt" ] || Scripts/dev-server.sh invite "mac-scenario" | awk '/^ *token:/ {print $2}' > "$DIR/invites.txt"42 [ -f "$DIR/import.csv" ] || printf 'name,url,username,password,note\nImported Shop,https://shop.example.org,ada,123456,\nImported Forum,https://forum.example.org,ada,123456,\nOld Router,http://192.168.1.1,admin,admin,\nImported Bank,https://bank2.example.org,ada,Tr0ub4dor&3-horse-staple-91,\n' > "$DIR/import.csv"43}44case "${1:-}" in45 main) prepare46 scenario main mac-main mac 1 dark 180 "ready;join:$DIR/invites.txt|$DIR/account-mac.txt;shot:$SHOTS/mac-recovery-kit.png;kit-done;seed;select:Example Bank;copy-password;shot:$SHOTS/mac-item-detail.png;search:pocket;search:;favorite-trash-restore:Pocket Mail;import:$DIR/import.csv;section:security;shot:$SHOTS/mac-security.png;lock;shot:$SHOTS/mac-locked.png;unlock;select:Example Bank;shot:$SHOTS/mac-main-dark.png;shot-menubar:$SHOTS/mac-menubar.png;section:generator;shot:$SHOTS/mac-generator.png;quit" || exit 147 scenario light mac-main mac 0 light 90 "ready;unlock;select:Example Bank;shot:$SHOTS/mac-main-light.png;section:settings;shot:$SHOTS/mac-settings.png;section:devices;sleep:2;shot:$SHOTS/mac-devices.png;quit" ;;48 recover) prepare49 scenario recover mac-fresh none-mac 1 dark 90 "ready;recover:$DIR/account-mac.txt;wait-item:Example Bank;quit" ;;50 pair) prepare51 rm -f "$DIR/pairing.txt" "$DIR/paired.txt" "$DIR/trusted-wrote.txt"52 xcodegen generate --quiet53 ( TEST_RUNNER_SPV_UI_DIR="$DIR" TEST_RUNNER_SPV_UI_SHOTS="$SHOTS" TEST_RUNNER_SPV_UI_PAIR_WITH=mac xcodebuild -project SPVault.xcodeproj -scheme SPVault-iOS -configuration Debug \54 -destination "platform=iOS Simulator,id=$(sim "SPVault iPhone")" -derivedDataPath "$DD" test -only-testing:SPVaultUITests-iOS/JourneyTests/test11_PairAsNewDeviceAndSync > build/logs/ui-pair-iphone.log 2>&155 sed 's/\x1b\[[0-9;]*m//g' build/logs/ui-pair-iphone.log | grep -E "Test Case .*(passed|failed)|error:" | cut -c1-300 | sort -u ) &56 BG=$!57 scenario pair mac-main mac 0 dark 420 "ready;unlock;approve:$DIR/pairing.txt;write:$DIR/paired.txt;wait-item:From New Device;create:From Trusted Device;write:$DIR/trusted-wrote.txt;section:devices;sleep:2;shot:$SHOTS/mac-devices.png;sleep:20;quit"; A=$?58 wait $BG; exit $A ;;59 *) echo "usage: $0 main|recover|pair"; exit 2 ;;60esac61