Repository Public
1#!/usr/bin/env bash2# Author: Simon-Pierre Boucher — contact@spboucher.ai3# File: Scripts/test-core.sh4# Description: Runs the SPMailCore tests, then the SPMailSystem tests (system-integration logic shared with the extensions; unit only). With `--integration`, also the tests against the local dev backend (real mail server, staging mailboxes created by dev-bootstrap.mjs).5#6# Usage: Scripts/test-core.sh [--integration] [swift test arguments…]7# Environment: SPMAIL_TEST_SHARED_TOKENS=1 — with --integration, use the tokens of Build/dev-env.sh instead of minting private ones.8# SPMAIL_SPM_SCRATCH — SwiftPM scratch path (default ~/Library/Developer/SPMail/spm-build). It must stay outside ~/Desktop;9# two builds of the package running at once (several agents, CI + a developer) need one scratch path each.10set -euo pipefail11cd "$(dirname "$0")/.."12SERIAL=()13if [[ "${1:-}" == "--integration" ]]; then14 shift15 # The integration suites share the two staging mailboxes: run one test at a time, or a test that measures quiet (« connecting costs16 # one sync pass ») sees the mail another suite is sending.17 SERIAL=(--no-parallel)18 Scripts/dev-backend.sh start19 node Scripts/dev-bootstrap.mjs up20 # shellcheck disable=SC109121 source Build/dev-env.sh22 # Session tokens of this run only (never written to disk). Build/dev-env.sh is shared: the app self-tests sign out with the token it23 # holds and the session-revocation test revokes the "victim" one, so the shared tokens can die in the middle of another run.24 # SPMAIL_TEST_SHARED_TOKENS=1 keeps the tokens of Build/dev-env.sh.25 if [[ "${SPMAIL_TEST_SHARED_TOKENS:-0}" != "1" ]]; then26 SPMAIL_TEST_TOKEN="$(node Scripts/dev-bootstrap.mjs token | tail -1)"27 SPMAIL_TEST_TOKEN_VICTIM="$(node Scripts/dev-bootstrap.mjs token | tail -1)"28 export SPMAIL_TEST_TOKEN SPMAIL_TEST_TOKEN_VICTIM29 fi30fi31SCRATCH="${SPMAIL_SPM_SCRATCH:-$HOME/Library/Developer/SPMail/spm-build}"32case "$SCRATCH" in "$HOME/Desktop"/*) echo "SPMAIL_SPM_SCRATCH must not be under ~/Desktop" >&2; exit 2 ;; esac33( cd Packages/SPMailCore && swift test --scratch-path "$SCRATCH" ${SERIAL[@]+"${SERIAL[@]}"} "$@" )34# the system package has no integration tests and takes no filter: it runs whole unless a filter was given for the core35if [[ $# -eq 0 ]]; then ( cd Packages/SPMailSystem && swift test --scratch-path "$SCRATCH-system" ); fi36