#!/usr/bin/env bash # The page check (architect, 15 Oct 2026): a record open on a fan card's page, at # rest, leaves the main thread idle. A record page under a scale effect once # re-laid itself out every frame — 100% of a core, the record frozen — and # nothing failed. On the caller's own simulator, with the Home preview already # installed (ui-tests-stub.sh --home-preview), a note opens on the shown card's # page, a person on it, a meeting on that, then back one and back to the root; # after each comes to rest the main thread's CPU time over # one second is measured. Fails when any rest costs more than LIMIT ms, or the # check never finishes (a main thread stuck in a layout loop cannot log). # Home alone costs ~100 ms a second on the simulator (the fan at rest); the # loop this guards against costs ~1000. # usage: scripts/home-preview/check-page.sh [limit ms, default 300] set -euo pipefail SIM="$1"; LIMIT="${2:-300}" APP=com.cottondb.homepreview PRED='subsystem == "com.cottondb.fan" AND category == "page"' xcrun simctl terminate "$SIM" "$APP" >/dev/null 2>&1 || true xcrun simctl launch "$SIM" "$APP" -page-check >/dev/null xcrun simctl spawn "$SIM" log stream --timeout 1m --style compact --predicate "$PRED" 2>/dev/null \ | grep --line-buffered -m1 "page check: done" >/dev/null || true LINES="$(xcrun simctl spawn "$SIM" log show --last 2m --style compact --predicate "$PRED" 2>/dev/null \ | grep -o 'page check: .*' || true)" echo "$LINES" WORST="$(echo "$LINES" | sed -n 's/^page check: done worst \([0-9.]*\) ms$/\1/p' | tail -1)" [ -n "$WORST" ] || { echo "check-page: the check never finished — the main thread did not yield"; exit 2; } awk -v w="$WORST" -v l="$LIMIT" 'BEGIN { exit !(w <= l) }' \ && echo "check-page: worst ${WORST} ms <= ${LIMIT} ms a second at rest — the main thread is idle" \ || { echo "check-page: worst ${WORST} ms > ${LIMIT} ms a second at rest — a record on the page keeps the main thread busy"; exit 1; }