178 lines · 7.9 KB · ShellRaw
#!/usr/bin/env bash# Called only by ui-tests-stub.sh --home-walk, inside its private workspace and# build lock: builds the synthetic Home preview with a UI-test runner# (HomeWalkUITests.swift), then on the caller's own booted simulator records# the screen while one walk of real touches runs, into <out.mp4>. The# simulator is the caller's; it is never created, erased or deleted here.## walk.sh <dir> <udid> <repo> <out.mp4> <walk> [app args...]## <walk> names a test of HomeWalkUITests.swift (edge → testEdge). App args go# to the preview (-home-keys mood|notes|..., -home-board bare). HOME_WALK_TILES# HOME_WALK_PAUSE and HOME_WALK_EVERY pass through to the walk; HOME_WALK_SCRIPT (a file of# steps) and HOME_WALK_OUT (a folder for its frames) to the script walk;# HOME_WALK_LOG keeps the fan's log lines there.set -euo pipefailDIR="$1"; SIM="$2"; REPO="$3"; OUT="$4"; WALK="$5"; shift 5# <dir> comes from the caller, so it is judged before anything below it is# deleted: never the home folder or anything above it (owned-root.sh).. "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/../lib/owned-root.sh"refuse_wide_root "the walk's build folder" "$DIR"W="$DIR/home-walk"mkdir -p "$W"if [ "$WALK" != checks ]; then python3 "$REPO/scripts/lib/evidence.py" begin "$(dirname "$OUT")" >/dev/null if [ -n "${HOME_WALK_OUT:-}" ]; then python3 "$REPO/scripts/lib/evidence.py" begin "$HOME_WALK_OUT" >/dev/null fificp "$REPO/scripts/home-preview/HomePreviewApp.swift" "$W/HomePreviewApp.swift"cp "$REPO/scripts/home-preview/HomeWalkUITests.swift" "$W/HomeWalkUITests.swift"# The walk `checks` runs CottonUITests files on this build instead of a walk:# the iOS-only ones (`#if os(iOS)`, which `swift test` on the Mac skips),# hosted in the synthetic preview, over CottonUI with no Rust core.# HOME_WALK_CHECKS names them, `|`-separated, from Tests/CottonUITests;# SourceSweep.swift, which they read the tree with, always comes.rm -rf "$W/checks"mkdir -p "$W/checks"cp "$REPO/apps/cotton/Tests/CottonUITests/SourceSweep.swift" "$W/checks/"IFS='|' read -ra CHECKS <<< "${HOME_WALK_CHECKS:-}"for check in ${CHECKS[@]+"${CHECKS[@]}"}; do cp "$REPO/apps/cotton/Tests/CottonUITests/$check" "$W/checks/"; donecat > "$W/project.yml" <<'YAML'name: CottonHomeWalkoptions: bundleIdPrefix: com.cottondbpackages: cotton: path: ../apps/cottontargets: CottonHomePreview: type: application platform: iOS deploymentTarget: '26.0' sources: [HomePreviewApp.swift] dependencies: - package: cotton product: CottonUI settings: base: PRODUCT_BUNDLE_IDENTIFIER: com.cottondb.homepreview GENERATE_INFOPLIST_FILE: YES INFOPLIST_KEY_UILaunchScreen_Generation: YES INFOPLIST_KEY_UIApplicationSceneManifest_Generation: YES INFOPLIST_KEY_NSMicrophoneUsageDescription: The record button listens to what you say. INFOPLIST_KEY_NSSpeechRecognitionUsageDescription: What you say becomes words on the device. SWIFT_VERSION: '6.0' SWIFT_OPTIMIZATION_LEVEL: '-O' ENABLE_TESTABILITY: YES CODE_SIGN_IDENTITY: '-' HomeWalk: type: bundle.ui-testing platform: iOS deploymentTarget: '26.0' sources: [HomeWalkUITests.swift] dependencies: - target: CottonHomePreview settings: base: GENERATE_INFOPLIST_FILE: YES PRODUCT_BUNDLE_IDENTIFIER: com.cottondb.homewalk TEST_TARGET_NAME: CottonHomePreview SWIFT_VERSION: '6.0' CODE_SIGN_IDENTITY: '-' HomeChecks: type: bundle.unit-test platform: iOS deploymentTarget: '26.0' sources: [checks] dependencies: - target: CottonHomePreview settings: base: GENERATE_INFOPLIST_FILE: YES PRODUCT_BUNDLE_IDENTIFIER: com.cottondb.homechecks TEST_HOST: $(BUILT_PRODUCTS_DIR)/CottonHomePreview.app/CottonHomePreview BUNDLE_LOADER: $(TEST_HOST) SWIFT_VERSION: '6.0' CODE_SIGN_IDENTITY: '-'schemes: HomeWalk: build: targets: CottonHomePreview: all HomeWalk: [test] HomeChecks: [test] test: targets: [HomeWalk, HomeChecks]YAML(cd "$W" && xcodegen generate >/dev/null)# shellcheck source=../lib/derived-data.sh. "$REPO/scripts/lib/derived-data.sh"DERIVED="$(cotton_derived_data)/home-walk"# Inside a lane's seatbelt Xcode's own sandboxes cannot start (sandbox_apply:# Operation not permitted); the lane policy's flags turn them off, as every# lane build does (scripts/lib/mac_disk_policy.py, lane_args).NO_SANDBOX=()[ "${COTTON_LANE_SANDBOXED:-}" = 1 ] && NO_SANDBOX=(-IDEPackageSupportDisableManifestSandbox=YES -IDEPackageSupportDisablePluginExecutionSandbox=YES ENABLE_USER_SCRIPT_SANDBOXING=NO 'OTHER_SWIFT_FLAGS=$(inherited) -disable-sandbox')# The packages come from the shared warm resolve (scripts/lib/swiftpm-cache.sh),# cloned on APFS (no bytes copied) into the walk's own workspace: a fresh# derived folder otherwise clones every dependency from the network, which a# lane's seatbelt refuses (submodules) and the home link pays for.# shellcheck source=../lib/swiftpm-cache.sh. "$REPO/scripts/lib/swiftpm-cache.sh"PACKAGES="$(cotton_swiftpm_sources "$REPO/apps/cotton" walk)"WARM="$(cotton_swiftpm_sources "$REPO/apps/cotton" mac)"if [ ! -d "$PACKAGES" ] && [ -d "$WARM" ]; then mkdir -p "$(dirname "$PACKAGES")" cp -Rc "$WARM" "$PACKAGES"fixcodebuild build-for-testing -project "$W/CottonHomeWalk.xcodeproj" -scheme HomeWalk \ -destination "platform=iOS Simulator,id=$SIM" -derivedDataPath "$DERIVED" \ -clonedSourcePackagesDirPath "$PACKAGES" -skipPackageUpdates -quiet ${NO_SANDBOX[@]+"${NO_SANDBOX[@]}"}XCTESTRUN="$(ls "$DERIVED"/Build/Products/HomeWalk_*.xctestrun | head -n 1)"xcrun simctl terminate "$SIM" com.cottondb.homepreview >/dev/null 2>&1 || trueARGS=""TAB="$(printf '\t')"for arg in "$@"; do ARGS="${ARGS:+$ARGS$TAB}$arg"; doneif [ "$WALK" = checks ]; then STATUS=0 TEST_RUNNER_COTTON_UI_TESTS_REPO_ROOT="$REPO" \ xcodebuild test-without-building -xctestrun "$XCTESTRUN" -destination "platform=iOS Simulator,id=$SIM" \ -only-testing:HomeChecks > "$W/checks.log" 2>&1 || STATUS=$? grep -E "Test Case .*(passed|failed)|error:|Executed" "$W/checks.log" || true [ "$STATUS" = 0 ] || { echo "home-walk: the checks failed (see $W/checks.log)" >&2; exit "$STATUS"; } echo "home-walk: checks passed" exit 0fiTEST="test$(printf '%s' "${WALK:0:1}" | tr '[:lower:]' '[:upper:]')${WALK:1}"xcrun simctl io "$SIM" recordVideo --codec h264 --force "$OUT" > "$W/record.log" 2>&1 &RECORDER="$!"trap 'kill -INT "$RECORDER" >/dev/null 2>&1 || true' EXIT# HOME_WALK_LOG: the fan's log lines (subsystem com.cottondb.fan) kept there.LOGGER=""if [ -n "${HOME_WALK_LOG:-}" ]; then xcrun simctl spawn "$SIM" log stream --style compact --predicate 'subsystem == "com.cottondb.fan"' \ > "$HOME_WALK_LOG" 2>&1 & LOGGER="$!"fitrap 'kill -INT "$RECORDER" >/dev/null 2>&1 || true; [ -z "$LOGGER" ] || kill "$LOGGER" >/dev/null 2>&1 || true' EXITsleep 2STATUS=0# The script walk (--walk script): HOME_WALK_SCRIPT names a file of steps, one# a line, words tab-separated; frames, trees and walk.log go to HOME_WALK_OUT.STEPS=""[ -n "${HOME_WALK_SCRIPT:-}" ] && STEPS="$(awk 'NF{printf "%s;;", $0}' "$HOME_WALK_SCRIPT")"TEST_RUNNER_HOME_WALK_SCRIPT="$STEPS" TEST_RUNNER_HOME_WALK_OUT="${HOME_WALK_OUT:-}" \TEST_RUNNER_HOME_WALK_ARGS="$ARGS" TEST_RUNNER_HOME_WALK_TILES="${HOME_WALK_TILES:-}" TEST_RUNNER_HOME_WALK_PAUSE="${HOME_WALK_PAUSE:-}" TEST_RUNNER_HOME_WALK_EVERY="${HOME_WALK_EVERY:-}" \ xcodebuild test-without-building -xctestrun "$XCTESTRUN" -destination "platform=iOS Simulator,id=$SIM" \ -only-testing:"HomeWalk/HomeWalk/$TEST" > "$W/walk.log" 2>&1 || STATUS=$?kill -INT "$RECORDER" >/dev/null 2>&1 || truewait "$RECORDER" || true[ -z "$LOGGER" ] || kill "$LOGGER" >/dev/null 2>&1 || truetrap - EXIT[ "$STATUS" = 0 ] || { echo "home-walk: the walk failed (see $W/walk.log)" >&2; exit "$STATUS"; }echo "home-walk: $OUT"