oficina / docs Public

Snapshot gate: wall-clock limits on both halves, print the environment

A screen that hangs the main thread (like the iOS render loop) never
reaches the kit's 3 s settle limit, which runs on the same thread. The Mac
test run now stops after SNAPSHOT_MAC_LIMIT seconds (default 300, after
its build), and the iPhone half passes -test-timeouts-enabled YES
-default-test-execution-time-allowance 120 to xcodebuild. Both halves run
even when the first fails, and each prints the environment it drew on
beside its baselines', so drift is told from a regression. Push guidance
now says what works: http.postBuffer, one commit per push.

Proved with a deliberate main-thread spin on the ru screen (reverted):
the Mac run stopped at its 60 s test limit, the iPhone test at XCTest's
2-minute allowance; both failed.

Review: Fable on #161, findings 1, 2 (script half) and 8.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by claude agent, operated by paul@keymail.dev 1530a7160978d74920bfe6bf428d7f8c45d6180e parent 3e12285
1 file changed, +76 −5
  • native/scripts/snapshots.sh +76 −5
diff --git a/native/scripts/snapshots.sh b/native/scripts/snapshots.sh
index a0a0193..dad7cc6 100755
--- a/native/scripts/snapshots.sh
+++ b/native/scripts/snapshots.sh
@@ -10,8 +10,20 @@
# compare (the default) fails on any changed, missing or stale picture;
# record redraws the baselines in apple/Tests/DocsSnapshots/__Snapshots__/docs*.
# Review the contact sheets, apple/.build/snapshots/docs*/index.html, before
-# committing a recording, and push baselines in commits under ~700 KB: the
-# hub drops a push whose pack is over about 1 MB.
+# committing a recording. Push baselines one commit per push, with
+# `git -c http.postBuffer=209715200 push`: without it the hub drops a pack
+# over about 1 MB ("unexpected disconnect while reading sideband packet"),
+# and pushes back to back trip its per-IP limit.
+#
+# Both halves run even when the first fails, and each ends by printing the
+# environment it drew on beside the one its baselines were drawn on. A
+# change there is drift, not a regression: see BUILDING.md, "The
+# screenshot gate", before re-recording anything.
+#
+# A screen that hangs the main thread never reaches the kit's own 3 s
+# limit, so each half has a wall clock: SNAPSHOT_MAC_LIMIT seconds (default
+# 300) for the Mac test run, after its build; and XCTest's execution time
+# allowance, 120 s a test, for the iPhone half.
#
# Not in .amadan/ci.d: baselines are exact only on the OS and simulator
# runtime that drew them (ENVIRONMENT beside them says which). The runner
@@ -22,17 +34,76 @@ cd "$(dirname "$0")/.."
mode=${1:-compare}
platforms=${2:-all}
case "$mode" in compare|record) ;; *) echo "usage: $0 [compare|record] [mac|iphone|all]" >&2; exit 2 ;; esac
+case "$platforms" in mac|iphone|all) ;; *) echo "usage: $0 [compare|record] [mac|iphone|all]" >&2; exit 2 ;; esac
if [ "${OFICINA_SKIP_PREPARE:-0}" != 1 ]; then scripts/build-crdt.sh; fi
swift package --package-path apple resolve
shared=${OFICINA_NATIVE_PACKAGE_PATH:-apple/.build/checkouts/native}
case "$shared" in /*) ;; *) shared="$(pwd)/$shared" ;; esac
tools="$shared/tools"
+
+# Stops a process and everything under it.
+kill_tree() {
+ for child in $(pgrep -P "$1" 2>/dev/null); do kill_tree "$child"; done
+ kill -TERM "$1" 2>/dev/null || true
+}
+
+# Runs the rest of the line, stopping it after $1 seconds.
+with_limit() {
+ limit=$1
+ shift
+ "$@" &
+ pid=$!
+ (
+ sleep "$limit"
+ echo "the snapshot run passed its ${limit} s limit: a screen hung the main thread; stopping it" >&2
+ kill_tree "$pid"
+ ) &
+ watchdog=$!
+ set +e
+ wait "$pid"
+ status=$?
+ set -e
+ kill_tree "$watchdog"
+ return "$status"
+}
+
+# What each catalog's run drew on, and what its baselines were drawn on.
+print_environment() {
+ python3 - "$1" <<'EOF'
+import json, pathlib, sys
+platform = sys.argv[1]
+shown = None
+for results in sorted(pathlib.Path("apple/.build/snapshots").glob(f"*/{platform}/results.json")):
+ run = json.loads(results.read_text())
+ here = run.get("environment", "")
+ if shown is None:
+ print(f"{platform} half drawn on:")
+ print(" " + here.replace("\n", "\n "))
+ shown = here
+ recorded = run.get("baselineEnvironment") or "(none recorded)"
+ if recorded == here:
+ print(f" {run['app']}: baselines drawn on the same")
+ else:
+ print(f" {run['app']}: ENVIRONMENT DIFFERS from its baselines, drawn on:")
+ print(" " + recorded.replace("\n", "\n "))
+ print(" Drift, not a regression: re-record from main in its own commit first (BUILDING.md).")
+EOF
+}
+
+failed=0
case "$platforms" in mac|all)
- (cd apple && "$tools/snapshots-mac.sh" "$mode" DocsSnapshots) ;;
+ (cd apple && swift build --build-tests)
+ if ! (cd apple && with_limit "${SNAPSHOT_MAC_LIMIT:-300}" "$tools/snapshots-mac.sh" "$mode" DocsSnapshots); then failed=1; fi
+ print_environment mac ;;
esac
case "$platforms" in iphone|all)
xcodegen generate --spec ios/project.yml
# Build products stay under apple/.build, beside the Mac half's.
- (cd apple && SNAPSHOT_DERIVED_DATA=.build/xcode "$tools/snapshots-iphone.sh" "$mode" DocsPhoneSnapshots DocsPhoneSnapshots \
- -project ../ios/DocsPhone.xcodeproj) ;;
+ if ! (cd apple && SNAPSHOT_DERIVED_DATA=.build/xcode "$tools/snapshots-iphone.sh" "$mode" DocsPhoneSnapshots DocsPhoneSnapshots \
+ -project ../ios/DocsPhone.xcodeproj -test-timeouts-enabled YES -default-test-execution-time-allowance 120); then
+ failed=1
+ grep -h "exceeded execution time allowance" apple/.build/snapshots-iphone.log || true
+ fi
+ print_environment iphone ;;
esac
+exit "$failed"