#!/usr/bin/env bash

set -euo pipefail

repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$repo_root"

destination="${KIVO_TEST_DESTINATION:-platform=iOS Simulator,name=iPhone 17 Pro,OS=latest}"
derived_data_path="${KIVO_TEST_DERIVED_DATA_PATH:-$repo_root/build/KivoAppStoreLiteTests}"

# App Store Release supplies KIVO_APP_STORE_LITE. ENABLE_TESTABILITY is an
# invocation-only override so the shipping configuration remains optimized and
# does not expose testable module interfaces.
#
# The shared SignalServiceKitTests target also contains tests for donation and
# payment source files that App Store Lite intentionally compile-excludes. Xcode
# compiles every source in a test target even when -only-testing selects one
# suite, so exclude those unrelated test sources for this focused Lite run.
xcodebuild test \
  -workspace Signal.xcworkspace \
  -scheme Kivo-Backup-Tests \
  -configuration "App Store Release" \
  -destination "$destination" \
  -derivedDataPath "$derived_data_path" \
  -only-testing:SignalServiceKitTests/BackupSettingsStoreTests \
  CODE_SIGNING_ALLOWED=NO \
  COMPILER_INDEX_STORE_ENABLE=NO \
  ONLY_ACTIVE_ARCH=YES \
  ENABLE_TESTABILITY=YES \
  'EXCLUDED_SOURCE_FILE_NAMES=$(inherited) DonationReceiptCredentialRedemptionJobFinderTest.swift OWSRequestFactoryTest.swift PendingMonthlyIDEALDonationCodableTest.swift StripeTest.swift' \
  'OTHER_SWIFT_FLAGS=$(inherited) -DTESTABLE_BUILD' \
  'GCC_PREPROCESSOR_DEFINITIONS=$(inherited) TESTABLE_BUILD=1'
