SPB Git

Repository Public

test-live.sh 3.9 KB 59 lines shellscript

1#!/usr/bin/env bash2# SP Notes iOS3# File: Scripts/test-live.sh4# Description: Runs the tests that need a real backend against the INTEGRATION server of SP Note Next (M4M64c:127.0.0.1:8486,5#              branch next-int, database note_next_int_dev — never production): opens the SSH tunnel on the SAME local port when6#              nothing listens on it yet (and closes only the forward it opened), creates a development session on the node,7#              runs the live suites on the simulator (the offline scenario of notes and the one of tasks). The token is never8#              printed. usage: test-live.sh [extra xcodebuild arguments]9#10# Author: Simon-Pierre Boucher11# Contact: contact@spboucher.ai12set -uo pipefail13cd "$(dirname "$0")/.."14SIM="${SPNOTES_SIM:-iPhone 17 Pro}"15PORT=848616NODE=M4M64c17SOCKET="/tmp/spnotes-live-$$.sock"18OPENED=019cleanup() { if [[ $OPENED == 1 ]]; then ssh -S "$SOCKET" -O exit "$NODE" >/dev/null 2>&1; fi; }20trap cleanup EXIT21if ! nc -z localhost $PORT 2>/dev/null; then22  # a control socket of our own: `-O exit` on it closes this forward and nothing else23  ssh -f -N -M -S "$SOCKET" -o ExitOnForwardFailure=yes -L $PORT:127.0.0.1:$PORT "$NODE" || { echo "tunnel impossible"; exit 1; }24  OPENED=125fi26# the integration server must answer before anything is run (reported, never faked)27CODE=$(curl -s -o /dev/null -m 10 -w "%{http_code}" "http://localhost:$PORT/api/meta" || true)28[[ "$CODE" == "401" || "$CODE" == "200" || "$CODE" == "403" ]] || { echo "serveur d'intégration injoignable sur le port $PORT (HTTP $CODE)"; exit 1; }29TOKEN=$(ssh "$NODE" 'cd ~/dev/note-next-int && export PATH=/opt/homebrew/bin:$PATH && set -a && . ./.env && set +a && node node_modules/tsx/dist/cli.mjs scripts/dev-session.ts' 2>/dev/null | tail -1)30[[ ${#TOKEN} -ge 40 ]] || { echo "session de développement impossible"; exit 1; }31mkdir -p build/logs32if [[ "${1:-}" == "ui" ]]; then33  # the hosted SPNotesFeatures screens opened on screen, signed in on the integration server; screenshots → /tmp/spnote-next/shots-ios/hosted-*34  shift35  RESULT="build/results/live-ui-${SIM// /_}.xcresult"; SHOTS="build/shots/live-${SIM// /_}"36  rm -rf "$RESULT" "$SHOTS"; mkdir -p "$SHOTS" /tmp/spnote-next/shots-ios37  TEST_RUNNER_SPNOTES_LIVE_URL="http://localhost:$PORT" TEST_RUNNER_SPNOTES_LIVE_TOKEN="$TOKEN" \38  xcodebuild -project SPNotes.xcodeproj -scheme SPNotes -destination "platform=iOS Simulator,name=$SIM" -derivedDataPath build/DerivedData \39    -only-testing:SPNotesUITests/HostedSectionsLiveUITests -resultBundlePath "$RESULT" "$@" test 2>&1 \40    | sed "s/$TOKEN/<jeton>/g" | tee "build/logs/test-live-ui-${SIM// /_}.log" | grep -E "Executed [0-9]+ tests|: error|\*\* " | sort -u | cut -c1-400 | head -6041  xcrun xcresulttool export attachments --path "$RESULT" --output-path "$SHOTS" >/dev/null 2>&1 || true42  python3 - "$SHOTS" <<'PY'43import json,sys,shutil,os,re44d=sys.argv[1]; out='/tmp/spnote-next/shots-ios'; n=045for test in json.load(open(os.path.join(d,'manifest.json'))):46    for a in test.get('attachments',[]):47        base=re.sub(r'_\d+_[0-9A-F-]{36}\.png$','',a.get('suggestedHumanReadableName',''))48        if base.startswith('hosted-'):49            shutil.copy(os.path.join(d,a['exportedFileName']),os.path.join(out,base+'.png')); n+=150print(n,'captures copiées')51PY52  exit 053fi54# the app sends `Origin: http://localhost:8486` itself (the origin of its base URL), which the server requires on mutations55TEST_RUNNER_SPNOTES_LIVE_URL="http://localhost:$PORT" TEST_RUNNER_SPNOTES_LIVE_TOKEN="$TOKEN" \56xcodebuild -project SPNotes.xcodeproj -scheme SPNotes -destination "platform=iOS Simulator,name=$SIM" -derivedDataPath build/DerivedData \57  -only-testing:SPNotesTests/OfflineScenarioTests -only-testing:SPNotesTests/TasksLiveTests "$@" test 2>&1 \58  | sed "s/$TOKEN/<jeton>/g" | tee build/logs/test-live.log | grep -E "error|✘|✔|Test run|\*\* " | grep -v "^\s*|" | sort -u | cut -c1-400 | head -4059
Files main
Menu

Theme